These are chat archives for ramda/ramda

22nd
Jun 2015
Scott Sauyet
@CrossEye
Jun 22 2015 00:21
Site's loading for me.
mac10688
@mac10688
Jun 22 2015 02:19
I've been learning haskell so that I can use this library. It's taking me a long time though.
Scott Sauyet
@CrossEye
Jun 22 2015 11:53
I was hoping that using this library meant that you didn't have to learn Haskell... until you really wanted to. :smile:
Adam Nalisnick
@theadam
Jun 22 2015 12:21
@CrossEye @mac10688 That was my experience! I used ramda for a while, now I'm trying to learn Haskell.
Ludwig Magnusson
@TheLudd
Jun 22 2015 13:58
Is there no function in ramda that counts elements in a list by a callback function? Like filterbut it would only return the number of matches. It would have this signature
(a -> Boolean) -> [a] -> Number
I thought this was countBybut apparently not...
Joseph Abrahamson
@tel
Jun 22 2015 14:13
Ramda has transducers, right? You could assdmble an efficient form of this from tilter and length if so
Ludwig Magnusson
@TheLudd
Jun 22 2015 14:14
Implementation is not a problem. I just thought I remembered such a function existing.
Scott Sauyet
@CrossEye
Jun 22 2015 15:06
partition is somewhat close.
predicate -> list -> [matched, unmatched]
Not the counts, but obviously those would be easy to drive.
David Chambers
@davidchambers
Jun 22 2015 16:47
@TheLudd, what’s wrong with composing R.length and R.filter?
Ludwig Magnusson
@TheLudd
Jun 22 2015 16:47
Nothing is wrong, I just seemed to remember such a function existing
David Chambers
@davidchambers
Jun 22 2015 16:47
Ah, okay.
It doesn’t seem necessary to me to include a function which is so easily derived (and not commonly used).
I’ve observed an inverse relationship between the number of lines of code in Ramda pull requests and the number of lines of comments. It’s the two-line changes that sometimes keep us chatting for hours. :)
Joseph Abrahamson
@tel
Jun 22 2015 16:57
If you compose R.length and R.filter does it produce a one-pass algorithm? Is there a standard way of writing such a composition in Ramda?
I see the transducers bit but haven’t really digested what’s being offered yet
I’m a little confused about the signature of transduce, e.g.
(c -> c) -> (a, b -> a) -> (a -> [b] -> a)
the last half is a church-encoded left-biased stream, useful for building lazy one-pass algorithms. The (c -> c) bit I don’t understand, though.
Ludwig Magnusson
@TheLudd
Jun 22 2015 17:28
Just noticed that path can handle null input of the second argument, but prop cannot. Is this known/intentional/bad/something to care about?
David Chambers
@davidchambers
Jun 22 2015 18:21
I think they should be consistent.
Hardy Jones
@joneshf
Jun 22 2015 18:35
@tel very cool! I don't have es6 stuff setup to play with it though.
Joseph Abrahamson
@tel
Jun 22 2015 18:37
I’m planning on writing a simplified translation in a bit!
This was a good exercise, but the classes are unncessary on re-analysis
Joseph Abrahamson
@tel
Jun 22 2015 20:29
no ES6, and I think I avoided some bugs
still untested ; )
Jethro Larson
@jethrolarson
Jun 22 2015 21:48
I wondered what you meant by arrow there. This is it, right? https://en.wikipedia.org/wiki/Arrow_(computer_science)
Jethro Larson
@jethrolarson
Jun 22 2015 23:21
Should R.match return [] when no matches are found rather than null?
Scott Christopher
@scott-christopher
Jun 22 2015 23:23
It would probably make for a nicer API
Kevin Wallace
@kedashoe
Jun 22 2015 23:24
if I have a Just of a Just (eg Just(Just('hi'))), have I done something wrong? If that's ok, is there a notion of unwrapping Justs until you get to the value?
Jethro Larson
@jethrolarson
Jun 22 2015 23:25
You might have been able to chain to collapse it
Scott Christopher
@scott-christopher
Jun 22 2015 23:25
If you’re using a map to create the inner Just, you could instead use chain to flatten them.
Kevin Wallace
@kedashoe
Jun 22 2015 23:26
ok, makes sense
Jethro Larson
@jethrolarson
Jun 22 2015 23:26
Just(Just('hi')) is analogous to [['hi']]. It's conceivable to want it nested but probably not what you intend
Kevin Wallace
@kedashoe
Jun 22 2015 23:26
ok so i should be paying more attention to my types as i go along
Scott Christopher
@scott-christopher
Jun 22 2015 23:26
If you already have aJust(Just(x)), you can also call .chain(R.identity) to flatten them
Kevin Wallace
@kedashoe
Jun 22 2015 23:27
rather than moving my data through a bunch of functions and relying on some way to safely unwrap it all at the end?
Jethro Larson
@jethrolarson
Jun 22 2015 23:28
It can be easier to understand the code if you keep it as flattened as you can as you go
Kevin Wallace
@kedashoe
Jun 22 2015 23:31
ok, and just for my curiosity's sake, is there an standard way to unwrap arbitrarily nested Justs is functional programming?
and btw what I have is a list of Maybes and wanted to get the first that is not Nothing (or Nothing if they are all Nothing)
so I wrote S.head(R.dropWhile(R.is(S.Nothing), maybes))
is there a better way to do that?
Jethro Larson
@jethrolarson
Jun 22 2015 23:34
R.find(R.is(S.Nothing)) is a little smaller
I'm not familiar with sanctuary though
Kevin Wallace
@kedashoe
Jun 22 2015 23:36
me neither :)
ah i see there is S.find, which leaves me with S.find(R.complement(R.is(S.Nothing)), maybes)
Jethro Larson
@jethrolarson
Jun 22 2015 23:40
If R.match always returns an array then using list methods on results wont throw:
http://bit.ly/1H9UT8W
Sorry, I'm back on a previous topic :)
Kevin Wallace
@kedashoe
Jun 22 2015 23:42
np
you started on that before I jumped in so I can hardly complain :)
Hardy Jones
@joneshf
Jun 22 2015 23:55
@kedashoe you want xs.sequence(S.Maybe.of).map(R.head).
@tel nice! I'll check that out later tonight.
@kedashoe oh, sorry. I misread what you wrote, you don't want that.
Kevin Wallace
@kedashoe
Jun 22 2015 23:59
@joneshf i'm ok with calling .chain(R.identity) at the end as @scott-christopher mentioned above, but if you have other thoughts on it i would be curious to hear