p-hatan/ mirror

pub repository

mirror.p-hatan.ir

option

0.3.3

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.

Download archive

Readme

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)}');
}
Changelog

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add option
pubspec.yaml
name: option
version: 0.3.3
homepage: https://github.com/JosephMoniz/dart-option
description: >
  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.
author: Joseph Moniz <joseph.moniz@gmail.com>
dependencies:
  either: '>=0.1.0 <0.2.0'
dev_dependencies:
  unittest: 0.4.7+1

Version history

VersionPublishedArchiveSHA-256
0.1.02013-03-09T17:36:31.003570ZDownload9b1c2d08e957125706db122bdb299ea4b06183410fa4f6421e0846cb9fe00d7a
0.2.02013-03-09T18:19:01.939340ZDownloadbc85cd65fc921bb124cc487ffc5c8ba11654976f2c8dd3466f28075a5b04acf3
0.2.12013-03-16T18:11:13.977400ZDownloadb47470a785fa871ff5160eb95b357bc268cbf25b41b5a8522305ecb81ce75cef
0.2.22013-03-17T03:16:21.289690ZDownload1515681b7c76d09f6b3d1e577be350c45e99c4a572d9f0b0ea1b14d278940e72
0.2.32013-03-17T03:27:29.364790ZDownloadcf917aec3c93b01bef901429ac6217ea8cc71beca9b39747aa7751995a772e27
0.3.02013-04-01T03:56:02.763760ZDownloadbed59ed173b76c06cd2bb1794ef5a7c098d52e1ce9bc3fad2770bf4a5ab086a3
0.3.12013-04-13T03:27:34.451200ZDownloadbc8778e0f36f45ad6a33f6c96b8bd79f4868c8b986ec56a2f0dcb6c9e704b90d
0.3.22013-04-18T01:11:27.302800ZDownloadaec3170f4487921bd245f1e3165b80149aacb5cd637dca2cd1a1f05b71a68b46
0.3.32013-05-04T04:45:37.955250ZDownload7e2a6e41b0643e91edebd56f5a1f3682436ead6439724d6c3d389d71db582565
1.0.02014-08-16T02:46:24.742920ZDownloadb666b0c5c2676fa40fe7b4963dc5b7eb892bfd64082c31015c911dd231e73f25
1.0.22014-08-17T21:55:54.918560ZDownload0ebd41b7c9b0443447fc34b2cc996b8177b8698ed8e9589e7bb04af7bb77ddab
1.1.02014-08-19T02:00:55.812870ZDownload07b61c7b17882faeb5acc5cb4392b25ef442a355210e20485c93b7f4ff97b5d3
1.2.02016-04-23T17:38:25.708ZDownload43ce0b3489187a3f9cc342ac4bf0533fdba42d75e5012650680d3582c6b37396

Dependencies

either "\u003e=0.1.0 \u003c0.2.0"