These are chat archives for ramda/ramda

Jun 2016
Jun 17 2016 01:04
Arrays are basically just weird objects in js though, no? Another sort of List type can have stronger, or more specific, properties than native arrays
Jakub Korzeniowski
Jun 17 2016 08:44

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?

Tushar Mathur
Jun 17 2016 12:35
Ramda alternative for —
(list,  ...args) => => x(...args))
Calling a list of functions with some arg
James Forbes
Jun 17 2016 13:34

@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 findUser via chain/composeK/pipeK.

Also, seeing as a Future is essentially an async Either, maybe in findUser you could join the Maybe before returning and encode the error in the Future instead? (Although I understand if you'd like to keep that level of information).

@tusharmath ap might be close enough. It applies a list of functions to a list of values

Tushar Mathur
Jun 17 2016 13:37
ap is the most magical function to me, It can pretty much do everything, I have never been able to get an intuition for this function
James Forbes
Jun 17 2016 13:40
Yeah its a strange one. I think the reliance on adding number in the examples may be the root problem.
Aldwin Vlasblom
Jun 17 2016 13:40
That's because ap considers a lot of things to be a list.
Or more specifically, Applicatives.
James Forbes
Jun 17 2016 13:46

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(, [1,2,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)], [4]) // => [7]

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.

Tim Navrotskyy
Jun 17 2016 14:15
@JAForbes do you collect your explanations somewhere in gists or something?
they are so good, you could collect yourself a book by now
James Forbes
Jun 17 2016 14:19
haha thanks @dypsilon - I don't unfortunately.
McClain Looney
Jun 17 2016 15:11
is there a good lib that implements the common functors (been looking at folktale, but not sure if appropriate)
Either, Maybe etc
data.Task in particular seems handy
intending to keep using ramda tho, of course :)
Brad Compton (he/him)
Jun 17 2016 15:27
@mlooney I've used Folktale for Maybe and Task. I've also used Sanctuary for Maybe (if you like runtime type checking it's great) and Fluture for Futures / Tasks. They are all good choices as far as I'm concerned
There's also Ramda-Fantasy
McClain Looney
Jun 17 2016 15:31
cool, tx
presumably all the monads & such will work fine w/ R.compose etc
Brad Compton (he/him)
Jun 17 2016 15:32
Yes. So they all comply with the Fantasy Land spec, so they're fairly interchangeable
Ramda is a really nice fit for working with those data structures