These are chat archives for ramda/ramda

3rd
May 2015
Hardy Jones
@joneshf
May 03 2015 00:36
i'm really liking all the activity in rf lately
Michael Hurley
@buzzdecafe
May 03 2015 13:06

I need something like R.all, but with the indexed passed to the predicate along with the element. Is there such a thing ?

What is the problem you are trying to solve?

Hardy Jones
@joneshf
May 03 2015 13:56
@buzzdecafe it looks like verifying that the array goes from 0 to n-1, but that might be a simplification.
Michael Hurley
@buzzdecafe
May 03 2015 14:14
hmm, so all(pred, take(n-1, list))?
the only reasonable use cases i've seen for wanting the index passed to all or any is for comparing adjacent list elements. addressing that was the motivation for aperture
Michael Hurley
@buzzdecafe
May 03 2015 14:19
looking this over again:
R.reduceIndexed((acc, elem, idx, lst) => { return acc && elem === idx }, true);
so we want to verify that each element is the same as its index.
hmm
Michael Hurley
@buzzdecafe
May 03 2015 14:33
i guess you could short-circuit the reduction using a transducer, e.g.:
R.reduceIndexed((acc, elem, idx, lst) => { return acc ? elem === idx : {'@@transducers/reduced': true, value: false}; }, true)([0,1,2,3,4]);
but that is less than lovely
Hardy Jones
@joneshf
May 03 2015 14:40
make it slightly more lovely with a function?
Michael Hurley
@buzzdecafe
May 03 2015 14:40
you mean like reduced(value)?
Hardy Jones
@joneshf
May 03 2015 14:41
var done = R.assoc('value', R.__, {'@@transducers/reduced': true});
R.reduceIndexed((acc, elem, idx, lst) => { return acc ? elem === idx : done(false) }, true)([0,1,2,3,4]);
yeah
Michael Hurley
@buzzdecafe
May 03 2015 14:42
maybe even: return elem === idx || reduced(false)
Hardy Jones
@joneshf
May 03 2015 14:42
sure
Michael Hurley
@buzzdecafe
May 03 2015 14:43
that's a little sweeter
Hardy Jones
@joneshf
May 03 2015 14:44
might it be worthwhile to have those helpers available?
Michael Hurley
@buzzdecafe
May 03 2015 14:44
@CrossEye has been looking for a way to wrap these "iterator" functions s.t. when wrapped they get passed the index
Hardy Jones
@joneshf
May 03 2015 14:45
I know i couldn't figure out how to exit a transducer early
not necessarily the index stuff, but the transducer stuff
Michael Hurley
@buzzdecafe
May 03 2015 14:46
see ramda/ramda#484

might it be worthwhile to have those helpers available?

probably

This message was deleted
arg
Michael Hurley
@buzzdecafe
May 03 2015 14:53
seems like such a special use case.
but probably handy for a case like this
Hardy Jones
@joneshf
May 03 2015 14:54
maybe it doesn't belong then?
i guess it's more generally for the specific implementation
might make a good standalone library then
Michael Hurley
@buzzdecafe
May 03 2015 14:55
like i would love to have a function otherwise :: Function f -> [R.T, f]
just so i can right cond expressions like:
cond(
    [expr1, cq1],
    [expr2, cq2],
   //...
   otherwise(f)
)
but the only use for such a function would be to make cond read nicely
and i never felt like that's a good enough reason to include it
Michael Hurley
@buzzdecafe
May 03 2015 15:04
right, we don't have that sugar (yet) as function or constructor. I don't see the point of constructing a Reduced object
when a plain old object does the trick
Scott Sauyet
@CrossEye
May 03 2015 15:28
I've been talking about addIndexed for a long time, and although we have something of an implementation in an old thread, I'm trying it from scratch to see if I can come up with something useful. It doesn't sound hard...
Simon Friis Vindum
@paldepind
May 03 2015 16:42
@buzzdecafe I think cond would read better if you special cased on the placeholder like this:
var fn = R.cond(
  [R.eq(0),   R.always('water freezes at 0°C')],
  [R.eq(100), R.always('water boils at 100°C')],
  [R.__,       function(temp) { return 'nothing special happens at ' + temp + '°C'; }]
);
But I also still think having R.case would be super neat:
var fn = R.case(
  [0,    R.always('water freezes at 0°C')],
  [100,  R.always('water boils at 100°C')],
  [R.__, function(temp) { return 'nothing special happens at ' + temp + '°C'; }]
);
Hardy Jones
@joneshf
May 03 2015 17:16
can't case be implemented in terms of cond?
This message was deleted
beh
something like case = R.map((x) => [R.eq(x[0]), x[1]])
Simon Friis Vindum
@paldepind
May 03 2015 17:29
@joneshf Yes. That is exactly what I had in mind as well. It is just a slight layer of sugar over cond (but for what I expect is a very common case)
Michael Hurley
@buzzdecafe
May 03 2015 17:50

[R., function(temp) { return 'nothing special happens at ' + temp + '°C'; }]

idk about that. that is a totally different meaning than everywhere else we use __

although it is more prolog/erlang like
the fall-through case for cond is [R.T, defaultFn]
and R.T is less typing than R.__ :smiling_imp: