immutable-ext
fantasyland extensions for immutablejs
Install
npm install immutable-ext
What is this?
In addition to the Functor, Foldable, and Monad functions, we now have:
- Monoid
- Applicative (list only right now)
- Traversable
Plus stuff that builds off of reduce like foldMap
. Please contribute/complain as you want/need things.
Examples
We can now traverse without messing with Array or Object:
const List Map = const Task = const IO = // Given Http.get :: String -> Task Error Blog List // List(Blog, Blog) Maphome: "<div>homepage</div>" faq: "<p>ask me anything</p>" // IO(Map({home: "[dom]", faq: "[dom]"})
We can fold
stuff down
const Disjunction Additive = List//[1,2,3,4,5,6] Mapa: "hidy" b: "hidy" c: "ho"// "hidyhidyho" List // Map({a: Additive(6), b: Disjunction(true), c: "sonofagun", d: [1,2,3], e: 'wut'})))
foldMap
some things
List// Additive(10) Mapa: true b: false// Disjunction(true)
We can ap
to get us some list comprehensions
List // List('a+', 'a-', 'b+', 'b-', 'c+', 'c-')