These are chat archives for ramda/ramda

12th
Jun 2015
Robert Balfre
@rob-balfre
Jun 12 2015 00:32
Can sortBy order be reversed?
Scott Christopher
@scott-christopher
Jun 12 2015 00:34
There’s nothing built in to sortBy or other similar function that I’m aware of, but you could either negate the property that you are sorting, or just reverse the resulting list.
Robert Balfre
@rob-balfre
Jun 12 2015 00:40
@scott-christopher ah thanks, as I suspected. Also why use pipe instead of compose, are there advantages I’m not aware of?
Scott Christopher
@scott-christopher
Jun 12 2015 00:41
Nope, just preference of reading left-to-right, or right-to-left
Robert Balfre
@rob-balfre
Jun 12 2015 00:42
Cool, good to know.
Robert Balfre
@rob-balfre
Jun 12 2015 02:19
can prop or something replace this function? function getLikes(a) { return a.likes.data; }
Scott Christopher
@scott-christopher
Jun 12 2015 02:20
Try R.path([“likes”, “data”])
Robert Balfre
@rob-balfre
Jun 12 2015 02:21
:D
Scott Christopher
@scott-christopher
Jun 12 2015 02:21
You could also compose some lenses, but path will do the trick if you only have to read.
Scott Sauyet
@CrossEye
Jun 12 2015 02:22
But you might look at lenses in any case -- just because they're cool! :bulb:
Robert Balfre
@rob-balfre
Jun 12 2015 02:23
Sure, got a good link for read up on them? I’m new to this stuff :)
Scott Sauyet
@CrossEye
Jun 12 2015 02:27
Most of the Haskell lens tutorials are a bit overwhelming, to my mind. The gist that inspired our original solution is simple and clear. One second while I find the link.
Very short. Very sweet: https://gist.github.com/andyhd/1795108
Scott Christopher
@scott-christopher
Jun 12 2015 02:29
Perhaps the examples in the Ramda docs might give you some intuition too:
http://ramdajs.com/docs/#lens
http://ramdajs.com/docs/#lensProp
http://ramdajs.com/docs/#pipeL
I would personally like to expand some other lenses, but that would perhaps be better suited for a ramda-contrib
Scott Sauyet
@CrossEye
Jun 12 2015 02:31
Nice. Looking at those, I think we should update the examples for lensProp so the objects also contain some unrelated property.
Robert Balfre
@rob-balfre
Jun 12 2015 02:32
Great, thanks. Will take a look.
Scott Christopher
@scott-christopher
Jun 12 2015 02:35
If you want some deeper knowledge of lenses, I’d recommend https://www.youtube.com/watch?v=cefnmjtAolY&hd=1&t=1m14s
But as @CrossEye mentioned, the detail can be a bit overwhelming.
Hardy Jones
@joneshf
Jun 12 2015 03:47
wait pipeL?
David Chambers
@davidchambers
Jun 12 2015 04:08
I’m excited about plaid/sanctuary#50 and would like to know how others feel about this level of run-time type checking. @paldepind and I would like Ramda to do something similar. ;)
Scott Christopher
@scott-christopher
Jun 12 2015 04:27
pipeL being the pipe version of composeL
or if you were questioning the L suffix, pipeL and composeL exist for composing lenses
Hardy Jones
@joneshf
Jun 12 2015 05:16
So there's pipe, pipeP, pipeL, and their compose counterparts?
i smell an abstraction
Scott Christopher
@scott-christopher
Jun 12 2015 05:17
I think we could probably get rid of the *P and *L in favour of dispatching via pipe and compose
Hardy Jones
@joneshf
Jun 12 2015 05:17
smells like a semigroup
Scott Christopher
@scott-christopher
Jun 12 2015 05:17
or that :)
Hardy Jones
@joneshf
Jun 12 2015 05:17
though, I guess since they're functions it's more category-ish
or semigroupoid I guess would be more proper
Scott Christopher
@scott-christopher
Jun 12 2015 05:21
How would something like concat handle the different left/right associativity behaviour of pipe and compose?
… scratch that. That should just be the difference between a left and right fold over the semigroup?
Hardy Jones
@joneshf
Jun 12 2015 05:25
well since it's a semigroup it should be associative
oh
do you mean commutativity?
yeah, it wouldn't
Scott Christopher
@scott-christopher
Jun 12 2015 05:28
yeah sorry, in terms of implementing the various pipe and compose using concat, if I understand correctly, pipe should just be a left fold and compose a right fold over the semigroups?
Hardy Jones
@joneshf
Jun 12 2015 05:29
oh
right
unfortunately, i'm not sure if this is actually feasible
isn't modifying the prototype of built in things like this looked down upon in js?
Function.prototype i mean
Scott Christopher
@scott-christopher
Jun 12 2015 05:31
We shouldn’t have to, if we can just dispatch inside concat
which it is already doing for Arrays
Hardy Jones
@joneshf
Jun 12 2015 05:31
dispatch on what?
oh, like an instanceof check?
Scott Christopher
@scott-christopher
Jun 12 2015 05:32
There’s alredy an _isThenable internal function that can handle the Promise
Hardy Jones
@joneshf
Jun 12 2015 05:38
Hmm, these are kind of special cases.
plain function, promise, lens
If some new case comes up, it'd end up needing to modify the code as well, right?
Scott Christopher
@scott-christopher
Jun 12 2015 05:39
It’s only the natives, where we don’t want to add concat methods to their prototypes
Hardy Jones
@joneshf
Jun 12 2015 05:40
hmm, maybe thats not so bad then
Scott Christopher
@scott-christopher
Jun 12 2015 05:40
which is just Promise, Function and Array that I can think of at the moment
Hardy Jones
@joneshf
Jun 12 2015 05:51
This seems relevant: http://sugarjs.com/native
Scott Christopher
@scott-christopher
Jun 12 2015 05:52
// concat
module.exports = _curry2(function(set1, set2) {
  if (_isArray(set2)) {
    return _concat(set1, set2);
  } else if (_hasMethod('concat', set1)) {
    return set1.concat(set2);
  } else if (_isThenable(set2)) {
    return _composeP(set2, set1);
  } else if (typeof set2 == 'function') {
    return _compose(set2, set1);
  } else {
    throw new TypeError("can't concat " + typeof set1);
  }
});
var addToString = concat(R.add, R.toString);
addToString(4, 5); // “9”
David Chambers
@davidchambers
Jun 12 2015 05:53
That’s an interesting idea.
Scott Christopher
@scott-christopher
Jun 12 2015 06:16
var fold1L = R.converge(R.reduce, R.always(concat), R.head, R.tail);
var fold1R = R.converge(R.reduceRight, R.always(R.flip(concat)), R.head, R.tail);

var pipe = R.unapply(fold1L);
var compose = R.unapply(fold1R);
Raine Virta
@raine
Jun 12 2015 07:46
has anyone come up with a nice pattern for building a typical options object where some fields appear conditionally?
one way is to run the object through pickBy not nil or similar
and evaluate unwanted fields to null/undefined
although to be honest I'm not sure why passing undefined would ever be a problem
Raine Virta
@raine
Jun 12 2015 07:52
perhaps if a library uses a property if the opts hasOwnProperty(prop)
Scott Christopher
@scott-christopher
Jun 12 2015 08:00
@raine: Not sure I follow. Can you provide a concrete example?
Raine Virta
@raine
Jun 12 2015 08:05
sure, a crude example:
proxy.web(req, res, {
  agent: opts.useAgent ? getMyAgent() : undefined,
  target: 'http://www.google.com',
  proxyTimeout: 1000
});
if proxy.web was (poorly?) implemented so that it used agent if it existed in the object, that would not work, right?
you'd have to use more ceremonial and sort of less declarative:
var proxyOpts = {
  target: 'http://www.google.com',
  proxyTimeout: 1000
};
if (opts.useAgent) proxyOpts.agent = getMyAgent();
proxy.web(req, res, proxyOpts);
Scott Christopher
@scott-christopher
Jun 12 2015 08:34
I'm on my phone, so it's a little difficult to test (and if I understand correctly)
Would something like the following work:
R.converge(R.pick, R.keys, R.identity)
That should remove any key pairs with undefined values.
Raine Virta
@raine
Jun 12 2015 08:39
true, pick has that property
Scott Christopher
@scott-christopher
Jun 12 2015 08:51
If however you want a function that takes an object of functions against keys and your opts, returning the final "cleansed" object, then I'll probably need to wait until I'm in front of a computer :D
Raine Virta
@raine
Jun 12 2015 09:25
this could be a temporary solution until we have the @aka and docs support https://github.com/ramda/ramda/wiki/Functions-AKA
future proofed for the impending release of 0.15
Tobias Pflug
@gilligan
Jun 12 2015 13:28
can anyone suggest a nice command line parsing solution ? commander.js is driving me nuts
Michael Hurley
@buzzdecafe
Jun 12 2015 14:51
@gilligan can't recommend one, but you sure have options
https://github.com/joyent/node/wiki/modules#parsers-commandline
Tobias Pflug
@gilligan
Jun 12 2015 16:02
@buzzdecafe yeah there sure are plenty. I looked at some and they all seemed rather "meh". Guess i'll just google some more
Vasiliy Yorkin
@vyorkin
Jun 12 2015 16:07
hi everyone! i’ve got some newbie questions (%
can I use ramdajs with es6 collections?
e.g. how can I apply a filter to Map? is there any function that I can use for this?
Michael Hurley
@buzzdecafe
Jun 12 2015 16:16
hi @vyorkin Map is not super-well integrated yet. but it's on the horizon: ramda/ramda#1055
at present, since maps are iterators you could transduce with 'em.
using reduce or transduce or into
Vasiliy Yorkin
@vyorkin
Jun 12 2015 16:21
thanks!
Asaf
@asaf-romano
Jun 12 2015 17:12
@raine wow, thanks!!!
Jethro Larson
@jethrolarson
Jun 12 2015 17:18
Watching lens talk. Can't tell if trolling...It's like he's intentionally trying to be confusing.
Hardy Jones
@joneshf
Jun 12 2015 17:51
He's surely not trolling.
but that's not the easiest talk if you've never dealt with lenses, algebras, functors, or haskell in general
That's very much a theory and implementation talk
Jethro Larson
@jethrolarson
Jun 12 2015 17:52
yeah, I was being facetious
Hardy Jones
@joneshf
Jun 12 2015 17:52
which is pretty great as far as talks go. I'm still learning stuff from it
Jethro Larson
@jethrolarson
Jun 12 2015 17:54
I guess a lot of these topics are hard to write talks for. You need prerequisite knowledge to understand a bunch of it.
Hardy Jones
@joneshf
Jun 12 2015 17:54
spj did that talk after only looking at lens after a few weeks, so it's from the perspective of someone learning it recently, rather than from someone building the whole thing
but the thing to realize about both of these are that they're describing one specific kind of lens
Jethro Larson
@jethrolarson
Jun 12 2015 17:55
I've used lenses a couple times but I've yet to feel the coolness of them
Hardy Jones
@joneshf
Jun 12 2015 17:56
they both start by talking about naïve/traditional/costate-comonad-coalgebra lenses then move on to van Laarhoven lenses.
yeah, that too, you do need some background
as far as the coolness, I think spj's talk really expresses why it's something that was spurred in haskellland
in js/python/ruby/java/etc you don't really need them, since updating down a chain of data isn't hard there.
whereas in haskell, it's atrocious.
Jethro Larson
@jethrolarson
Jun 12 2015 17:58
hm
When I played with it composeL didn't exist so maybe it's cooler now
Hardy Jones
@joneshf
Jun 12 2015 17:59
watch the first 5 minutes of spj's talk to see what i'm talking about haskell being absolutely awful for nested updates.
Jethro Larson
@jethrolarson
Jun 12 2015 18:00
will do
Hardy Jones
@joneshf
Jun 12 2015 18:07
Personally, I think the coolness of lenses comes from using van Laarhoven lenses rather than the cococo-lens. With that, we don't even need composeL, since van Laarhoven lenses are just functions. So composing two lenses together is exactly the same as composing any other functions together, i.e. compose.
So, i mean, ramda already supports van Laarhoven lenses just by the virtue of having compose.
Jethro Larson
@jethrolarson
Jun 12 2015 18:53
It's cool how humble SPJ is despite his expertise
Contrast Rich Hickey ;)
Jethro Larson
@jethrolarson
Jun 12 2015 19:06
I was noticing that R.scan doesn't transduce. Should that be added?
Michael Hurley
@buzzdecafe
Jun 12 2015 19:07
probably yes
btw, i'm a fan of rich hickey. and spj too, although i haven't seen him talk as much.
Jethro Larson
@jethrolarson
Jun 12 2015 19:08
I am too, it's just a tease