These are chat archives for ramda/ramda
Chainand it'll be easier to understand.
R.pipewhich gives the equivalent of
R.pipe(R.tap(log), f, R.tap(log), g, R.tap(log), h, R.tap(log))for
pipeLog(f, g, h). ;)
Nothing()is the empty Maybe value, is it not?
I think that depends on how you want to define your Monoid. That's always a possibility. We have an odd habit in JS of trying to think of
Maybe as the type rather than
Maybe a, and that confuses things a lot.
Monoid m => Maybe m, such that it relies on the
emptyof the value it contains.
concat(semigroup), there is no sane way of
Maybetypes unless you can concat their values.
Lastinstances of monoids for
Maybe awhere the identity is
Just a.identity, the usual one uses
Nothingfor an identity. I find this strange, but a long discussion in the FantasyLand Gitter room convinced me that this is, if nothing else, the most common version.
a(x) || b(x) || c(x)then to use
R.either(R.either(a, b), c)) I feel like I'm looking in the wrong direction if this is what I'm doing.
eithershould return a boolean. That is how I have used it.
trueif any of the functions returned a truthy value, but that value is lost.
err.stack || err.message || err.toString()->
R.either(R.either(R.prop("stack"), R.prop("message")), R.toString)
stepfunction which can be given to any process in order to transform the steps it takes. They're useful for any process that takes a succession of steps (like processing arrays or streams, listening to events, etc), which is not what I'm doing I think.
condlooks like a really close match, except I think I'd have to do:
R.cond([[a,a], [b,b], [c,c]])- which is a bit odd.
transducefor this too I beleive.
R.transduce(R.find(isTruthy), R.defaultTo, null, list). Not sure it works and it isn't all that declarative. I'd write my own function instead
Functors you get a
Functor, if you compose
Applys you get an
Apply, if you compose
Applicatives you get an
Applicative, if you compose
Chains you get an
Apply, if you compose
Monads you get an
Applicative. Monad transformers allow you to compose
Monads and get a
Maybe (Identity a)or
[Either a b]or
Future String [Maybe a]or something.
(Functor f, Functor g) => f (g a)
Functors for example, you know you can always
mapyour way to the actual value.
Monads, you have no such guarantee
Maybewith another monad then I need to have a
Monadup front, like
Maybe [a]then you can say things about it (like you can
chainthe list because you know it's a list). it's when you don't know both
Monads up front, like
Monad m => Maybe m aor more generally
(Monad m, Monad n) => m (n a)(here you can only say that you for sure can
ofall the way down, it's only as powerful as an
Monads you don't necessarily get a new
Monadout of it. But if you use a monad transformer with another
Monad, then you get a new
Monadout of it.
fork. What do I get if I user
Future? Can I fork and/or run it?
Readerand you know you hve a
Future, so you can talk about operations on each piece.
Futurebecause it is async and I need
Maybebecause there may be no match for the id. Should I then use a Future transformer with a maybe?
Monads then there's no way to write the function
chain2 :: (Monad m, Monad n) => m (n a) -> (a -> m (n b)) -> m (n b), which is an attempt to
Monads. And you can prove that there's no way to write that function,
Monadjust isn't powerful enough to do that. So the composition of two
Monads is not a
Monad. If instead you have a monad transformer and a
Monad, then you can write that function.
a -> Maybe bthen you're going to have to
liftall over the place, so it'll be just as crufty as using
mtl-style, which I don't think anyone has done in js yet.
You go from something like
increment :: Monad m => StateT Int m () (this is how most transformers are encoded) to something like
increment :: MonadState Int m => m () (
In the first case, you have to be aware of where the
StateT Int m a is in the stack. So you might have something like
lift $ increment or
lift $ lift $ lift $ increment depending on where you use it in the stack.
In the second case, you can just call
increment anywhere in the stack and it "should" do the right thing.
MonadReader r min part of your stack, you can just
askanywhere and get the
r, like db config or whatever, rather than trying to figure out where you are in the stack and how many lifts are necessary.
R.difference(R.union(a, b), R.intersection(a, b))
R.converge(R.difference, R.union, R.intersection)