option 0.3.3 copy "option: ^0.3.3" to clipboard
option: ^0.3.3 copied to clipboard

outdatedDart 1 only

The Option typeclass inspired by Scala's implementation and Haskell's Maybe monad. Option is a composable and more expressive alternative to things that may be null on absence of value.

Option #

Build Status

The option typeclass inspired by scala's implementation and Haskell's Maybe monad. Option is a composable and more expressive alternative to things that may be null on absence of value.

Tested with Dart 0.4.7

Examples #

import 'package:option/option.dart';

main() {
  final some   = new Some(42);
  final inner  = some.get();
  final mapped = some.map((n) => n / 2);
  final toSome = some.flatMap((n) => new Some(12));
  final toNone = some.flatMap((n) => new None<num>());
  final passed = some.filter((n) => (n % 2) == 0);
  final failed = some.filter((n) => (n % 2) != 0);
  final none   = new None();
  final alt1   = none.getOrElse(42);
  final alt2   = none.orElse(() => new Some(33));
  final alt3   = none.orElse(new Some(32));

  print('secret to all ${some.getOrElse(12)}');
}
0
likes
15
pub points
5%
popularity

Publisher

unverified uploader

The Option typeclass inspired by Scala's implementation and Haskell's Maybe monad. Option is a composable and more expressive alternative to things that may be null on absence of value.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

either

More

Packages that depend on option