These are chat archives for ramda/ramda

1st
Dec 2018
Greg Fagan
@gregfagan
Dec 01 2018 08:04
Hi y'all, I'm trying to figure out how to express what seems like it should be a pretty simple operation: I want to take a list, find the first item that satisfies a predicate, and then return that item and the remainder of the list (without the item) as a pair
something like partition but with a predicate that only returns true once
Ben Briggs
@ben-eb
Dec 01 2018 11:25
@gregfagan Probably something like this (if you don't care about the duplicates):
const partitionFirst = juxt([find, reject])

partitionFirst(equals(1), [4, 1, 2, 3, 1])
Michael Klim
@michael-klim
Dec 01 2018 11:37
Hello guys, I am fairly new to ramda, I would like to use pipeP function, which performs left-to-right composition of one or more Promise-returning functions. But I see that it was deprecated. But I am not quite sure why. How can I use pipe with promise-returning functions now?
Ben Briggs
@ben-eb
Dec 01 2018 11:48
@michael-klim pipeWith(then) ramda/ramda#2702
Michael Klim
@michael-klim
Dec 01 2018 11:48
@ben-eb ooh, I see, thanks a million!
Harry Solovay
@harrysolovay
Dec 01 2018 11:48
@michael-klim niiiice!!! I was about to suggest a much more convoluted approach ahaha. That's awesome
Ben Briggs
@ben-eb
Dec 01 2018 11:49
@michael-klim Alternatively you can use pipe(syncFn, syncFn2, then(asyncFn))
Depends on how many async fns you want to chain I guess :)
Harry Solovay
@harrysolovay
Dec 01 2018 11:50

Another question: is there a way to curry into deeply nested function calls? I'm trying to do the following:

const addWebpackPlugin = (plugin, config) => over(lensProp('plugins'), append(plugin), config)

Like this:

const addWebpackPlugin = over(lensProp('plugins'), append(__), __)
Any way to get the simplified version working?
Maybe it's counterintuitive
Idk––I'd love feedback
:)
Ben Briggs
@ben-eb
Dec 01 2018 11:52
@harrysolovay Have a look into applyTo, am not sure that you can use __ this way
Harry Solovay
@harrysolovay
Dec 01 2018 11:55
@ben-eb thanks! Just checked out applyTo and I'm not sure how I'd be able to use it to simplify creating this function. Any tips? And yea––it's a shame __ can't handle that... it would be so so cool if it worked on nested calls
Ben Briggs
@ben-eb
Dec 01 2018 11:58
@harrysolovay applyTo allows us to do stuff like this:
const fn = curry((a, b, c, d, e) => [a, b, c, d, e]);

const h = compose(applyTo(5), applyTo(4), fn(1, 2))

h(3)
Harry Solovay
@harrysolovay
Dec 01 2018 11:58
How would I use that in this situation?
Ben Briggs
@ben-eb
Dec 01 2018 12:05
@harrysolovay Check out https://gitter.im/sanctuary-js/sanctuary?at=5bf70e95d24f9324d2397c22, for a bit more background, am not sure if it's worth trying to overcomplicate this code just so that you can remove the arguments :)
Apart from the easy win of:
const f2 = plugin => over(lensProp('plugins'), append(plugin));
Harry Solovay
@harrysolovay
Dec 01 2018 12:07
Righttttt
Thank you!!!!!!!!
Ben Briggs
@ben-eb
Dec 01 2018 12:08
@harrysolovay No worries :)
@harrysolovay You can also do const f3 = uncurryN(2, f2) to get the auto-currying back
Harry Solovay
@harrysolovay
Dec 01 2018 12:09
Beautiful! I was wondering why it was returning a function even when config is passed in
Harry Solovay
@harrysolovay
Dec 01 2018 12:27
Another question: how can I delete a deeply-nested prop by its lens?
Riku Tiira
@rikutiira
Dec 01 2018 12:54
lens to the parent object instead and use R.over + R.omit to remove the property you want
Harry Solovay
@harrysolovay
Dec 01 2018 12:54
Cool cool. Thank you @rikutiira
Harry Solovay
@harrysolovay
Dec 01 2018 15:57
is there a version of forEachObjIndexed that allows you to break out of the loop early?
Kurt Milam
@kurtmilam
Dec 01 2018 16:56
Hm, seems like support for reduced could be added to forEach and forEachIndexed.
Brad Compton (he/him)
@Bradcomp
Dec 01 2018 17:00
What are you trying to do? Could you use a combo of toPairs and find instead?
I don’t think too many people are keen on adding more functionality to the forEach functions. I would prefer to see them deprecated...
Greg Fagan
@gregfagan
Dec 01 2018 17:42
is there a way to express this pattern in a "pointfree" style? I'm not sure how to express passing data in both places just by composing ramda functions:
const mapSum = data => map(compose(add, sum)(data))(data)
mapSum([1, 2, 3, 4, 5])
Kurt Milam
@kurtmilam
Dec 01 2018 17:45
Getting rid of forEach would be doing the world a favor.
Kurt Milam
@kurtmilam
Dec 01 2018 18:00
@gregfagan I think this does the trick
const mapSum = chain(o(map, add), sum)
mapSum([1, 2, 3, 4, 5])
// -> [16, 17, 18, 19, 20]

From the chain documentation:

If second argument is a function, chain(f, g)(x) is equivalent to f(g(x), x).

Greg Fagan
@gregfagan
Dec 01 2018 18:23
@kurtmilam Okay, thank you. I'm still a bit confused about how I can generally compose functions that require the data in multiple locations, for example extracting two different paths from an object and then combining those values in some way. Is there a book on FP in JS with Ramda?
Kurt Milam
@kurtmilam
Dec 01 2018 18:46
@gregfagan I'm not familiar with a book, but there are a number of good articles online.
Do you have an example of a problem you're trying to solve?
chain, ap and converge are the three functions that come to mind when I think about needing to apply more than one function to an argument.
Ben Briggs
@ben-eb
Dec 01 2018 18:48
@gregfagan converge should do the trick :)
Kurt Milam
@kurtmilam
Dec 01 2018 18:48
On the other hand, I don't jump through hoops in pursuit of point-free code.
Greg Fagan
@gregfagan
Dec 01 2018 18:50
okay thanks for the advice :) I'll take a look at those functions
Ben Briggs
@ben-eb
Dec 01 2018 18:50
@kurtmilam Yeah, agreed. It's really easy to do that and produce an unreadable mess
Kurt Milam
@kurtmilam
Dec 01 2018 18:52
:thumbsup:
Greg Fagan
@gregfagan
Dec 01 2018 20:25
Is the "Ram" in "Ramda" pronounced more like the name for a male sheep or more like the term for read only memory?
Daniel Gray
@DanielFGray
Dec 01 2018 21:13
..is there a difference?
as an american english speaker, they both soundn the same to me. maybe other accents use different a sounds idk
oh wait, i can't read, you said read only memory not random access memory. i think it's more like RAMda than ROMda
Greg Fagan
@gregfagan
Dec 01 2018 21:53
yeah I guess I could have just spelled it out like you did that would have been easier haha
Daniel Gray
@DanielFGray
Dec 01 2018 22:07
is like lambda but with an r. not to be confused with the other node module rambda
Greg Fagan
@gregfagan
Dec 01 2018 22:15
oh that makes sense. I don't know why I didn't make the connection