These are chat archives for ramda/ramda

14th
Apr 2015
Eugene Lerman
@airbugg
Apr 14 2015 08:42
hey guys, I was wondering if anyone can help with a little utility function i'm trying to refactor. @CrossEye helped me yesterday writing this function:
var byProperty = R.curry(function(name, value, list) { return R.filter(R.propEq(name, value), list); });
I was trying to refactor it to be a little more general; accepting a function reference instead if R.propEq so that i'll be able to pass a custom comparator (for example, R.eq or R.lt), but I can't seem to manage to nail the correct functional syntax down.
Raine Virta
@raine
Apr 14 2015 08:57
airbuggy: comparator for a property's value? something like propEqLt?
Eugene Lerman
@airbugg
Apr 14 2015 08:59
@raine exactly! Ideally, i'd like to generalise byProperty to be able to filter by a custom logic wrapped by a boolean function (as is the case with propEq).
Raine Virta
@raine
Apr 14 2015 09:32
Raine Virta
@raine
Apr 14 2015 09:40
added another example
Eugene Lerman
@airbugg
Apr 14 2015 09:45
@raine this is fantastic! exactly what I was trying to achieve. Thank you so much :)
Michael Hurley
@buzzdecafe
Apr 14 2015 10:38
can't you just do this with where?
filter(where({age: gte(__, 13)))
Raine Virta
@raine
Apr 14 2015 10:47
right. missed that one. i was thinking ramda should have something like it and checked docs for prop*
Eugene Lerman
@airbugg
Apr 14 2015 11:59
@buzzdecafe can I pass an argument instead of age, like this: var filterBy = function (prop) { return filter(where({prop: gte(__, 13)})); }
because I can't seem to be able to pass prop as a variable to R.where
Eugene Lerman
@airbugg
Apr 14 2015 12:17
also, I'd like to be able to pass a collection through multiple filters, dynamically. is there an elegant way to do that, for example storing the filters in an array and passing the collection to each of these filters one by one, eventually returning the filtered collection?
Alistair Dutton
@kelveden
Apr 14 2015 13:57
I'm looking for a neat way of creating a "not-ted" version of a function similar to lodash's negate function - e.g. var isOdd = _.negate(isEven). The best I can come up with in Ramda is var isOdd = _.pipe(isEven, R.not). Does anyone have a neater approach? (I could just use lodash of course...)
lluft
@lluft
Apr 14 2015 14:04
@kelveden I think you are looking for http://ramdajs.com/docs/#complement
Alistair Dutton
@kelveden
Apr 14 2015 14:30
That's it! Thanks @lluft. Why didn't I think of that? This is functional programming land we're in after all.
Scott Sauyet
@CrossEye
Apr 14 2015 15:30
@airbuggy: You can apply multiple filters with reduce:
var friendly = R.complement(R.propEq('disposition', 'surly'));
var preteen = R.pipe(R.prop('age'), R.lt(R.__, 13));
var brunette = R.propEq('hair', 'brown');
R.reduce(R.flip(R.filter), kids, [friendly, preteen, brunette])
Simon Friis Vindum
@paldepind
Apr 14 2015 18:05
This is not Ramda related (sorry). But if anyone here have experience with FRP I'd really like to hear what you think about Flyd. Especially with regards to the tutorial. Does is make sense?
Scott Sauyet
@CrossEye
Apr 14 2015 18:54
@paldepind: Just looked over the docs, and haven't tried it yet. Looks very exciting!
Some minor caveats: You seem to be missing filter, which I would expect to find available.
You also call your function reduce, when it looks closer to scanl or some such. We really can't reduce unbounded collections.
Simon Friis Vindum
@paldepind
Apr 14 2015 18:56
There is a filter as a module. I've kept it out of the core because Flyd works with transducers and Ramda filter can thus be used which I prefer.
Scott Sauyet
@CrossEye
Apr 14 2015 18:57
And finally, is there a reason for mapStream/reduceStream instead of just map/reduce ? If you made these properties of the stream function, you could even have them dispatched from Ramda! :smile:
Ah, I hadn't looked at the modules, or at how your transducers worked yet. Makes sense.
Looks very appealing!
Simon Friis Vindum
@paldepind
Apr 14 2015 18:59
@CrossEye, that is a very good point. I should probably call it scan.
The names mapStream and reduceStream are only used in the tutorial. map is actually a property of streams but that is only to achieve fantasy-land compatibility. I prefer to avoid methods.
I've thought about integrating with the Ramda dispatch mechanism. But the difference is small flyd.map vs R.map and I think is obscures the fact that you're working with streams.
Thank you :)
Scott Sauyet
@CrossEye
Apr 14 2015 19:06
Yes, there is no reason to use R.map; I was just noticing that you could if you had these as properties of streams. I noticed that you had a number of functions in there for compatibility with FantasyLand. What Algebraic Data Types do your streams implement? Obviously Functor and Apply. Are they full Monads too?
Simon Friis Vindum
@paldepind
Apr 14 2015 19:09
They're currently Applicatives. Maybe they could be monads but to be honest I don't fully understand monads. I know Elms signals aren't monads though.
Scott Sauyet
@CrossEye
Apr 14 2015 19:35
@paldepind: One other issue: the multiple clicks example is a 404.
Simon Friis Vindum
@paldepind
Apr 14 2015 19:42
Oops. Thanks for catching that. It is in the example dictionary.
Scott Sauyet
@CrossEye
Apr 14 2015 19:43
I guess the transducer one is as well. I just hadn't tried that one. The secret combo one is using fat arrows so doesn't work in some browsers, BTW.
Simon Friis Vindum
@paldepind
Apr 14 2015 19:44
I think I've forgot to update the gh-pages branch.
Simon Friis Vindum
@paldepind
Apr 14 2015 19:51
Yes. I had!
Scott Sauyet
@CrossEye
Apr 14 2015 19:55
They look good. Should the transducers example have a page or just the repo?