These are chat archives for ramda/ramda

9th
Mar 2018
Brandon Chartier
@brandonchartier
Mar 09 2018 00:47
reduce/concat usually works for me
Ivanov Ivan
@832bb9
Mar 09 2018 08:02
Hi all! Can someone explain why functions in R.ifElse takes multiple arguments, but functions in R.when and R.unless only one?
Matthew Willhite
@miwillhite
Mar 09 2018 13:28
when(pred, f) is the same as ifElse(pred, f, identity), unless(pred, f) is the same as ifElse(pred, identity, f)
Brad Compton (he/him)
@Bradcomp
Mar 09 2018 16:10
@zhtbcgtw I think you're referring to the fact that the function returned by when and unless only take one parameter take one parameter, while ifElse returns a variadic function. In that case, the answer is that with when and unless if the predicate isn't (or is) satisfied, the input gets returned directly. That doesn't make sense if the input is more than one parameter.
sitty
@sitty
Mar 09 2018 16:32
How can i transform a nested object like this
{ identifier: 'id', prices : [ {key: 'key1', price: 10.05}, {key: key2, price: 20.65}] }
into and nested array like this
[['id', key1, 10.05], ['id', key2, 10.05] ]
Ivanov Ivan
@832bb9
Mar 09 2018 16:35
@Bradcomp, it makes sense, thanks
Matthew Willhite
@miwillhite
Mar 09 2018 16:41
@sitty something this? https://goo.gl/Zn22BM
Brad Compton (he/him)
@Bradcomp
Mar 09 2018 16:42
@ram-bot
map(values, [ {key: 'key1', price: 10.05}, { price: 20.65, key: 'key2' }])
ram-bot
@ram-bot
Mar 09 2018 16:42
[ [ 'key1', 10.05 ], [ 20.65, 'key2' ] ]
Brad Compton (he/him)
@Bradcomp
Mar 09 2018 16:43
@ram-bot
map(props(['key', 'price']), [ {key: 'key1', price: 10.05}, { price: 20.65, key: 'key2' }])
ram-bot
@ram-bot
Mar 09 2018 16:43
[ [ 'key1', 10.05 ], [ 'key2', 20.65 ] ]
Brad Compton (he/him)
@Bradcomp
Mar 09 2018 16:44
I would generally recommend props over values if you care about the order
Other than that though, I fully agree with your solution
Mike Lambert
@lax4mike
Mar 09 2018 16:47
oh, interesting, i wasn't aware of props
Matthew Willhite
@miwillhite
Mar 09 2018 16:53
@Bradcomp :thumbsup:
The explicitness is nice too
Brad Compton (he/him)
@Bradcomp
Mar 09 2018 16:56
Yeah, values would be thrown off if there were extra props too
sitty
@sitty
Mar 09 2018 16:57
thanks @Bradcomp , @miwillhite