Skip to main content

API Reference

Complete public API surface for ModernSyntax. All types are in the Source/ directory; unit names follow the ModernSyntax.* convention.


TOption<T>ModernSyntax.Option

Class methods (constructors)

MethodSignatureDescription
Someclass function Some(const AValue: T): TOption<T>Creates an option with a value
Noneclass function None: TOption<T>Creates an empty option
Zipclass function Zip(const AThis, AOther: TOption<Variant>): TOption<Variant>Combines two options into a Variant pair

Inspection

MethodSignatureDescription
IsSomefunction IsSome: BooleanTrue if has value
IsNonefunction IsNone: BooleanTrue if empty
IsSomeAndfunction IsSomeAnd(const APredicate: TFunc<T, Boolean>): BooleanTrue if has value and predicate passes
Containsfunction Contains(const AValue: T; const AComparer: TFunc<T, T, Boolean> = nil): BooleanTrue if value equals AValue

Extraction

MethodSignatureDescription
Valueproperty Value: T (read-only)Raises if None
Unwrapfunction Unwrap: TAlias for Value
UnwrapOrfunction UnwrapOr(const ADefault: T): TValue or default
UnwrapOrElsefunction UnwrapOrElse(const ADefaultFunc: TFunc<T>): TValue or computed default
UnwrapOrDefaultfunction UnwrapOrDefault: TValue or type default
Expectfunction Expect(const AMessage: string): TValue or raises with message

Transformation

MethodSignatureDescription
Map<U>function Map<U>(const AFunc: TFunc<T, U>): TOption<U>Applies func to value
Filterfunction Filter(const APredicate: TFunc<T, Boolean>): TOption<T>Keeps value if predicate
AndThen<U>function AndThen<U>(const AFunc: TOptionAndThen<U>): TOption<U>flatMap
Otherwisefunction Otherwise(const AAlternative: TOption<T>): TOption<T>Self if Some, else alternative
OrElsefunction OrElse(const AAlternativeFunc: TOptionOrElse<T>): TOption<T>Self if Some, else computed
Flatten<U>function Flatten<U>: TOption<U>Unwrap TOption<TOption<U>>

Conversion

MethodSignatureDescription
OkOr<F>function OkOr<F>(const AFailure: F): TResultPair<T, F>Success if Some, Failure if None
AsStringfunction AsString: stringRTTI string representation

Branching

MethodSignatureDescription
Match (proc)procedure Match(const ASomeProc: TSomeProc<T>; const ANoneProc: TNoneProc)Execute on Some or None
Match<R> (func)function Match<R>(const ASome: TSome; const ANone: TNone): RReturn value from branch
IfSomeprocedure IfSome(const AAction: TSomeProc<T>)Execute only if Some

Mutation

MethodSignatureDescription
Takefunction Take(var ASelf: TOption<T>): TOption<T>Extract and clear
Replacefunction Replace(var ASelf: TOption<T>; const ANewValue: T): TOption<T>Swap; return old

TResultPair<S, F>ModernSyntax.ResultPair

Class methods (constructors)

MethodSignatureDescription
Successclass function Success(const ASuccess: S): TResultPair<S, F>Creates a success result
Failureclass function Failure(const AFailure: F): TResultPair<S, F>Creates a failure result

Inspection

Property / MethodDescription
IsSuccessTrue when rtSuccess
IsFailureTrue when rtFailure
ValueSuccessThe success value
ValueFailureThe failure value

Chaining

MethodDescription
ThenOf(AFunc)Registers AFunc(ValueSuccess): TResultPair<S,F> in the success queue; runs on Return
ExceptOf(AFunc)Registers AFunc(ValueFailure): TResultPair<S,F> in the failure queue; runs on Return
Ok(ASuccessProc)Executes ASuccessProc(ValueSuccess) immediately if IsSuccess
Fail(AFailureProc)Executes AFailureProc(ValueFailure) immediately if IsFailure
ReturnDrains the success/failure queues built by ThenOf/ExceptOf

Supporting types

TypeDescription
TResultTypeEnum: rtNone, rtSuccess, rtFailure
EFailureException<F>Exception carrying a failure value
ESuccessException<S>Exception carrying a success value
ETypeIncompatibilityRaised on RTTI type mismatch
TResultValueRecord holding both Success and Failure TValue fields
TResultPairValue<T>Internal wrapper with HasValue: Boolean

TMatch<T>ModernSyntax.Match

Entry point

MethodSignatureDescription
Valueclass function Value(const AValue: T): TMatch<T>Starts a match session

Case builders

MethodDescription
CaseEq(AValue, AProc/AFunc)Equality match
CaseGt(AValue, AProc/AFunc)Greater-than match
CaseLt(AValue, AProc/AFunc)Less-than match
CaseRange(AStart, AEnd, AProc/AFunc)Inclusive range match
CaseIn(AArray/ASet, AProc/AFunc)Membership match (array, TSysCharSet, TIntegerSet)
CaseIs<Typ>(AProc/AFunc)Type-kind match
CaseIf(ACondition, AProc/AFunc?)Conditional guard
CaseRegex(AInput, APattern)Regular expression match

All case builders return TMatch<T> (fluent API). Each has multiple overloads accepting TProc, TProc<T>, TProc<TValue>, TFunc<TValue>, TFunc<T, TValue>.

Terminals

MethodReturnsDescription
Default(AProc/AFunc)TMatch<T>Fallback case
TryExcept(AProc)TMatch<T>Exception fallback inside the match
Combine(AMatch)TMatch<T>Merge two matches
ExecuteTResultPair<Boolean, String>Run proc cases; True on match
Execute<R>TResultPair<R, String>Run func cases; typed value on match

Session states

TMatchSession enum: sMatch, sGuard, sCase, sDefault, sTryExcept.


TAsyncModernSyntax.Async

MethodReturnsDescription
Await(ATimeout?)TFutureBlock until task completes
Await(AContinue, ATimeout?)TFutureBlock then run continuation
RunTFutureStart and return immediately
Run(AError)TFutureStart with error handler
NoAwaitTFutureFire-and-forget
NoAwait(AError)TFutureFire-and-forget with error handler
StatusTTaskStatusCurrent task status
GetIdIntegerTask identifier
CancelRequest cancellation
CheckCanceledRaise if cancelled

Global functions: Async(AProc: TProc): TAsync and Async(AFunc: TFunc<TValue>): TAsync.


TFutureModernSyntax (core unit)

MethodDescription
IsOkTrue if task succeeded
IsErrTrue if task raised
Ok<T>Typed result value
ErrError message string
SetOk(AValue)Set success (internal use)
SetErr(AMessage)Set error (internal use)

TTupleModernSyntax.Tuple

MethodDescription
New(AValues: TValueArray)Factory
Get<T>(AIndex)Typed value by position
CountElement count
Items[AIndex]Default indexed property (TValue)

Implicit conversions: TTuple ↔ TValueArray, array of Variant → TTuple.


TTuple<K>ModernSyntax.Tuple

MethodDescription
New(AKeys, AValues)Factory
Get<T>(AKey)Typed value by key
TryGet<T>(AKey, out AValue)Non-raising lookup
CountEntry count
SetTuple(AKeys, AValues)Replace all

TSafeTry / TSafeResultModernSyntax.SafeTry

TSafeTry

MethodReturnsDescription
Try(AFunc)TSafeTryStart with a function (class method)
Try(AProc?)TSafeTryStart with a procedure (class method)
Except(AProc)TSafeTryRegister exception handler
Finally(AProc)TSafeTryRegister finally block
EndTSafeResultExecute and return result

Global: Try(AFunc), Try(AProc), Try (no args).

TSafeResult

MethodDescription
IsOkTrue if no exception
IsErrTrue if exception caught
GetValueRaw TValue
TryGetValue(out AValue)Non-raising
ExceptionMessageCaptured message
AsType<T>Cast result
IsType<T>Test result type

TDotEnvModernSyntax.DotEnv

MethodDescription
Create(AFileName, AUseSystemFallback)Constructor; loads the file immediately
OpenReloads variables from the current file
LoadFiles(AFileNames)Loads multiple .env files in order; later files override earlier
SaveWrites current variables back to the file
Add(AName, AValue)Adds or updates a variable
Push(AName, AValue)Like Add but returns Self for chaining
Delete(AName)Removes a variable
Value<T>(AName)Returns the variable as type T; raises if not found
Get<T>(AName)Alias for Value<T>
GetOr<T>(AName, ADefault)Returns the variable or ADefault if not found
TryGet<T>(AName, out AValue)Non-raising lookup; returns False if not found
CountNumber of variables loaded
EnvCreate(AName, AValue)Creates a system environment variable
EnvLoad(AName)Reads a system environment variable
EnvUpdate(AName, AValue)Updates a system environment variable
EnvDelete(AName)Deletes a system environment variable
Items[AName]Default property; read/write access as TValue
UseSystemFallbackProperty; if True, falls back to system env vars when key is missing