dartz 0.8.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 81

dartz

Functional programming in Dart

  • Type class hierarchy in the spirit of cats, scalaz and the standard Haskell libraries
  • Immutable, persistent collections, including IVector, IList, IMap, IHashMap, ISet and AVLTree
  • Option, Either, State, Tuple, Free, Lens and other tools for programming in a functional style
  • Evaluation, a Reader+Writer+State+Either+Future swiss army knife monad
  • Type class instances (Monoids, Traversable Functors, Monads and so on) for included types, as well as for several standard Dart types
  • Conveyor, an implementation of pure functional streaming (Dart 1 only, for now)
  • Examples, showcasing core concepts
New to functional programming?

A good place to start learning is the excellent Functional Programming in Scala by Paul Chiusano and Rúnar Bjarnason. I can not recommend this book highly enough.

Transition to Dart 2

dartz was originally written for Dart 1, whose weak type system could be abused to simulate higher-kinded types. Dart 2 has a much stricter type system, making it impossible to pull off the same trick without regressing to fully dynamic typing. Therefore, the open, type class based design of older versions of dartz is gradually being replaced by a more closed design, with a fixed set of type class instances interacting through hard coded logic. Some things, such as monad transformers, will probably have to be completely removed. Starting with version 0.8.0 and going forward, more and more of dartz will be Dart 2 compatible, at the expense of many breaking API changes. If you are developing for Dart 1, you might be happier sticking with version 0.7.5.

Status for versions >= 0.8.0
  • Core design is in flux, with a lot of restructuring going on
  • Basic functionality of collections, tuples, Evaluation, Option, Either, State and Free works on Dart 2
  • Everything still works on Dart 1
  • Conveyor is currently broken on Dart 2
  • Explicit type class hierarchy is still in there, but is going away in 0.9.x
Status for versions < 0.8.0
  • Basic type class structure and collection classes are relatively stable
  • Optimized for dart2js/node/v8, with performance on the dart vm being of distant secondary concern
  • Most things are stack safe and reasonably efficient, but there are a couple of exceptions and plenty of room for further optimizations
  • The streaming/conveyor stuff is highly experimental
  • The lens implementation is experimental and very bare bones
License/Disclaimer

See LICENSE

Changelog

0.8.2

  • Added isLeft, isRight and swap to Either
  • Fixed some type issues on 2.1.0-dev.6.0

0.8.1

  • Massive performance improvements for many operations on IMap on Dart 2
    • Inserts and lookups are now almost as fast on Dart 2 as on Dart 1
  • Fixed some tests that passed for the wrong reason...

0.8.0

  • Bridge release with few breaking changes, full Dart 1 support and rudimentary Dart 2 support
  • (0.9.0 will probably be Dart 2 only and have lots of breaking changes)
  • Basic things work correctly on Dart 2 -- many other things don't...
  • Started work on removing type class hierarchy, with hard coded replacements such as IList#traverseFuture being added
  • Temporarily replaced propcheck with quick'n'dirty minimal replacement, while it is being updated for Dart 2
  • Disabled some broken monad transformer tests, since they probably won't survive the move to Dart 2

0.7.5

  • IMap.fromPairs and IHashMap.fromPairs, for constructing maps from sequences of Tuple2
  • IList.flattenIList and IVector.flattenIVector for type safe flattening of IList/IVector
  • IList.flattenOption and IVector.flattenOption for type safe flattening/uniting IList/IVector of Option

0.7.4

  • Corrected analyzer errors on recent Dart 2 dev releases

0.7.3

  • More useful types for eitherM()
  • Declared argument type F of '>>' on MonadOps as covariant, enabling better specialization in implementations
  • Specialized types for replace on StateT
  • Fixed buggy foldLeftWithIndex/foldRightWithIndex on IVector

0.7.2

  • Added curried versions of several Lens members (setC, modifyC and so on)
  • Improved typing for generic methods on Evaluation
  • More type information retained for filter operations on MonadPlus instances
  • Added custom filter operation on Either
  • Introduced 'where' as an alias to filter where applicable

0.7.1

  • Added foldLeftWithIndexBetween and foldRightWithIndexBetween to IVector
  • Added cata and order to IMap
  • Exposed step operation on Free, enabling manual bind reassociation for now

0.7.0

  • Preparations for Dart 2.0
  • Improved type safety for IMap and ISet
    • Reworked and/or removed functions/constructors that implicitly assumed that keys/members implemented Comparable
    • Added replacement helpers for constructors that couldn't be saved
    • All dependencies on Comparable are now explicit and enforced by the type system
  • IMap additions:
    • getKey
    • mapKV
    • traverseKV
    • traverseKV_

0.6.3

  • Added:
    • foldLeftBetween and foldRightBetween operations to AVLTree
    • foldLeftBetween, foldRightBetween and subSetBetween operations to ISet
    • regexp pipe to Text utilities
    • IList.generate factory constructor
    • ifM combinator and some type refinements to Free
    • Eq instances for Iterators
  • More memory efficient and faster equality checks for IMap, IHashMap, AVLTree, ISet and IVector
  • New, slightly more advanced example for streaming IO

0.6.2

  • I goofed up... the "efficient file reads" from 0.6.1 now actually work!

0.6.1

  • Way more efficient file reads using Free IO and Conveyor
  • Improved typing for Applicative liftX and mapX, with specialized overrides on Option and Either
  • Added optionOf utility, for safely wrapping a possibly null value in Option
  • Added forEach operation to dartz_unsafe, for performing side effects on Foldables
  • Added forEach operations to Option, Either, IList, IVector, ISet, IMap, IHashMap and AVLTree
  • Various small tweaks, additions and bug fixes

0.6.0

  • Updated sdk requirement to >= 1.24.0
    • Now uses real (non-commented) generic method syntax
    • Takes advantage of improvements in strong mode type inference
    • Various workarounds for remaining strong mode quirks

0.5.7

  • Added efficient operations related to lower/upper bounds to IMap:
    • min
    • max
    • minKey
    • maxKey
    • minGreaterThan
    • maxLessThan
    • foldLeftKVBetween
    • foldRightKVBetween
  • hashCode consistent with '==' where overridden

0.5.6

  • 'Gather' IO primitive for parallelizing IO operations
  • Refined types for map2 to map6 on Free and IO monads
  • Improvements to type safety/inference for Free and IO

0.5.5

  • Slightly less efficient, but more correct/safe traverse for IList
  • Better type inference for Either and Future Monad instance helpers

0.5.4

  • Added modifyE to EvaluationMonad, for state updates that can fail
  • Either, Option, Evaluation, State, StateT and Free:
    • Tightened types of various derived operations, such as flatMap, andThen and <<

0.5.3

  • Reworked Free to be stack safe in more cases
    • Implementations more similar to the ones in scalaz and cats
    • Still a work in progress, but works for basic use cases
  • Added TraversableMonad instance for Function0

0.5.2

  • Improved performance of set operation on IMap and IVector
  • Added setIfPresent to IMap
  • Added setIfPresent, removeFirst, dropFirst, removeLast and dropLast to IVector
  • Added window and windowAll to Pipe and Conveyor

0.5.1

  • Added experimental Lens implementation and example!
  • Added IMap.fromIterables
  • Slightly faster get operations on IMap and AVLTree

0.5.0

  • Swallowed a chunk of purist pride:
    • Added toIterable and iterator operations to Option, Either and all immutable collections
    • Added iterables/iterators for pairs, keys and values to IMap and IHashMap

0.4.5

  • Added minSi and maxSi to Order
  • Added reverse to TraversableMonadPlus
  • Added zip to IList

0.4.4

  • Tightened types of some overrides and helpers
  • Added free IO primitive Delay
  • Added scanWhile to Pipe
  • Added foldWhile to Conveyor
  • Added repeatEval and repeatEval_ to Source

0.4.3

  • Added uniteOption to Pipe
  • Added chunk to Pipe and Conveyor
  • Square bracket syntax as alternative to get(K key) on IMap and IHashMap
  • Got rid of all implicit down casts by disabling them in the analysis options
  • Cleaner types on Pipe

0.4.2

  • Aggressive internal optimizations in IList, for speed and memory efficiency
  • Much faster map and bind/flatMap IList operations, especially on V8
  • Slightly faster map operations on IMap and IVector

0.4.1

  • Helpers for composing Free algebras and interpreters through coproduct nesting
  • Free composition example
  • Moved Free IO primitives into IOOps, for easy composition with other Free algebras
  • emptyMap and singletonMap convenience functions for IMap
  • Some more convenience functions for Conveyor

0.4.0

  • New mini library, dartz_streaming!
  • Moved Conveyor and friends to dartz_streaming
  • Added lots of stream combinators for general use, IO and text processing
  • Added Execute IO primitive for running external commands
  • Beefed up mock IO interpreter

0.3.6

  • foldLeftWithIndex and foldRightWithIndex on Foldable/FoldableOps
  • Specialized foldLeftWithIndex/foldRightWithIndex implementations on IVector
  • Source.fromStream (Conveyor) now takes a Stream thunk instead of a direct Stream
  • Minor cleanups in streaming IO example

0.3.5

  • Improved resource safety of Conveyor primitives
  • repeatUntilExhausted, repeatNonEmpty, intsFrom, window2 and window2all operations for Conveyor
  • Corrections for stronger strong mode

0.3.4

  • repeatNotEmpty operation for Conveyor
  • Opaque FileRefs in Free IO
  • Proper type parameterization for derived Tuple Semigroups and Monoids

0.3.3

  • Tee construct for combining Conveyors
  • tee, zip, zipWith, interleave, intersperse and constant operations on Conveyor
  • through and to operations for effectful sinks and channels on Conveyor
  • Moved Free IO algebra back into library
  • Extracted side effecting IO interpreter into "unsafe" mini library

0.3.2

  • Updated for the improvements to strong mode in Dart 1.19.0
  • Fully mockable IO type and other cleanups in examples

0.3.1

  • Renamed Conveyor primitives (await -> consume, emit -> produce)
  • Added identity, drop and dropWhile operations to Pipe and Conveyor
  • Added Source#fromStream for driving Conveyors from Dart Streams
  • Helpers for creating anonymous Eq instances
  • ObjectEq Eq instance for comparing Objects for equality using '=='
  • Beefed up mock IO interpreter in Free IO example
  • Funner, faster and longer streaming IO example

0.3.0

  • Conveyor, an experimental implementation of functional streams, based on work by Chiusano/Bjarnason (chapter 15 in FPIS)
  • Clarified Free IO example
  • Added Streaming IO example, based on Free IO and Conveyor

0.2.5

  • MonadCatch type class
  • Simplistic Task implementation, with MonadCatch instance

0.2.4

  • Fixed incompatibilities with dart2js

0.2.3

  • New TraversableMonadPlus type class, with partition operation
  • TraversableMonadPlus instances for IList, List, IVector and Option
  • prependElement and appendElement operations for ApplicativePlus
  • better type inference for applicative mapX operations on Option and Either
  • uncons, unconsO and sort operations for IList

0.2.2

  • Added Free IO example

0.2.1

  • Added two examples
  • Foldable instance for ISet
  • liftOption operation for Evaluation
  • foldMapM operation for Foldable
  • More type annotations and convenience functions

0.2.0

  • New TraversableMonad and TraversableMonadOps
  • Moved traverseM operation to TraversableMonadOps
  • Removed IO stuff
  • Removed redundant type class instance aliases. Use IListMP instead of IListA, and so on
  • Gave up on mixin inheritance chains, since dart2js still doesn't implement them properly

0.1.3

  • Inspire dart2js to insert fewer cast checks and other runtime type paranoia, leading to significant performance improvements all over the place
  • Type parameters for Option mapX operations
  • traverseM operation for Traversable

0.1.2

  • IHashMap, an immutable and persistent map that, unlike IMap, doesn't require a total ordering of keys, but instead relies on hashCode and equality of keys
  • Even more method/function type parameters added
  • More efficient primitives for State and Evaluation

0.1.1

  • A lot more method/function type parameters for better type safety/inference
  • find and specialized filter operations for IList
  • Modified all tests for strong mode compliance
  • orElse and eager getOrElse operator '|' for Either
  • orElse and getOrElse operations on Option and Either take thunks instead of values
  • Faster IMap modify
  • Various cleanups

0.1.0

  • Dart Strong Mode compliance. This forced a couple of breaking changes:
    • Use Option<A> none<A>() instead of Option<dynamic> none
    • Prefer IList<A> nil<A>() to IList<dynamic> Nil
    • ...and so on for emptyVector, IMapMi, etc.
  • Much improved type safety through type parameterization of commonly used methods/functions, using the prototype syntax. More type annotations to come!

0.0.10

  • Fixed embarrassing bug in IMap#set. Let's never mention it again.

0.0.9

  • IVector, an immutable and persistent indexed sequence with O(log n) prepend, append, get and set operations
  • MonadPlus, Traversable and Monoid instances for IVector
  • Faster List monoid
  • Faster map and new set operation for IMap
  • strengthL and strengthR operations for Functor
  • foldLeftM and foldRightM operations for Foldable

0.0.8

  • Improved compatibility with dart2js, Dartium and dart strong mode
  • Proper type parameters for Tuple semigroups and monoids

0.0.7

  • Much faster and leaner IMap
  • Significantly faster and leaner ISet and AVLTree
  • Slightly faster IList

0.0.6

  • Significantly faster and lighter AVLTree, IMap and ISet
  • Corrected a couple of type annotations in IList and Evaluation

0.0.5

  • toIterable and iterator operations for IList
  • Faster, stack safe equality checks for IList, IMap, ISet and AVLTree
  • Tighter types for id and Endo

0.0.4

  • Bind Evaluation and Future through microtask queue by default
  • Optimized map implementations for Evaluation and Future
  • Retain more type information in Evaluation and EvaluationMonad operations
  • Added liftEither and handleError operations to Evaluation/EvaluationMonad

0.0.3

  • Default foldMap for Traversable is now trampolined
  • Moved State primitives to StateMonad
  • MonadPlus instance for List
  • reverse operation for Order
  • modify, foldLeftKV, foldRightKV, foldMapKV, mapWithKey and optimized Foldable operations for IMap
  • Curried appendC for Semigroup

0.0.2

  • Order constructs (order, orderBy, min and max semigroups)
  • length, any, all, minimum and maximum operations for Foldable
  • Plus, PlusEmpty, ApplicativePlus and MonadPlus type classes
  • MonadPlus instances for Option and IList
  • ISet monoid and operations for union, intersection and difference
  • Option and Either utils (cata, toOption, catching)
  • StateT
  • Trampoline
  • mapWithIndex and zipWithIndex for Traversable

0.0.1

  • The immutable conception

example/example.dart

main() {
  print("See sub directories for topic specific examples!");
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dartz: ^0.8.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dartz/dartz.dart';
  
Version Uploaded Documentation Archive
0.8.2 Oct 10, 2018 Go to the documentation of dartz 0.8.2 Download dartz 0.8.2 archive
0.8.1 Sep 30, 2018 Go to the documentation of dartz 0.8.1 Download dartz 0.8.1 archive
0.8.0 Aug 19, 2018 Go to the documentation of dartz 0.8.0 Download dartz 0.8.0 archive
0.7.5 Apr 15, 2018 Go to the documentation of dartz 0.7.5 Download dartz 0.7.5 archive
0.7.4 Mar 8, 2018 Go to the documentation of dartz 0.7.4 Download dartz 0.7.4 archive
0.7.3 Feb 28, 2018 Go to the documentation of dartz 0.7.3 Download dartz 0.7.3 archive
0.7.2 Jan 21, 2018 Go to the documentation of dartz 0.7.2 Download dartz 0.7.2 archive
0.7.1 Nov 19, 2017 Go to the documentation of dartz 0.7.1 Download dartz 0.7.1 archive
0.7.0 Oct 21, 2017 Go to the documentation of dartz 0.7.0 Download dartz 0.7.0 archive
0.6.3 Sep 18, 2017 Go to the documentation of dartz 0.6.3 Download dartz 0.6.3 archive

All 54 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
68
Health:
Code health derived from static analysis. [more]
88
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
81
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:dartz/dartz.dart.

Health suggestions

Fix lib/src/state.dart. (-2.96 points)

Analysis of lib/src/state.dart reported 6 hints, including:

line 6 col 43: The generic type comment is being deprecated in favor of the real syntax.

line 6 col 89: The generic type comment is being deprecated in favor of the real syntax.

line 6 col 125: The generic type comment is being deprecated in favor of the real syntax.

line 40 col 48: The generic type comment is being deprecated in favor of the real syntax.

line 40 col 98: The generic type comment is being deprecated in favor of the real syntax.

Fix lib/src/streaming/conveyor.dart. (-2.96 points)

Analysis of lib/src/streaming/conveyor.dart reported 6 hints, including:

line 12 col 58: The generic type comment is being deprecated in favor of the real syntax.

line 12 col 107: The generic type comment is being deprecated in favor of the real syntax.

line 12 col 156: The generic type comment is being deprecated in favor of the real syntax.

line 12 col 195: The generic type comment is being deprecated in favor of the real syntax.

line 12 col 238: The generic type comment is being deprecated in favor of the real syntax.

Fix lib/src/either.dart. (-2.48 points)

Analysis of lib/src/either.dart reported 5 hints:

line 4 col 58: The generic type comment is being deprecated in favor of the real syntax.

line 4 col 101: The generic type comment is being deprecated in favor of the real syntax.

line 4 col 144: The generic type comment is being deprecated in favor of the real syntax.

line 4 col 181: The generic type comment is being deprecated in favor of the real syntax.

line 4 col 229: The generic type comment is being deprecated in favor of the real syntax.

Fix additional 46 files with analysis or formatting issues. (-3.98 points)

Additional issues in the following files:

  • lib/src/evaluation.dart (3 hints)
  • lib/src/free.dart (3 hints)
  • lib/src/unsafe/io.dart (2 hints)
  • lib/dartz.dart (Run dartfmt to format lib/dartz.dart.)
  • lib/src/applicative.dart (Run dartfmt to format lib/src/applicative.dart.)
  • lib/src/applicative_plus.dart (Run dartfmt to format lib/src/applicative_plus.dart.)
  • lib/src/avl_tree.dart (Run dartfmt to format lib/src/avl_tree.dart.)
  • lib/src/builtins.dart (Run dartfmt to format lib/src/builtins.dart.)
  • lib/src/dual.dart (Run dartfmt to format lib/src/dual.dart.)
  • lib/src/endo.dart (Run dartfmt to format lib/src/endo.dart.)
  • lib/src/eq.dart (Run dartfmt to format lib/src/eq.dart.)
  • lib/src/foldable.dart (Run dartfmt to format lib/src/foldable.dart.)
  • lib/src/free_composition.dart (Run dartfmt to format lib/src/free_composition.dart.)
  • lib/src/function.dart (Run dartfmt to format lib/src/function.dart.)
  • lib/src/functor.dart (Run dartfmt to format lib/src/functor.dart.)
  • lib/src/future.dart (Run dartfmt to format lib/src/future.dart.)
  • lib/src/id.dart (Run dartfmt to format lib/src/id.dart.)
  • lib/src/ihashmap.dart (Run dartfmt to format lib/src/ihashmap.dart.)
  • lib/src/ilist.dart (Run dartfmt to format lib/src/ilist.dart.)
  • lib/src/imap.dart (Run dartfmt to format lib/src/imap.dart.)
  • lib/src/io.dart (Run dartfmt to format lib/src/io.dart.)
  • lib/src/iset.dart (Run dartfmt to format lib/src/iset.dart.)
  • lib/src/ivector.dart (Run dartfmt to format lib/src/ivector.dart.)
  • lib/src/lens.dart (Run dartfmt to format lib/src/lens.dart.)
  • lib/src/list.dart (Run dartfmt to format lib/src/list.dart.)
  • lib/src/monad.dart (Run dartfmt to format lib/src/monad.dart.)
  • lib/src/monad_catch.dart (Run dartfmt to format lib/src/monad_catch.dart.)
  • lib/src/monad_plus.dart (Run dartfmt to format lib/src/monad_plus.dart.)
  • lib/src/monoid.dart (Run dartfmt to format lib/src/monoid.dart.)
  • lib/src/option.dart (Run dartfmt to format lib/src/option.dart.)
  • lib/src/order.dart (Run dartfmt to format lib/src/order.dart.)
  • lib/src/plus.dart (Run dartfmt to format lib/src/plus.dart.)
  • lib/src/plus_empty.dart (Run dartfmt to format lib/src/plus_empty.dart.)
  • lib/src/semigroup.dart (Run dartfmt to format lib/src/semigroup.dart.)
  • lib/src/streaming/io.dart (Run dartfmt to format lib/src/streaming/io.dart.)
  • lib/src/streaming/pipe.dart (Run dartfmt to format lib/src/streaming/pipe.dart.)
  • lib/src/streaming/source.dart (Run dartfmt to format lib/src/streaming/source.dart.)
  • lib/src/streaming/tee.dart (Run dartfmt to format lib/src/streaming/tee.dart.)
  • lib/src/streaming/text.dart (Run dartfmt to format lib/src/streaming/text.dart.)
  • lib/src/task.dart (Run dartfmt to format lib/src/task.dart.)
  • lib/src/trampoline.dart (Run dartfmt to format lib/src/trampoline.dart.)
  • lib/src/traversable.dart (Run dartfmt to format lib/src/traversable.dart.)
  • lib/src/traversable_monad.dart (Run dartfmt to format lib/src/traversable_monad.dart.)
  • lib/src/traversable_monad_plus.dart (Run dartfmt to format lib/src/traversable_monad_plus.dart.)
  • lib/src/tuple.dart (Run dartfmt to format lib/src/tuple.dart.)
  • lib/src/unit.dart (Run dartfmt to format lib/src/unit.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.0 <3.0.0
Dev dependencies
test >=0.12.4+5