Skip to content

API Reference

Complete signatures for every public type, current as of 0.4.0. For prose and examples, follow the per-module guides; this page is the quick lookup.

Option<T>

Maybe\Option\Option — an optional value, either Some or None.

MemberSignatureDescription
Option::somesome($value): Option<T>Wrap a present value (never null).
Option::nonenone(): Option<mixed>The empty option.
Option::fromNullablefromNullable($value): Option<T>nullNone, otherwise Some.
mapmap(callable $fn): OptionTransform the value; a null result collapses to None.
flatMapflatMap(callable $fn): OptionChain an operation returning an Option.
filterfilter(callable $predicate): OptionKeep the value only if the predicate holds.
matchmatch(callable $onSome, callable $onNone)Handle both branches, returns their result.
unwrapunwrap()The value, or throws UnwrapNoneException on None.
unwrapOrunwrapOr($default)The value, or an eager fallback.
unwrapOrElseunwrapOrElse(callable $fn)The value, or a lazy fallback.
expectexpect(string $message)The value, or throws with your message.
okOrokOr($error): ResultSomeOk, NoneErr($error).
okOrElseokOrElse(callable $fn): ResultLike okOr, error computed lazily.
isSome / isNone(): boolInspect the variant.

Result<T, E>

Maybe\Result\Result — a success (Ok) or a typed failure (Err).

MemberSignatureDescription
Result::okok($value): Result<T,mixed>A success.
Result::errerr($error): Result<mixed,E>A typed failure.
mapmap(callable $fn): ResultTransform the success value.
mapErrmapErr(callable $fn): ResultTransform the error value.
andThenandThen(callable $fn): ResultChain a fallible op; short-circuits on Err.
orElseorElse(callable $fn): ResultRecover from Err; passes Ok through.
matchmatch(callable $onOk, callable $onErr)Handle both branches.
unwrapunwrap()The value, or throws UnwrapErrException on Err.
unwrapErrunwrapErr()The error, or throws UnwrapOkException on Ok.
unwrapOrunwrapOr($default)The value, or an eager fallback.
unwrapOrElseunwrapOrElse(callable $fn)The value, or a fallback computed from the error.
expectexpect(string $message)The value, or throws with your message.
okOptionokOption(): OptionOk(v)Some(v), ErrNone.
errOptionerrOption(): OptionErr(e)Some(e), OkNone.
isOk / isErr(): boolInspect the variant.

Schema

Maybe\Schema\Schema — builders for immutable validators. Every modifier returns a new instance.

BuilderSignature
Schema::stringstring(): StringSchema
Schema::intint(): IntSchema
Schema::boolbool(): BoolSchema
Schema::datedate(): DateSchema
Schema::enumerationenumeration(array $allowedValues): EnumSchema
Schema::arrayOfarrayOf(SchemaInterface $itemSchema): ArraySchema
Schema::shapeshape(array $shape): ObjectSchema
Schema::optionoption(SchemaInterface $inner): OptionSchema

Modifiers: StringSchema: ->trimmed(), ->min(int), ->max(int), ->regex(string). IntSchema: ->min(int), ->max(int). DateSchema: ->format(string), ->min(DateTimeImmutable), ->max(DateTimeImmutable). ObjectSchema: ->allowUnknown().

Entry points (all schemas): ->safeParse($input): Result<T, ValidationErrorBag> (never throws) and ->parse($input): T (throws ValidationException). ->transform(callable): SchemaInterface.

Validation errors (0.4.0)

Tell-Don't-Ask value objects — there are no path(), message(), code(), all(), or first() getters.

Maybe\Schema\ValidationErrorBag — a first-class collection, Countable and iterable.

MemberSignatureDescription
countcount(): intNumber of errors (Countable).
isEmptyisEmpty(): boolWhether there are no errors.
iterationforeach ($bag as $error)Yields ValidationError items.
describedescribe(): string[]One "path: message" line per error.
summarysummary(): stringFirst line plus "(and N more…)".
toArraytoArray(): array[]Serialization boundary: ['path','message','code'] rows.
withError / merge(...): selfImmutable add / combine.

Maybe\Schema\ValidationError: describedAs(): string, underField(string): self, underIndex(int): self, toArray(): array{path,message,code}. Build one with a Path: new ValidationError(Path::field('email'), 'message', 'code').

Maybe\Schema\Path: Path::root(): self, Path::field(string): self, ->underField(string): self, ->underIndex(int): self, ->toString(): string.

DTO

Maybe\DTO\DTO — abstract base mapping validated input into a typed object.

MemberSignatureDescription
schemaabstract static schema(): ObjectSchemaDefine the shape.
fromValidatedabstract static protected fromValidated(array): staticBuild the instance from validated data.
fromArraystatic fromArray(array $input): Result<static, ValidationErrorBag>Validate, never throws.
parsestatic parse(array $input): staticValidate, throws on invalid input.

Async

Maybe\Async\Async and AsyncFuture — concurrency via child processes (proc_open).

MemberSignatureDescription
asyncasync(callable $task, array $args = [], array $options = []): AsyncFutureStart a task. options: ['timeout' => 2.5]. Wraps Async::run.
awaitawait($futureOrArray)Resolve one future, or an array via Async::all.
Async::runrun(callable $task, array $args = [], array $options = []): AsyncFutureSame as async(), called directly on the class.
Async::allall(array $futures): arrayWait for all (keys preserved).
Async::racerace(array $futures)First to finish wins.
Async::poolpool(array $tasks, int $limit = 5, array $options = []): arrayBounded concurrency.
Async::setDefaultTempDirsetDefaultTempDir(string $tempDir): voidOverride where worker temp files are written.
Async::setDefaultTimeoutsetDefaultTimeout(?float $seconds): voidDefault per-task timeout when options['timeout'] is omitted.
Async::setDefaultPollIntervalsetDefaultPollInterval(int $microseconds): voidDefault polling interval used while waiting on a future.
Async::setDefaultMaxInputBytessetDefaultMaxInputBytes(?int $bytes): voidDefault serialized input limit; null disables it.
Async::setDefaultMaxOutputBytessetDefaultMaxOutputBytes(?int $bytes): voidDefault serialized output limit; null disables it.
AsyncFuture->then(fn), ->catch(fn), ->finally(fn)Register callbacks.
->resolve()Block until done (or timeout).
->pending(): bool, ->cancel()Non-blocking check / kill the process.

Async size options are max_input_bytes (16 MiB by default), max_output_bytes (64 MiB by default), and include_remote_trace (disabled by default). A size limit can be set to null for a trusted, explicitly bounded workload.

Maybe\Async\Exception\PayloadTooLargeException reports which IPC direction exceeded its configured limit. TaskFailedException::remoteTrace() is empty by default; enable include_remote_trace only in trusted diagnostics.

Global helper functions

Auto-loaded (namespace Maybe\): some(), none(), fromNullable(), ok(), err(), stringSchema(), intSchema(), boolSchema(), dateSchema(), enumSchema(), arraySchema(), objectSchema(), optionSchema(), async(), await().

Writing code with an AI assistant? Point it at llms.txt for the same signatures in an LLM-friendly form.