nullable

Runs a block in an info-free raise scope: any short-circuit makes the whole block evaluate to null. The nullable-first alternative to an Option type.

A? nullable<A>(A Function(SingletonRaise r) block) Future<A?> nullableAsync<A>(FutureOr<A> Function(SingletonRaise r) block) on SingletonRaise: A bind<A>(A? value) · ensure(bool) · ensureNotNull(A?) · none()

Lecture

When the only failure information you need is absence, an Either is overkill — Dart already has a dedicated absence channel: T?. nullable is the either builder's info-free twin (the port of Arrow's nullable { }): the scope's r.bind(value) unwraps a nullable, and if it's null the whole block returns null.

Compared to chaining ?. and ??, the win is that any step can bail out — a lookup, a parse, a condition via r.ensure(cond) — without nesting, and intermediate values stay promoted and non-null. This is why FxDart ships no Option/Maybe type: T? plus this builder covers it, with zero wrapping.

Demo 1 · bind on tryParse

Demo 2 · deep lookups without ?. staircases

Try it yourself

Exercise: lastSeen['lee'] exists but holds null, and 'park' is missing entirely — r.bind treats both as absence. Fix describe so both print null.

Related: either builder — when the failure needs a reason · EithergetOrNull() bridges back to nullable · nonNulls — drop nulls from a pipeline · typed errors — full guide