Skip to content

Some<A> final

final class Some<A> extends Option<A>

An Option that signifies the presence of a value.

Inheritance

Object → Option<A>Some<A>

Constructors

Some() const

const Some(A value)
Implementation
dart
const Some(this.value) : super._();

Properties

hashCode no setter override

int get hashCode

The hash code for this object.

A hash code is a single integer which represents the state of the object that affects operator == comparisons.

All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).

If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.

Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.

Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.

If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.

Implementation
dart
@override
int get hashCode => value.hashCode;

isDefined no setter inherited

bool get isDefined

Returns true if this Option is a Some, false if it's a None.

Inherited from Option.

Implementation
dart
bool get isDefined => this is Some;

isEmpty no setter inherited

bool get isEmpty

Whether this collection contains no elements.

Inherited from Option.

Implementation
dart
@override
bool get isEmpty => this is None;

isNotEmpty no setter inherited

bool get isNotEmpty

Whether this collection contains at least one element.

Inherited from RIterableOnce.

Implementation
dart
bool get isNotEmpty => !isEmpty;

isTraversableAgain no setter inherited

bool get isTraversableAgain

Whether this collection can be traversed more than once.

Always false for a bare RIterableOnce; overridden to true by RIterable and its subtypes.

Inherited from RIterableOnce.

Implementation
dart
bool get isTraversableAgain => false;

iterator no setter override

RIterator<A> get iterator

Returns an RIterator over the elements of this collection.

Implementation
dart
@override
RIterator<A> get iterator => RIterator.single(value);

knownSize no setter inherited

int get knownSize

Returns the number of elements in this collection, if that number is already known. If not, -1 is returned.

Inherited from RIterableOnce.

Implementation
dart
int get knownSize => -1;

nonEmpty no setter inherited

bool get nonEmpty

Whether this collection contains at least one element.

Inherited from Option.

Implementation
dart
@override
bool get nonEmpty => this is Some;

runtimeType no setter inherited

Type get runtimeType

A representation of the runtime type of the object.

Inherited from Object.

Implementation
dart
external Type get runtimeType;

size no setter inherited

int get size

Returns the number of elements in this collection.

Inherited from RIterableOnce.

Implementation
dart
int get size {
  if (knownSize >= 0) {
    return knownSize;
  } else {
    final it = iterator;
    var len = 0;

    while (it.hasNext) {
      len += 1;
      it.next();
    }

    return len;
  }
}

value final

final A value
Implementation
dart
final A value;

Extension Properties

get extension no setter

A get get

Returns the value if this is a Some, or throws a StateError if this is a None.

This is an unsafe, partial operation. Prefer getOrElse, fold, or pattern matching when the Option may be None. Use get only when you have already proven that this Option is non-empty.

See also getOrNull for a nullable alternative, and getOrElse for providing a fallback value.

Available on Option<A>, provided by the OptionOps<A> extension

Implementation
dart
A get get => fold(() => throw StateError('None.get'), identity);

getOrNull extension no setter

A? get getOrNull

Returns the value if this is a Some, or null if this is a None.

This is equivalent to Option.toNullable and is provided as a conventionally named companion to get.

Available on Option<A>, provided by the OptionOps<A> extension

Implementation
dart
A? get getOrNull => toNullable();

Methods

collect() inherited

Option<B> collect<B>(Option<B> Function(A) f)

Returns a new collection by applying f to each element an only keeping results of type Some.

Inherited from Option.

Implementation
dart
@override
Option<B> collect<B>(Function1<A, Option<B>> f) => flatMap(f);

collectFirst() inherited

Option<B> collectFirst<B>(Option<B> Function(A) f)

Applies f to each element of this collection, returning the first element that results in a Some, if any.

Inherited from RIterableOnce.

Implementation
dart
Option<B> collectFirst<B>(Function1<A, Option<B>> f) {
  final it = iterator;

  while (it.hasNext) {
    final x = f(it.next());
    if (x.isDefined) return x;
  }

  return none();
}

copyToArray() inherited

int copyToArray(Array<A> xs, [int start = 0, int? n])

Copies elements into xs starting at start, writing at most n elements (or all remaining capacity when n is omitted).

Returns the number of elements actually copied.

Inherited from RIterableOnce.

Implementation
dart
int copyToArray(Array<A> xs, [int start = 0, int? n]) {
  final it = iterator;
  final end = start + min(n ?? Integer.maxValue, xs.length - start);
  var i = start;

  while (i < end && it.hasNext) {
    xs[i] = it.next();
    i += 1;
  }

  return i - start;
}

corresponds() inherited

bool corresponds<B>(RIterable<B> that, bool Function(A, B) p)

Returns true if this collection has the same size as that and each corresponding element from this and that satisfies the given predicate p.

Inherited from RIterableOnce.

Implementation
dart
bool corresponds<B>(
  covariant RIterable<B> that,
  Function2<A, B, bool> p,
) {
  final a = iterator;
  final b = that.iterator;

  while (a.hasNext && b.hasNext) {
    if (!p(a.next(), b.next())) return false;
  }

  return !a.hasNext && !b.hasNext;
}

count() inherited

int count(bool Function(A) p)

Return the number of elements in this collection that satisfy the given predicate.

Inherited from RIterableOnce.

Implementation
dart
int count(Function1<A, bool> p) {
  var res = 0;
  final it = iterator;

  while (it.hasNext) {
    if (p(it.next())) res += 1;
  }

  return res;
}

drop() inherited

Option<A> drop(int n)

Returns a new collection with the first n elements removed.

Inherited from Option.

Implementation
dart
@override
Option<A> drop(int n) => filter((_) => n <= 0);

dropWhile() inherited

Option<A> dropWhile(bool Function(A) p)

Returns a new collection with leading elements satisfying p removed.

Inherited from Option.

Implementation
dart
@override
Option<A> dropWhile(Function1<A, bool> p) => filterNot(p);

exists() inherited

bool exists(bool Function(A) p)

Returns true if any element of this collection satisfies the given predicate, false if no elements satisfy it.

Inherited from RIterableOnce.

Implementation
dart
bool exists(Function1<A, bool> p) {
  var res = false;
  final it = iterator;

  while (!res && it.hasNext) {
    res = p(it.next());
  }

  return res;
}

filter() override

Option<A> filter(bool Function(A) p)

Returns a new collection containing only elements that satisfy p.

Implementation
dart
@override
Option<A> filter(Function1<A, bool> p) => p(value) ? this : const None();

filterNot() inherited

Option<A> filterNot(bool Function(A) p)

Returns a new collection containing only elements that do not satisfy p.

Inherited from Option.

Implementation
dart
@override
Option<A> filterNot(Function1<A, bool> p) => filter((a) => !p(a));

find() inherited

Option<A> find(bool Function(A) p)

Returns the first element from this collection that satisfies the given predicate p. If no element satisfies p, None is returned.

Inherited from RIterableOnce.

Implementation
dart
Option<A> find(Function1<A, bool> p) {
  final it = iterator;

  while (it.hasNext) {
    final a = it.next();
    if (p(a)) return Some(a);
  }

  return none();
}

flatMap() override

Option<B> flatMap<B>(Option<B> Function(A) f)

Returns a new collection by applying f to each element and concatenating the results.

Implementation
dart
@override
Option<B> flatMap<B>(Function1<A, Option<B>> f) => f(value);

fold() override

B fold<B>(B Function() ifEmpty, B Function(A) f)

Returns the result of applying f to this Option value if non-empty. Otherwise, returns the result of ifEmpty.

Implementation
dart
@override
B fold<B>(Function0<B> ifEmpty, Function1<A, B> f) => f(value);

foldLeft() inherited

B foldLeft<B>(B z, B Function(B, A) op)

Returns a summary value by applying op to all elements of this collection, moving from left to right. The fold uses a seed value of z.

Inherited from RIterableOnce.

Implementation
dart
B foldLeft<B>(B z, Function2<B, A, B> op) {
  var result = z;
  final it = iterator;

  while (it.hasNext) {
    result = op(result, it.next());
  }

  return result;
}

foldRight() inherited

B foldRight<B>(B z, B Function(A, B) op)

Returns a summary value by applying op to all elements of this collection, moving from right to left. The fold uses a seed value of z.

Inherited from RIterableOnce.

Implementation
dart
B foldRight<B>(B z, Function2<A, B, B> op) => _reversed().foldLeft(z, (b, a) => op(a, b));

forall() inherited

bool forall(bool Function(A) p)

Returns true if all elements of this collection satisfy the given predicate, false if any elements do not.

Inherited from RIterableOnce.

Implementation
dart
bool forall(Function1<A, bool> p) {
  var res = true;
  final it = iterator;

  while (res && it.hasNext) {
    res = p(it.next());
  }

  return res;
}

foreach() inherited

void foreach<U>(U Function(A) f)

Applies f to each element of this collection, discarding any resulting values.

Inherited from RIterableOnce.

Implementation
dart
void foreach<U>(Function1<A, U> f) {
  final it = iterator;
  while (it.hasNext) {
    f(it.next());
  }
}

map() override

Option<B> map<B>(B Function(A) f)

Returns a new collection by applying f to each element.

Implementation
dart
@override
Option<B> map<B>(Function1<A, B> f) => Some(f(value));

maxByOption() inherited

Option<A> maxByOption<B>(B Function(A) f, Order<B> order)

Finds the largest element in this collection by applying f to each element and using the given Order to find the greatest.

If this collection is empty, None is returned.

Inherited from RIterableOnce.

Implementation
dart
Option<A> maxByOption<B>(Function1<A, B> f, Order<B> order) => _minMaxByOption(f, order.max);

maxOption() inherited

Option<A> maxOption(Order<A> order)

Finds the largest element in this collection according to the given Order.

If this collection is empty, None is returned.

Inherited from RIterableOnce.

Implementation
dart
Option<A> maxOption(Order<A> order) => switch (knownSize) {
  0 => none(),
  _ => _reduceOptionIterator(iterator, order.max),
};

minByOption() inherited

Option<A> minByOption<B>(B Function(A) f, Order<B> order)

Finds the smallest element in this collection by applying f to each element and using the given Order to find the greatest.

If this collection is empty, None is returned.

Inherited from RIterableOnce.

Implementation
dart
Option<A> minByOption<B>(Function1<A, B> f, Order<B> order) => _minMaxByOption(f, order.min);

minOption() inherited

Option<A> minOption(Order<A> order)

Finds the largest element in this collection according to the given Order.

If this collection is empty, None is returned.

Inherited from RIterableOnce.

Implementation
dart
Option<A> minOption(Order<A> order) => switch (knownSize) {
  0 => none(),
  _ => _reduceOptionIterator(iterator, order.min),
};

mkString() inherited

String mkString({String? start, String? sep, String? end})

Returns a String by using each elements toString(), adding sep between each element. If start is defined, it will be prepended to the resulting string. If end is defined, it will be appended to the resulting string.

Inherited from RIterableOnce.

Implementation
dart
String mkString({String? start, String? sep, String? end}) {
  if (knownSize == 0) {
    return '${start ?? ""}${end ?? ""}';
  } else {
    return _mkStringImpl(StringBuffer(), start ?? '', sep ?? '', end ?? '');
  }
}

noSuchMethod() inherited

dynamic noSuchMethod(Invocation invocation)

Invoked when a nonexistent method or property is accessed.

A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:

dart
dynamic object = 1;
object.add(42); // Statically allowed, run-time error

This invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).

Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.

A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:

dart
class MockList<T> implements List<T> {
  noSuchMethod(Invocation invocation) {
    log(invocation);
    super.noSuchMethod(invocation); // Will throw.
  }
}
void main() {
  MockList().add(42);
}

This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.

If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.

The default behavior is to throw a NoSuchMethodError.

Inherited from Object.

Implementation
dart
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);

reduce() inherited

A reduce(A Function(A, A) op)

Reduces this collection to a single value by applying op left to right.

Throws if the collection is empty.

Inherited from RIterableOnce.

Implementation
dart
A reduce(Function2<A, A, A> op) => reduceLeft(op);

reduceLeft() inherited

A reduceLeft(A Function(A, A) op)

Reduces from left to right. Throws if empty.

Inherited from RIterableOnce.

Implementation
dart
A reduceLeft(Function2<A, A, A> op) => switch (this) {
  final IndexedSeq<A> seq when seq.length > 0 => _foldl(seq, 1, seq[0], op),
  _ when knownSize == 0 => throw UnsupportedError('empty.reduceLeft'),
  _ => _reduceLeftIterator(() => throw UnsupportedError('empty.reduceLeft'), op),
};

reduceLeftOption() inherited

Option<A> reduceLeftOption(A Function(A, A) op)

Returns a summary values of all elements of this collection by applying f to each element, moving left to right.

If this collection is empty, None will be returned.

Inherited from RIterableOnce.

Implementation
dart
Option<A> reduceLeftOption(Function2<A, A, A> op) => switch (knownSize) {
  0 => none(),
  _ => _reduceOptionIterator(iterator, op),
};

reduceOption() inherited

Option<A> reduceOption(A Function(A, A) op)

Returns a summary values of all elements of this collection by applying f to each element, moving left to right.

If this collection is empty, None will be returned.

Inherited from RIterableOnce.

Implementation
dart
Option<A> reduceOption(Function2<A, A, A> op) => reduceLeftOption(op);

reduceRight() inherited

A reduceRight(A Function(A, A) op)

Reduces from right to left. Throws if empty.

Inherited from RIterableOnce.

Implementation
dart
A reduceRight(Function2<A, A, A> op) => switch (this) {
  final IndexedSeq<A> seq when seq.length > 0 => _foldr(seq, op),
  _ when knownSize == 0 => throw UnsupportedError('empty.reduceLeft'),
  _ => _reversed().reduceLeft((x, y) => op(y, x)),
};

reduceRightOption() inherited

Option<A> reduceRightOption(A Function(A, A) op)

Returns a summary values of all elements of this collection by applying f to each element, moving right to left.

If this collection is empty, None will be returned.

Inherited from RIterableOnce.

Implementation
dart
Option<A> reduceRightOption(Function2<A, A, A> op) => switch (knownSize) {
  -1 => _reduceOptionIterator(_reversed().iterator, (x, y) => op(y, x)),
  0 => none(),
  _ => Some(reduceRight(op)),
};

scan() inherited

RIterableOnce<B> scan<B>(B z, B Function(B, A) op)

Alias for scanLeft.

Inherited from RIterableOnce.

Implementation
dart
RIterableOnce<B> scan<B>(B z, Function2<B, A, B> op) => scanLeft(z, op);

scanLeft() inherited

RIterableOnce<B> scanLeft<B>(B z, B Function(B, A) op)

Returns a new collection of running totals starting with z.

The first element of the result is z; each subsequent element is the result of applying op to the previous total and the next element.

Inherited from Option.

Implementation
dart
@override
RIterableOnce<B> scanLeft<B>(B z, Function2<B, A, B> op) => toIList().scanLeft(z, op);

slice() inherited

RIterableOnce<A> slice(int from, int until)

Returns a new collection containing elements in the range [from, until).

Inherited from Option.

Implementation
dart
@override
RIterableOnce<A> slice(int from, int until) => toIList().slice(from, until);

span() inherited

Record span(bool Function(A) p)

Returns two collections: elements before and starting from the first element that does not satisfy p.

Inherited from Option.

Implementation
dart
@override
(RIterableOnce<A>, RIterableOnce<A>) span(Function1<A, bool> p) => toIList().span(p);

splitAt() inherited

Record splitAt(int n)

Returns two collections: the first n elements and the remainder.

Inherited from RIterableOnce.

Implementation
dart
(RIterableOnce<A>, RIterableOnce<A>) splitAt(int n) {
  final spanner = _Spanner<A>(n);
  return span(spanner.call);
}

take() inherited

RIterableOnce<A> take(int n)

Returns a new collection containing only the first n elements.

Inherited from Option.

Implementation
dart
@override
RIterableOnce<A> take(int n) => toIList().take(n);

takeWhile() inherited

RIterableOnce<A> takeWhile(bool Function(A) p)

Returns a new collection of leading elements that satisfy p.

Inherited from Option.

Implementation
dart
@override
RIterableOnce<A> takeWhile(Function1<A, bool> p) => toIList().takeWhile(p);

tapEach() inherited

RIterableOnce<A> tapEach<U>(U Function(A) f)

Applies f to each element in this collection, discarding any results and returns this collection.

Inherited from RIterableOnce.

Implementation
dart
RIterableOnce<A> tapEach<U>(Function1<A, U> f) {
  foreach(f);
  return this;
}

toIList() inherited

IList<A> toIList()

Returns an IList with the same elements as this collection.

Inherited from RIterableOnce.

Implementation
dart
IList<A> toIList() => IList.from(this);

toIndexedSeq() inherited

IndexedSeq<A> toIndexedSeq()

Returns an IndexedSeq with the same elements as this collection.

Inherited from RIterableOnce.

Implementation
dart
IndexedSeq<A> toIndexedSeq() => IndexedSeq.from(this);

toISet() inherited

ISet<A> toISet()

Returns an ISet with the same elements as this collection, duplicates removed.

Inherited from RIterableOnce.

Implementation
dart
ISet<A> toISet() => ISet.from(this);

toIVector() inherited

IVector<A> toIVector()

Returns an IVector with the same elements as this collection.

Inherited from RIterableOnce.

Implementation
dart
IVector<A> toIVector() => IVector.from(this);

toLeft() override

Either<A, X> toLeft<X>(X Function() ifEmpty)

If this is a Some a Left is returned with the value. It this is a None, a Right is returned with the result of evaluating ifEmpty.

Implementation
dart
@override
Either<A, X> toLeft<X>(Function0<X> ifEmpty) => Either.left(value);

toList() inherited

List<A> toList({bool growable = true})

Returns a new List with the same elements as this collection.

Inherited from RIterableOnce.

Implementation
dart
List<A> toList({bool growable = true}) {
  if (growable) {
    final it = iterator;
    final res = List<A>.empty(growable: true);

    while (it.hasNext) {
      res.add(it.next());
    }

    return res;
  } else {
    final it = iterator;
    return List.generate(size, (_) => it.next());
  }
}

toNullable() override

A? toNullable()

Returns a nullable value, which is the value itself if this is a Some, or null if this is a None.

Implementation
dart
@override
A? toNullable() => value;

toRight() override

Either<X, A> toRight<X>(X Function() ifEmpty)

If this is a Some a Right is returned with the value. It this is a None, a Left is returned with the result of evaluating ifEmpty.

Implementation
dart
@override
Either<X, A> toRight<X>(Function0<X> ifEmpty) => Either.right(value);

toSeq() inherited

RSeq<A> toSeq()

Returns a RSeq with the same elements as this collection.

Inherited from RIterableOnce.

Implementation
dart
RSeq<A> toSeq() => RSeq.from(this);

toString() inherited

String toString()

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.

Inherited from Option.

Implementation
dart
@override
String toString() => fold(() => 'None', (a) => 'Some($a)');

Extension Methods

contains() extension

bool contains(A elem)

Available on Option<A>, provided by the OptionOps<A> extension

Implementation
dart
bool contains(A elem) => fold(() => false, (value) => value == elem);

filterN() extension

Option<Record> filterN(bool Function(T1, T2, T3) p)

Available on Option<A>, provided by the OptionTuple3Ops<T1, T2, T3> extension

Implementation
dart
Option<(T1, T2, T3)> filterN(Function3<T1, T2, T3, bool> p) => filter(p.tupled);

filterN() extension

Option<Record> filterN(bool Function(T1, T2) p)

Available on Option<A>, provided by the OptionTuple2Ops<T1, T2> extension

Implementation
dart
Option<(T1, T2)> filterN(Function2<T1, T2, bool> p) => filter(p.tupled);

filterN() extension

Option<Record> filterN(bool Function(T1, T2, T3, T4, T5) p)

Available on Option<A>, provided by the OptionTuple5Ops<T1, T2, T3, T4, T5> extension

Implementation
dart
Option<(T1, T2, T3, T4, T5)> filterN(Function5<T1, T2, T3, T4, T5, bool> p) => filter(p.tupled);

filterN() extension

Option<Record> filterN(bool Function(T1, T2, T3, T4) p)

Available on Option<A>, provided by the OptionTuple4Ops<T1, T2, T3, T4> extension

Implementation
dart
Option<(T1, T2, T3, T4)> filterN(Function4<T1, T2, T3, T4, bool> p) => filter(p.tupled);

filterNotN() extension

Option<Record> filterNotN(bool Function(T1, T2, T3, T4, T5) p)

Available on Option<A>, provided by the OptionTuple5Ops<T1, T2, T3, T4, T5> extension

Implementation
dart
Option<(T1, T2, T3, T4, T5)> filterNotN(Function5<T1, T2, T3, T4, T5, bool> p) =>
    filterNot(p.tupled);

filterNotN() extension

Option<Record> filterNotN(bool Function(T1, T2) p)

Available on Option<A>, provided by the OptionTuple2Ops<T1, T2> extension

Implementation
dart
Option<(T1, T2)> filterNotN(Function2<T1, T2, bool> p) => filterNot(p.tupled);

filterNotN() extension

Option<Record> filterNotN(bool Function(T1, T2, T3) p)

Available on Option<A>, provided by the OptionTuple3Ops<T1, T2, T3> extension

Implementation
dart
Option<(T1, T2, T3)> filterNotN(Function3<T1, T2, T3, bool> p) => filterNot(p.tupled);

filterNotN() extension

Option<Record> filterNotN(bool Function(T1, T2, T3, T4) p)

Available on Option<A>, provided by the OptionTuple4Ops<T1, T2, T3, T4> extension

Implementation
dart
Option<(T1, T2, T3, T4)> filterNotN(Function4<T1, T2, T3, T4, bool> p) => filterNot(p.tupled);

flatMapN() extension

Option<T5> flatMapN<T5>(Option<T5> Function(T1, T2, T3, T4) f)

Available on Option<A>, provided by the OptionTuple4Ops<T1, T2, T3, T4> extension

Implementation
dart
Option<T5> flatMapN<T5>(Function4<T1, T2, T3, T4, Option<T5>> f) => flatMap(f.tupled);

flatMapN() extension

Option<T6> flatMapN<T6>(Option<T6> Function(T1, T2, T3, T4, T5) f)

Available on Option<A>, provided by the OptionTuple5Ops<T1, T2, T3, T4, T5> extension

Implementation
dart
Option<T6> flatMapN<T6>(Function5<T1, T2, T3, T4, T5, Option<T6>> f) => flatMap(f.tupled);

flatMapN() extension

Option<T4> flatMapN<T4>(Option<T4> Function(T1, T2, T3) f)

Available on Option<A>, provided by the OptionTuple3Ops<T1, T2, T3> extension

Implementation
dart
Option<T4> flatMapN<T4>(Function3<T1, T2, T3, Option<T4>> f) => flatMap(f.tupled);

flatMapN() extension

Option<T3> flatMapN<T3>(Option<T3> Function(T1, T2) f)

Available on Option<A>, provided by the OptionTuple2Ops<T1, T2> extension

Implementation
dart
Option<T3> flatMapN<T3>(Function2<T1, T2, Option<T3>> f) => flatMap(f.tupled);

flatten() extension

Option<A> flatten()

If this is a Some, the value is returned, otherwise None is returned.

Available on Option<A>, provided by the OptionNestedOps<A> extension

Implementation
dart
Option<A> flatten() => fold(() => none<A>(), identity);

foldN() extension

T6 foldN<T6>(T6 Function() ifEmpty, T6 Function(T1, T2, T3, T4, T5) ifSome)

Available on Option<A>, provided by the OptionTuple5Ops<T1, T2, T3, T4, T5> extension

Implementation
dart
T6 foldN<T6>(
  Function0<T6> ifEmpty,
  Function5<T1, T2, T3, T4, T5, T6> ifSome,
) => fold(ifEmpty, ifSome.tupled);

foldN() extension

T3 foldN<T3>(T3 Function() ifEmpty, T3 Function(T1, T2) ifSome)

Available on Option<A>, provided by the OptionTuple2Ops<T1, T2> extension

Implementation
dart
T3 foldN<T3>(
  Function0<T3> ifEmpty,
  Function2<T1, T2, T3> ifSome,
) => fold(ifEmpty, ifSome.tupled);

foldN() extension

T4 foldN<T4>(T4 Function() ifEmpty, T4 Function(T1, T2, T3) ifSome)

Available on Option<A>, provided by the OptionTuple3Ops<T1, T2, T3> extension

Implementation
dart
T4 foldN<T4>(
  Function0<T4> ifEmpty,
  Function3<T1, T2, T3, T4> ifSome,
) => fold(ifEmpty, ifSome.tupled);

foldN() extension

T5 foldN<T5>(T5 Function() ifEmpty, T5 Function(T1, T2, T3, T4) ifSome)

Available on Option<A>, provided by the OptionTuple4Ops<T1, T2, T3, T4> extension

Implementation
dart
T5 foldN<T5>(
  Function0<T5> ifEmpty,
  Function4<T1, T2, T3, T4, T5> ifSome,
) => fold(ifEmpty, ifSome.tupled);

foreachN() extension

void foreachN(void Function(T1, T2, T3) ifSome)

Available on Option<A>, provided by the OptionTuple3Ops<T1, T2, T3> extension

Implementation
dart
void foreachN(Function3<T1, T2, T3, void> ifSome) => foreach(ifSome.tupled);

foreachN() extension

void foreachN(void Function(T1, T2, T3, T4, T5) ifSome)

Available on Option<A>, provided by the OptionTuple5Ops<T1, T2, T3, T4, T5> extension

Implementation
dart
void foreachN(Function5<T1, T2, T3, T4, T5, void> ifSome) => foreach(ifSome.tupled);

foreachN() extension

void foreachN(void Function(T1, T2) ifSome)

Available on Option<A>, provided by the OptionTuple2Ops<T1, T2> extension

Implementation
dart
void foreachN(Function2<T1, T2, void> ifSome) => foreach(ifSome.tupled);

foreachN() extension

void foreachN(void Function(T1, T2, T3, T4) ifSome)

Available on Option<A>, provided by the OptionTuple4Ops<T1, T2, T3, T4> extension

Implementation
dart
void foreachN(Function4<T1, T2, T3, T4, void> ifSome) => foreach(ifSome.tupled);

getOrElse() extension

A getOrElse(A Function() ifEmpty)

Returns the value if this is a Some or the value returned from evaluating ifEmpty.

Available on Option<A>, provided by the OptionOps<A> extension

Implementation
dart
A getOrElse(Function0<A> ifEmpty) => fold(ifEmpty, identity);

mapN() extension

Option<T4> mapN<T4>(T4 Function(T1, T2, T3) f)

Available on Option<A>, provided by the OptionTuple3Ops<T1, T2, T3> extension

Implementation
dart
Option<T4> mapN<T4>(Function3<T1, T2, T3, T4> f) => map(f.tupled);

mapN() extension

Option<T5> mapN<T5>(T5 Function(T1, T2, T3, T4) f)

Available on Option<A>, provided by the OptionTuple4Ops<T1, T2, T3, T4> extension

Implementation
dart
Option<T5> mapN<T5>(Function4<T1, T2, T3, T4, T5> f) => map(f.tupled);

mapN() extension

Option<T6> mapN<T6>(T6 Function(T1, T2, T3, T4, T5) f)

Available on Option<A>, provided by the OptionTuple5Ops<T1, T2, T3, T4, T5> extension

Implementation
dart
Option<T6> mapN<T6>(Function5<T1, T2, T3, T4, T5, T6> f) => map(f.tupled);

mapN() extension

Option<T3> mapN<T3>(T3 Function(T1, T2) f)

Available on Option<A>, provided by the OptionTuple2Ops<T1, T2> extension

Implementation
dart
Option<T3> mapN<T3>(Function2<T1, T2, T3> f) => map(f.tupled);

orElse() extension

Option<A> orElse(Option<A> Function() orElse)

If this is a Some, this is returned, otherwise the result of evaluating orElse is returned.

Available on Option<A>, provided by the OptionOps<A> extension

Implementation
dart
Option<A> orElse(Function0<Option<A>> orElse) => fold(orElse, (_) => this);

product() extension

int product()

Returns the product of all elements in this list

Available on RIterableOnce<A>, provided by the RIterableIntOps extension

Implementation
dart
int product() {
  var p = 1;
  final it = iterator;

  while (it.hasNext) {
    p *= it.next();
  }

  return p;
}

product() extension

double product()

Returns the product of all elements in this list

Available on RIterableOnce<A>, provided by the RIterableDoubleOps extension

Implementation
dart
double product() {
  var p = 1.0;
  final it = iterator;

  while (it.hasNext) {
    p *= it.next();
  }

  return p;
}

sequence() extension

IO<Option<A>> sequence()

Returns an IO that will return None if this is a None, or the evaluation of the IO lifted into an Option, specifically a Some.

Available on Option<A>, provided by the OptionIOOps<A> extension

Implementation
dart
IO<Option<A>> sequence() => fold(() => IO.pure(none()), (io) => io.map((a) => Some(a)));

sum() extension

double sum()

Returns the sum of all elements in this list

Available on RIterableOnce<A>, provided by the RIterableDoubleOps extension

Implementation
dart
double sum() {
  var s = 0.0;
  final it = iterator;

  while (it.hasNext) {
    s += it.next();
  }

  return s;
}

sum() extension

int sum()

Returns the sum of all elements in this list

Available on RIterableOnce<A>, provided by the RIterableIntOps extension

Implementation
dart
int sum() {
  var s = 0;
  final it = iterator;

  while (it.hasNext) {
    s += it.next();
  }

  return s;
}

traverseIO() extension

IO<Option<B>> traverseIO<B>(IO<B> Function(A) f)

If this is a Some, returns the result of applying f to the value, otherwise an IO with a None is returned.

Available on Option<A>, provided by the IOOptionOps<A> extension

Implementation
dart
IO<Option<B>> traverseIO<B>(Function1<A, IO<B>> f) =>
    fold(() => IO.none(), (a) => f(a).map((a) => Some(a)));

traverseIO_() extension

IO<Unit> traverseIO_<B>(IO<B> Function(A) f)

Same behavior as traverseIO but the resulting value is discarded.

Available on Option<A>, provided by the IOOptionOps<A> extension

Implementation
dart
IO<Unit> traverseIO_<B>(Function1<A, IO<B>> f) =>
    fold(() => IO.unit, (a) => f(a).map((_) => Unit()));

Operators

operator ==() override

bool operator ==(Object other)

The equality operator.

The default behavior for all Objects is to return true if and only if this object and other are the same object.

Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:

  • Total: It must return a boolean for all arguments. It should never throw.

  • Reflexive: For all objects o, o == o must be true.

  • Symmetric: For all objects o1 and o2, o1 == o2 and o2 == o1 must either both be true, or both be false.

  • Transitive: For all objects o1, o2, and o3, if o1 == o2 and o2 == o3 are true, then o1 == o3 must be true.

The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.

If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.

Implementation
dart
@override
bool operator ==(Object other) => other is Some && other.value == value;