These are chat archives for ramda/ramda

19th
Feb 2017
Nicholas Kircher
@MiracleBlue
Feb 19 2017 03:44
Howdy all!
Matt McKellar-Spence
@MattMS
Feb 19 2017 03:45
Welcome! :smile:
Nicholas Kircher
@MiracleBlue
Feb 19 2017 03:46
Hey, I know you! :smile_cat:
Matt McKellar-Spence
@MattMS
Feb 19 2017 03:47
Haha
Rick Medina
@rickmed
Feb 19 2017 16:44
a babel plugin for currying syntax? :thumbsup: / :thumbsdown: ? It would be useful to wrap all native (and user) functions to make compositions more readable
Drew
@dtipson
Feb 19 2017 17:02
so, I've been writing an article about traverse, and I've run into an interesting problem I can't wrap my head around. Basically, the idea is that you can take a datastructure (a List just to keep it simple), annotate it with Either, traverse by turning the Eithers into Tasks, and then traverse again to turn the list into a Task. The result is an operation that can go to the network to retrieve missing data.
And all that actually works out great! (here mocked with Id). A list with some string usernames and some integer ids, and I want to fill in the usernames by using the user ids to "retrieve" their matching string (actual matching not implemented)
['dana',8,'drew',9]
  .map(Either.is(Number))
  .traverse(
    Id.of,
    e=>e.traverse(Id.of, x=>Id('mock username'))
  )
  .fold(I).map(x=>x.fold(I,I));//->['dana','mock username','drew','mock username']
Only the Rights actually run the traversal function, which means that the Rights get (mocked) network requests for data that can take time while the Lefts "return" immediately (just wrapped in point, which for Task.of means there's no request), and since the entire structure is now the same, the list of Tasks can turn into a Task for lists.
Drew
@dtipson
Feb 19 2017 17:08
But here's the tricky bit I can't figure out: what if instead of a network request for each username, I had an api that could take a list of ids and return a list of usernames, thus making it all one network request. How would I get the list of just user ids out of the original list, make the request, and get the results back into the list in the same positions, thus generating the complete list.
I know there's a traversal lens, but I'm not sure if that's the right avenue to explore
Rick Medina
@rickmed
Feb 19 2017 17:38
@dtipson I'm probably missing things, but doesn't it depend on the function that actually makes the network request? ie: whether it receives a single id or a list of ids to be requested?
Drew
@dtipson
Feb 19 2017 17:46
the idea is that previously I had a network api that could map one id to one username, so I can very easily create a Task that represents all those requests... but now suddenly I'm offered one that can do everything I need in just one request. The trick is how I'd get that one request out of the datastructure, and then how I'd get its result back into the datastructure
Drew
@dtipson
Feb 19 2017 17:53
the fact that I can do the first is, by itself, pretty awesome, to be fair. In general, if I have a function that takes an Either, and then traverses it into a Task of an Either, the fact that when I fork it, Rights make the request (which might take time) and Lefts just return the value immediately is... perfect. But turning that into a single request is the logical next step/question
Rick Medina
@rickmed
Feb 19 2017 18:17
@dtipson I agree its pretty cool. So now, let's say, you would use a network function that takes a list of Int and return a Task [Str] (making one trip for the list of ids)? and then the problem is to map the initial list with the list of strings?
or task of list of strings assuming the function interacting with the network returns a task
Sean Cannon
@SeanCannon
Feb 19 2017 18:21
Hey guys quick question
I feel like Ramda should have a core function where I can provide a two lists and an index, and get back a new list where the two have been merged from the index. Like R.combineFrom() or something, like a variation of R.zip and R.insertAll:
const a = ['a','b','c','d','e'], b = ['x','y','z'];
R.combineFrom(1, b, a); // ['a','x','y','z','e'];
Is there one I'm missing or is this a one-off I need to create
Drew
@dtipson
Feb 19 2017 18:23
@rickmed exactly. Neither the request nor the response are of the same List structure as what we want out of the result, but we'd want to preserve structure... while only making the one request
Sean Cannon
@SeanCannon
Feb 19 2017 18:34
https://goo.gl/73dlvO -- is there a better way to do this? or is there a built-in Ramda function I can use outright?
Rick Medina
@rickmed
Feb 19 2017 18:42
@dtipson why don't create a closure which compares the initial list with the result of the network function to return the same structure?
Sean Cannon
@SeanCannon
Feb 19 2017 18:46
https://goo.gl/viFP41 -- alternative I suppose.
Aldwin Vlasblom
@Avaq
Feb 19 2017 18:50
@SeanCannon Using reduce simplifies it, in my opinion: https://goo.gl/XW3hWm
Sean Cannon
@SeanCannon
Feb 19 2017 18:52
Nice I was thinking about using reduce but kept going back to "there has to be a built in R. for this"
Aldwin Vlasblom
@Avaq
Feb 19 2017 18:53
Not that I'm aware of.
Sean Cannon
@SeanCannon
Feb 19 2017 18:58
Works for me. Thanks mate~
Reduce is wicked faster too - got me curious: https://jsperf.com/combinefrom
Galileo Sanchez
@galileopy
Feb 19 2017 19:00

hello i have this

const merger = lift(merge);

and if I have 2 list of objects I will be able to have the cross product of merging each object from a list with each object of the second list, reading a bit I found that the former is equivalent of writing

const merger = xs => ys => ap(ap([merge], xs), ys )
now, what if I want to be able to merge an arbitrary number of object lists?
with 3 lists it would be ap([merge], merger(xs)(ys))(zs)
Markus Pfundstein
@MarkusPfundstein
Feb 19 2017 19:08
smells like recursion
Galileo Sanchez
@galileopy
Feb 19 2017 19:08
it does
Drew
@dtipson
Feb 19 2017 20:02
@rickmed I mean, it would certainly be possible to write a bespoke implementation that examines the indexes of everything and builds an operation to put it all back together, but I mostly feel like I'm missing some existing abstraction/operation
Rick Medina
@rickmed
Feb 19 2017 20:27
@dtipson ohh! (I was confused asking myself why you weren't simplifying it)