These are chat archives for ramda/ramda

24th
Feb 2015
Nate Wildermuth
@wildermuthn
Feb 24 2015 00:18
Everytime I compose a function, I feel like Ramda probably has a better answer than what I put together. For instance:
var fnSwitch = function(fnList) {
  return R.mapObjIndexed((val, key) => fnList[key](val));
};
This message was deleted
Nate Wildermuth
@wildermuthn
Feb 24 2015 00:24
So this particular function, fnSwitch, feels like it probably could be done differently with an existing Ramda function.
I pasted in a link to my gist, but it's huge.
Jethro Larson
@jethrolarson
Feb 24 2015 04:09
Not really more understandable but you could drop the inner function with some magic:
var R.fnSwitch = (fnList) =>
  R.mapObjIndexed(R.flip(R.useWith(
      R.call
    , R.propOf(fnList)
    , R.I
  )));
};
Jethro Larson
@jethrolarson
Feb 24 2015 04:39
Okay, I thought about it some more and here's it is with even more magic:
var R.fnSwitch = R.compose(
    R.mapObjIndexed
  , R.compose(
      R.partial(R.useWith, R.flip(R.call), I)
    , R.propOf
  )
);
Jethro Larson
@jethrolarson
Feb 24 2015 04:48
But even I can hardly figure out what I wrote, so maybe the original function is better than the tacit version.
Jethro Larson
@jethrolarson
Feb 24 2015 05:06
BTW, I've been thinking it'd be good to have some more advanced examples somewhere. Either in the github or on the docs site. The two blog articles are great but I think more is necessary for people that aren't used to curry at 5/5 spicy.
Nate Wildermuth
@wildermuthn
Feb 24 2015 05:07
There was a REPL linked to earlier in this room.. but I don't see it right away in the docs
Jethro Larson
@jethrolarson
Feb 24 2015 05:08
Oh yeah, that's a good place for examples. I forgot about that.
Nate Wildermuth
@wildermuthn
Feb 24 2015 05:08
Yeah, I did too. But it's a great tool, I think.
David Chambers
@davidchambers
Feb 24 2015 05:10
I've been thinking of creating a repository for Project Euler solutions implemented with Ramda functions. That would provide some more advanced examples, @jethrolarson.
Nate Wildermuth
@wildermuthn
Feb 24 2015 05:11
That's a great idea.
Jethro Larson
@jethrolarson
Feb 24 2015 05:12
Yeah, if you're looking at the docs and wondering what R.lens is for the jsdoc example can only go so far without getting huge.
Nate Wildermuth
@wildermuthn
Feb 24 2015 05:16
I was looking at lens today. What's the use case for that?
David Chambers
@davidchambers
Feb 24 2015 05:18
I haven't used it yet, so I'm not sure. ;)
Jethro Larson
@jethrolarson
Feb 24 2015 05:28
Is the R.tap function only useful if you want to have side effects?
David Chambers
@davidchambers
Feb 24 2015 05:33
I think so. It's handy for logging a value in the middle of a pipe: R.pipe(f, g, R.tap(console.log), h, i, j).
Hardy Jones
@joneshf
Feb 24 2015 05:45
@CrossEye that sort of dispatch is okay, It's the jquery-esque dispatch that's a problem
$.map([1, 2, [3]], function(x) {return x;})
[1, 2, 3]
Jethro Larson
@jethrolarson
Feb 24 2015 06:32
@davidchambers That's what I thought, probably one of the functions that shouldn't pass code review in usage.
Ludwig Magnusson
@TheLudd
Feb 24 2015 07:59

@CrossEye Isn't the map overload really unnecessary? I mean, Array is after all a functor isn't it? Which means that map could just be

function (f, functor) { 
  return functor.map(f)
}

This would work for arrays and for fantasy-land stuff.

David Chambers
@davidchambers
Feb 24 2015 08:11
^^ This assumes that Array.prototype.map is available, which isn't the case in ES3.
Ludwig Magnusson
@TheLudd
Feb 24 2015 08:15
So ramda is ES3 compatible?
David Chambers
@davidchambers
Feb 24 2015 08:27
Yes.
Ludwig Magnusson
@TheLudd
Feb 24 2015 08:30
I really had no idea. This isn't mentioned in the documentation or contributing guidelines.
David Chambers
@davidchambers
Feb 24 2015 08:38
That wouldn't be the only thing. There are still quite a few things for us to document. :)
Jethro Larson
@jethrolarson
Feb 24 2015 19:37
I did the first project euler problem for fun: http://jsbin.com/fiwuroraye/1/edit?js,console
Nate Wildermuth
@wildermuthn
Feb 24 2015 19:44
I like this part:
var multOf = R.compose(R.not, R.flip(R.modulo))
  , multOf3or5 = R.filter(R.or(multOf(3), multOf(5)))
  , sumMultiplesTacit = R.compose(R.sum, multOf3or5)
Jethro Larson
@jethrolarson
Feb 24 2015 20:01
Yeah, I like that solution the best. If our lists were lazy that one would still be one iter
Might be another solution using unfold or a generator worth trying
Jethro Larson
@jethrolarson
Feb 24 2015 20:43
generators are broken on jsbin with 6to5 so I guess that'll have to be another time
Robin Lambertz
@roblabla
Feb 24 2015 20:48
:O
Raine Virta
@raine
Feb 24 2015 23:01
btw it's bit confusing in the ramda repl how it says # Output but console.log doesn't go there
it's more like return value instead of "output"
David Chambers
@davidchambers
Feb 24 2015 23:03
I agree.