Skip to content

ReadOptionOps<A>

extension ReadOptionOps<A> on Read<A>

Adds nullable column support to Read.

Methods

optional() extension

Read<Option<A>> optional()

Returns a Read that produces None when the column is null or out of range, and Some with the decoded value otherwise.

Available on Read<A>, provided by the ReadOptionOps<A> extension

Implementation
dart
Read<Option<A>> optional() => Read.instance(
  gets,
  (row, n) => Option.unless(
    () => n >= row.length || row[n] == null,
    () => unsafeGet(row, n),
  ),
);