These are chat archives for ramda/ramda

5th
Dec 2017
Mike Lambert
@lax4mike
Dec 05 2017 03:02
so, i think this works, but i'm not sure if it'a any clearer...
// uses v from [k, v] from R.toPairs
const withValue = R.over(R.lensIndex(1));

return R.compose(
  R.fromPairs,
  R.adjust(withValue(v => offBy + v), 0), // adjust the biggest one
  R.map(withValue(Math.round)), // round the values
  R.sortBy(withValue(v => Math.round(v) - v)), // largest difference at the top
  R.toPairs
)(percentages);
it's pretty crazy, R.over takes 3 arguments, and we're partially applying it with 1. The 2nd is coming from out our custom logic, then the 3rd goes through sortBy, map, adjust, then into R.over
Mike Lambert
@lax4mike
Dec 05 2017 03:15
i'm not actually sure if that sort is working...
Adam Szaraniec
@mimol91
Dec 05 2017 07:42
I was thinking how can I get min/max from list doing only one loop
It can be done like (but it does looping two times), any ideas how can it be done ?
const minMax = R.converge(R.pair, [(b) => Math.min(...b), (a) => Math.max(...a)])
minMax([1, 2, 3, 4, 5, 6, 7])  //[1,7]
Syaiful Bahri
@syaiful6
Dec 05 2017 08:10
@mimol91 reduce operation can be abstracted to Applicative, and since the operation deferred you will end up doing loop/reduction only once. here simple example: https://goo.gl/YJ1Ay4
Adam Szaraniec
@mimol91
Dec 05 2017 08:36
Thanks, I will try to deeply look into it. Recently I was reading about transducers, and I tried to do it using them.
Syaiful Bahri
@syaiful6
Dec 05 2017 08:41
@mimol91 that example i give isn't tranducers, all it's do is capturing reduce operation and initial value.
Jakub R Pawlowski
@jakubrpawlowski
Dec 05 2017 08:41
Syaiful Bahri
@syaiful6
Dec 05 2017 08:42
i basically porting Gabriel's library in haskell: https://github.com/Gabriel439/Haskell-Foldl-Library
Adam Szaraniec
@mimol91
Dec 05 2017 09:46
thanks, definitely will watch it today
Matías Fidemraizer
@mfidemraizer
Dec 05 2017 11:56
hey! is there any Ramda function to get object keys and values in separate arrays (i.e. [["a", "b"], [1, 3]])?
James Forbes
@JAForbes
Dec 05 2017 12:35
you could do something like unapply(ap([ keys, values ]))
Barry G
@bgits
Dec 05 2017 13:59
Is there a way to set a nested path on an object without having to define a lens?
Matías Fidemraizer
@mfidemraizer
Dec 05 2017 14:00
@JAForbes Thanks, I'm going to try it :D
@JAForbes now I've double checked your proposal
Matías Fidemraizer
@mfidemraizer
Dec 05 2017 14:05
I don't have keys and values before doing so (otherwise, I wouldn't need a function)
why would I need unapply/ap if I could do this: [ Object.keys(obj), Object.values(obj) ]. What's wrong here? Order isn't guaranteed
Denis Stoyanov
@xgrommx
Dec 05 2017 15:33
juxt([keys, values])
Brad Compton (he/him)
@Bradcomp
Dec 05 2017 16:39
@bgits R.assocPath?
Alec
@alavkx
Dec 05 2017 17:48
@mfidemraizer the keys and values they are referring to are ramda functions R.keys and R.values. Your solution would work, but it assumes you have the data you are operating on. In a composition, it would have to look more like.. obj => [Object.keys(obj), Object.values(obj)]
The difference is strictly style
R.keys
Alec
@alavkx
Dec 05 2017 17:49
R.values