These are chat archives for ramda/ramda

13th
Mar 2015
David Chambers
@davidchambers
Mar 13 2015 01:02
@joneshf, that's a very nice solution!
John-David Dalton
@jdalton
Mar 13 2015 04:06
second example (the last one) doesn't return the right result.
Martin Algesten
@algesten
Mar 13 2015 05:57
isVideo = do ->
    lookup = R.reduce ((p, c) -> R.assoc c, true, p), {}, videoIds
    R.compose R.has(R.__, lookup), R.prop('id')
R.filter isVideo, items
Martin Algesten
@algesten
Mar 13 2015 06:14
hey @jdalton do you consider coffeescript especially bad given your. uhm. history with its creator? :)
Ludwig Magnusson
@TheLudd
Mar 13 2015 07:24
@joneshf That did actually work. I had looked at call previously but didn't thin it would do the trick. Turns out it did. Thanks
Raine Virta
@raine
Mar 13 2015 07:31
joneshf: why chain instead of map?
Hardy Jones
@joneshf
Mar 13 2015 07:41
@jdalton ah, right, moved the wrong things out.
var filterById = R.pipe(R.propEq('id'), R.flip(R.filter)(items));
var out = R.chain(filterById, videoIds);
point free is hard in js
@raine map doesn't talk about choices to be made based on what it's mapping over
@raine chain can though
or at least, it should'nt be able to
if you map over something, you should get back a thing of the same shape.
if you chain over something, you're not restricted by this.
Hardy Jones
@joneshf
Mar 13 2015 07:48
if you were to map then filter, you would expect to get exactly as many elements as the outer array you're mapping over.
those elements would also be arrays, though
when you chain then filter, you say nothing about the number of elements you get back out.
but you do say that it will be one less level of arrays than the map would've given
you can call it by its other names if that helps you to intuit wht happens: flatMap or concatMap. But the takeaway is that chain is the monadic bind function.
Hardy Jones
@joneshf
Mar 13 2015 07:54
and if you think about it in terms of using the current value to make a decision about what to do with the next value, then the monadic stuff shows up.
@raine does that make any sense?
Raine Virta
@raine
Mar 13 2015 07:56
hardly, i'm afraid
if you map over something, you should get back a thing of the same shape
same shape as in?
Hardy Jones
@joneshf
Mar 13 2015 08:15
heh, sorry
Raine Virta
@raine
Mar 13 2015 08:15
in haskell you would use fmap?
Hardy Jones
@joneshf
Mar 13 2015 08:15
I was speaking more generally
if you map an array with three elements, you should get back an array with three elements
if you map an empty array, you should get back an empty array.
and so on
it extends to other types though (where I was being more general)
if you map a Nothing, you get back a Nothing
map a Left, get back a Left
etc
so if you map videoIds you would expect to get an array with the same number of elements as videoIds.
judging by what @wildermuthn posted, I assumed that wasn't what was wanted
Raine Virta
@raine
Mar 13 2015 08:21
but you wouldn't be able to break that rule anyway, in javascript at least, unless we are not considering undefined as a value
but i think i see that distinction now
Hardy Jones
@joneshf
Mar 13 2015 15:09
I'm not sure I understand what you mean
you can break that law in most languages, as it's not something easily expressed in most statically typed languages, and dynamically typed, fuggitaboutit
Array.prototype.map = function() {
  return [];
};
Left.prototype.map = function() {
  return Right(this.value);
};
or something
Hardy Jones
@joneshf
Mar 13 2015 15:16
of course that last one isn't actually possible in a language with good types, but the point is there. It's usually possile to break that law
John-David Dalton
@jdalton
Mar 13 2015 16:12
@algesten lol, not a fan but hey there's https://github.com/eventualbuddha/decaffeinate
David Chambers
@davidchambers
Mar 13 2015 16:29
I assume that was tongue-in-cheek, @algesten, but what one thinks of a person shouldn't affect one's opinion of his or her software.
Ludwig Magnusson
@TheLudd
Mar 13 2015 17:17
Opinions on CoffeeScript are very polarized. I like it and would probably prefer to write code in it. But I understand why people have a hard time with it. And if functions grow large it can be difficult to comprehend. But to me that is mostly a reason to write those single line functons =)
John-David Dalton
@jdalton
Mar 13 2015 17:54
Naw, I'm not a robot. What I think of a person totally affects how I view their software. I see them as the reps of their code.
Danny Fritz
@dannyfritz
Mar 13 2015 18:21
I think there might be a conflation between an idea and a product being done here. Or something like that.
Ideas should be considered on their own, but a product has a lifetime being directed by an opinionated agent.
David Chambers
@davidchambers
Mar 13 2015 19:57
Yes, that's a valid distinction.
John-David Dalton
@jdalton
Mar 13 2015 20:45
some deep stuff right here : P