These are chat archives for ramda/ramda

16th
Mar 2015
James Forbes
@JAForbes
Mar 16 2015 00:04

@raine I had written a similar logging function, that shows the argument names too by parsing the func.toString() Which is kind of hacky and error prone, but it worked for me at the time.

https://github.com/JAForbes/proxyLog

Asaf
@asaf-romano
Mar 16 2015 08:07
Hey all, if I want to do something like functional-izing map.values, resulting in a getMapValues function that take a map, is |R.pipe(R.bind(Map.prototype.values), R.call)| the best way to construct such function?
Asaf
@asaf-romano
Mar 16 2015 08:20
(Ideally, it'd be getValues, so it also works for Set.prototype.values)
Martin Algesten
@algesten
Mar 16 2015 08:30
@asaf-romano check out R.invoke I suspect it will solve your Map/Set problem.
Asaf
@asaf-romano
Mar 16 2015 08:50
looking
R.invoker(0, "values") works indeed
@algesten thanks much!
probably a good idea to mention it in the bind documentation, or the other way around
I was looking for "bound" in the docs, and only found bind
Scott Sauyet
@CrossEye
Mar 16 2015 08:59
We probably need a lot more cross-referencing in the docs.
Martin Algesten
@algesten
Mar 16 2015 09:04
np
Asaf
@asaf-romano
Mar 16 2015 09:54
btw, is it planned to support Map and Set in functions like R.values/keys?
it seems that while I can workaround my issue with invoker, ramda plays much better with my code if I go back to pojos
Sergey Lapin
@lapanoid
Mar 16 2015 14:21
This message was deleted

Hey everyone, I want to change this ugly lodash code

decomposeChangeComposeObject = (data, changeFunc)->
  _.object(_.map(_.pairs(data), (item)->
    return [item[0], changeFunc(item[1])]
  ))

to something more elegant with ramda, but I did not find object func, some help please..

Sergey Lapin
@lapanoid
Mar 16 2015 14:29
found it! object is fromPairs
Nate Wildermuth
@wildermuthn
Mar 16 2015 14:54
@joneshf Hey, thanks for the help with that filtering function. Chain/flatMap was the missing piece of the puzzle for me, letting me filter multiple times on the same set of data.
Nate Wildermuth
@wildermuthn
Mar 16 2015 15:07
Is there a Ramda function to use R.eqDeep on unlimited number of arguments?
nvm, map + eqDeep comes to mind.
Hardy Jones
@joneshf
Mar 16 2015 15:35
@lapanoid it looks like you want mapObj: http://ramdajs.com/docs/#mapObj
assuming that what you wrote in lodash was mapValues: https://lodash.com/docs#mapValues
@wildermuthn great!
Nate Wildermuth
@wildermuthn
Mar 16 2015 17:12
@joneshf, I ended up using this: http://goo.gl/Pa3xsI
// joneshf solution modified
var getMetricsById = items => R.pipe(
  R.propEq('id'),
  R.flip(R.filter)(items), 
  R.pluck('metrics')
);

var metrics3 = R.chain(
  getMetricsById(items), 
  videoIds
);
This message was deleted
John-David Dalton
@jdalton
Mar 16 2015 17:55
Here's the perf of those http://jsperf.com/compare-rdma#chart=bar
Nate Wildermuth
@wildermuthn
Mar 16 2015 18:00
That is a remarkable graph.
I think this whole experience with Ramda is pushing me to adopt Clojurescript! :)
Jethro Larson
@jethrolarson
Mar 16 2015 18:01
I could see that. Though clojure doesn't emphasize currying as much
(+ 1) ;; == 1
rather than a curried Add1 function
Nate Wildermuth
@wildermuthn
Mar 16 2015 18:06
Yeah, I don't see a lot of currying in Clojure, since it can accept unlimited arguments. (+ 1 2 3 4) etc.
Jethro Larson
@jethrolarson
Mar 16 2015 18:06
Speaking of clojure, I found that they call our R.nix(formerly R.not) complement I don't really think it's better, but it's out there in use...
Nate Wildermuth
@wildermuthn
Mar 16 2015 18:06
Does have partial, though. (def add1 (partial + 1))
Jethro Larson
@jethrolarson
Mar 16 2015 18:07
Yeah, that can cover the bases.
Nate Wildermuth
@wildermuthn
Mar 16 2015 18:09
Of course, you could use a macro to define a function that is auto-curried.
Jethro Larson
@jethrolarson
Mar 16 2015 18:09
I'm not versed in clojure enough to know what the benefit of making the uniary + * / etc just apply the passed argument against the unit. making that a partial deems more useful.
Nate Wildermuth
@wildermuthn
Mar 16 2015 18:10
But anyhow, the performance of Ramda does seem to be an issue for me as I deal with larger and larger datasets. As someone who doesn't know Ramda all that well, it's hard to know if I'm simply doing it wrong or if that's just the cost of using Ramda.
Jethro Larson
@jethrolarson
Mar 16 2015 18:12
Hopefully when transducers drop it'll be easier to do operations without iterating over the data set repeatedly
We going to do a big perf pass pre 1.0 or post?
Jethro Larson
@jethrolarson
Mar 16 2015 18:18
i.e. compose(filter, map) currently goes over the array twice where with either a transducer or lazy approach would only go over it once.
Hardy Jones
@joneshf
Mar 16 2015 18:25
I think you need more than laziness to get fusion.
Martin Algesten
@algesten
Mar 16 2015 18:29
why isn’t compose implemented using a simple reduce?
compose = (fs...) -> R.reduce fs, (f, g) -> (as...) -> f g as…
but then i got the R.reduce argument order wrong.
but you get the idea.
Walle Cyril
@GrosSacASac
Mar 16 2015 18:36
is it possible to make range work the same as in python ?
list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list(range(1, 11))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
list(range(0, 30, 5))
[0, 5, 10, 15, 20, 25]
so 3 behaviours
Danny Fritz
@dannyfritz
Mar 16 2015 18:42
variable arity doesn't work very well with curried functions @GrosSacASac
Walle Cyril
@GrosSacASac
Mar 16 2015 18:44
thats why I propose a range2
Danny Fritz
@dannyfritz
Mar 16 2015 18:47
range2 takes 3 args?
min, max, step?
Martin Algesten
@algesten
Mar 16 2015 18:50
they can all be the same function. just set to different arity.
i'm missing a shift step for min not 0 in this
Walle Cyril
@GrosSacASac
Mar 16 2015 19:01
we can also do R.map(R.partial(F["*"],step), R.range(startx, endx)) instead of range2 but you have to calculate startx and endx
to have [0,5,10] you have to do
R.map(R.partial(F["*"],5), R.range(0, 3))
Walle Cyril
@GrosSacASac
Mar 16 2015 19:29
VERY NICE
Danny Fritz
@dannyfritz
Mar 16 2015 19:31
I thought python's range was max exclusive though
Walle Cyril
@GrosSacASac
Mar 16 2015 19:57
Is R.partial useless if we know how to use R.curry ?
Sergey Lapin
@lapanoid
Mar 16 2015 20:02
@
Walle Cyril
@GrosSacASac
Mar 16 2015 20:07
how many people use ramda ?
I use partial rarely, but it does have different behavior than curry. Some might prefer it
Jason Marmon
@jtmarmon
Mar 16 2015 20:43
hey @CrossEye !
came to present my case for #930 ;)
Scott Sauyet
@CrossEye
Mar 16 2015 20:44
No idea how many users. Until NPM stats stopped working last week, we watched a steady uptick in downloads. But that's not a great way too estimate users.
Jason Marmon
@jtmarmon
Mar 16 2015 20:45
so a more concrete example: I use an API framework called actionherojs. in actionhero, you can create tasks for processing small things you want to be handled off your barebones api (e.g. sending email and push notifications)
every task is passed a 'next' callback when invoked, and whatever data is passed back to next is shown in the logs. generally I try to keep my logs clean by just passing back nothing when the task runs successfully
however, when i interface with promises, I get an issue: findAllDocumentsInMongoPromise.then(next) will pass all those documents into the logs, for example
I also see this issue a lot when i write tests that interface with callback-based libs

so it would be nice to have a way to pre-determine the value passed to a function, ignoring the second value passed, so I could do

findAllDocumentsInMongoPromise.then(R.package(null, next)) and have null passed into the logs

i know this is a bit of an obtuse example but i imagine there are other use cases for this functioanlity
Scott Sauyet
@CrossEye
Mar 16 2015 20:49
How about passing nAry (0, next) to the success case?
I'd have to double-check the implementation to make sure it handles 0, but if it doesn't, such a wrapper would be easy to write.
Jason Marmon
@jtmarmon
Mar 16 2015 20:51
ah yes - R.curry(R.nAry(2, next))(null) seems to do what i want. thanks!
2 because I want to be able to invoke it once with the correct data, then a second time to indicate completion
love this library btw. I evangelize it to all my js writing friends >.>
John-David Dalton
@jdalton
Mar 16 2015 20:52
instead of all that wrapping maybe partailing a null would do
Jason Marmon
@jtmarmon
Mar 16 2015 20:53
@jdalton - R.rPartial(next, anyNumber)(null) seems to always invoke next instantly
John-David Dalton
@jdalton
Mar 16 2015 20:54
the idea is to create the partialed function with null provided as the partialed first arg
Jason Marmon
@jtmarmon
Mar 16 2015 20:55
ah got it, but next takes 1 parameter so it'll always be invoked instantly
Scott Sauyet
@CrossEye
Mar 16 2015 20:55
What is the signature of next?
Jason Marmon
@jtmarmon
Mar 16 2015 20:57
it's whatever the invoker says it should be, but I believe it's generally called with 1 arg. delving into the code one sec..
Scott Sauyet
@CrossEye
Mar 16 2015 21:00
I'm a little unclear on the call-it-twice bit. I was thinking of promise.then (nAry (0, next)).catch (next)
Would that work for you?
Jason Marmon
@jtmarmon
Mar 16 2015 21:01
next has 1 parameter, but if I do promise.then(next) next will be invoked with whatever was returned by the promise, when I'd really like to just pass null. R.curry(R.nAry(2, next))(null) turns next into a 2 parameter function, so that first argument (the one I want to be passed back) is applied, and the second is ignored
oh i see
so R.nAry(0, func) turns it into a no-parameter accepting function
regardless of what it's invoked with?
Scott Sauyet
@CrossEye
Mar 16 2015 21:03
Right. It's a small wrapper that just calls your function with no parameters.
Jason Marmon
@jtmarmon
Mar 16 2015 21:04
ahh awesome. just what i wanted. thank you
Scott Sauyet
@CrossEye
Mar 16 2015 21:04
Np.
Jason Marmon
@jtmarmon
Mar 16 2015 21:05
on an unrelated note, after explaining the same n reasons why ramda is cool to my friends, i wrote a scrappy blog post which i'll probably rewrite soon. but though this would be a good place to share it
Scott Sauyet
@CrossEye
Mar 16 2015 21:09
Very nice! Thanks.
Walle Cyril
@GrosSacASac
Mar 16 2015 21:24
I dont understand why one would use R.always, can someone explain ?
Hardy Jones
@joneshf
Mar 16 2015 21:26
@jtmarmon Based on your post, I feel like you would enjoy some of the things lenses can do.
@GrosSacASac you can use always for a multitude of things
if you wanted to set a Functor to a default value, like make an array of 10's or something
R.map(R.always(10), xs)
Jason Marmon
@jtmarmon
Mar 16 2015 21:27
oh cool @joneshf. lenses do some things I was looking for the other day...it's definitely hard for a beginner to find stuff in the docs imo. maybe we can find a better way to traverse them? like crowdsourcing tags for each function or something
Hardy Jones
@joneshf
Mar 16 2015 21:28
but more than that, it can work with any Functor since thi is ramda
Jethro Larson
@jethrolarson
Mar 16 2015 21:28
Most commonly used when a function accepts another function and you just want to put a value there
R.ifElse(somePredicate, R.always('foo'), R.always('bar'));
Hardy Jones
@joneshf
Mar 16 2015 21:31
var const1 = R.map(R.always(1));
var size = R.pipe(const1, R.sum);

var xs = [1,2,3];
size(xs) //=> 3
var j = Maybe.Just(3);
size(j) //=> 1
var n = Maybe.Nothing();
size(n) //=> 0
I don't actually know if that works, but in theory it should
depends on how R.sum is implemented
and whether or not Maybe has a reduce probably
Hardy Jones
@joneshf
Mar 16 2015 21:38
also, it forms the Apply implementation for functions.
it's also half of the basis for a turing complete language
the other half being
var star = R.curry(function(f, g, x) {
  return f(x, g(x));
};
so, lots of reasons :)
Hardy Jones
@joneshf
Mar 16 2015 21:44
@jtmarmon yeah, it's tough to understand at first.
Raine Virta
@raine
Mar 16 2015 21:45
i would like to see "real world" examples of monads other than maybe, promise etc. in javascript
guys like reader, IO. to see if they're practical or not
Walle Cyril
@GrosSacASac
Mar 16 2015 21:55
can someone show me a real program made with Ramda because I have some difficulty understanding how to use it
Raine Virta
@raine
Mar 16 2015 22:22
GrosSacASac: whenever you want to turn data from one shape to another, you probably have a use case for ramda