Specification for interoperability of common algebraic structures in JavaScript
davidchambers on ci
improve portability of the UMD … (compare)
davidchambers on master
Version 5.0.0 (compare)
davidchambers on v5.0.0
@dtipson
If someone could do a version of this video https://www.youtube.com/watch?v=hmX2s3pe_qk but with javascript instead of Scala, I have a feeling that my mind would be blown. But my inability to follow Scala notation prevents me from following all the way through
chain
everything, instead of dealing with nested types, no?
Reader.T
(https://github.com/ramda/ramda-fantasy/blob/master/docs/Reader.md) ?
@safareli: I like that it just leans on the Monoid laws in regards to concat
. The only other thing missing from those examples (I may have just missed it) is how you go about getting the value out of empty
, e.g.
fold = xs => xs.reduce((m, x) = m.concat(x), empty)
// sums :: Additive
sum = fold([])
You could perhaps adopt something like:
Additive.valueOf = a => a === empty ? 0 : a.value
So type of fold is :: (Monoid m) => [m] -> m
i.e. items in list should be monoids.
sum = fold(["a", "b"]) // should be ["ab"]
foldr f z [] = z
foldr f z (x:xs) = f x (foldr f z xs)
But if we empty list to reduce then it will just return the empty
and will lose the type information which we actually did not had as there is nothing in list, so result of sum = fold([])
would be empty
for instance for the Maybe monad, I can just do
flatMap(f) {
return match(this)
.when(Empty, this)
.when(Just, f(this.__value))
}
where f is a function that returns a Maybe. So I don’t need join here that joins two Maybes…
flatMap(f) {
return match(this)
.when(Empty, this)
.when(Just, Maybe.join(this, f(this.__value)))
}
foldl
f :: (a -> Either Error b)
and call it on a Maybe Monad. While in Haskell this wouldn’t compile.