These are chat archives for ramda/ramda
Hi all. Getting a little bit lost with nested monads here and could use some help:
// findUser :: String -> Future Error (Maybe User) // testPassword :: String -> User -> Future Error (Maybe AuthenticatedUser)
The idea of
findUser is to represent all screw-ups in the Error part in the Future and Maybe to denote whether it was found or not. Similarly with
testPassword - all unexpected screw-ups in the Error part and Maybe denoting whether the passwords match. Any tips on how to compose these 2 together?
(list, ...args) => list.map(x => x(...args))
@kujon I'm new to this stuff but 2 things come to mind. Maybe you could rearrange your args in
testPassword so the
String comes after the
User. That way
testPassword can accept the user from
Also, seeing as a
Future is essentially an async
Either, maybe in
findUser you could
Maybe before returning and encode the error in the
Future instead? (Although I understand if you'd like to keep that level of information).
apis the most magical function to me, It can pretty much do everything, I have never been able to get an intuition for this function
Putting theory to one side. Imagine it as mapping over a dataset for each fn in your list. And then concatenating the resulting list in order.
R.ap([R.multiply(2), R.add(3)], [1,2,3]); //=> [2, 4, 6, 4, 5, 6] //Will have equivalent output to R.concat( R.map(R.multiply(2), [1,2,3]) ,R.map(R.add(3), [1,2,3]) )
Bringing theory back.
ap is used to apply a function that lives in side a container, against another value within another container.
R.ap(Maybe.of(R.add(3)), Maybe.of(4)) //=> Maybe.of(7)
When you translate that to an array with a single value you get a similar output:
R.ap([R.add(3)], ) // => 
Now arrays can hold multiple values. So when our second argument has multiple values, we transform all of them. And when our first argument has multiple functions, we apply all of them. Because we don't want to lose any result, and because the data type of the output has to be the same as the inputs, you end up with a list of all possible results.