These are chat archives for ramda/ramda

8th
Oct 2015
Hardy Jones
@joneshf
Oct 08 2015 01:24
@davidchambers it might help to make it point free.
compose(filter(p), filter(q)) === compose(filter(q), filter(p))
Jethro Larson
@jethrolarson
Oct 08 2015 01:26
Doesn't it makes sense? If you take all the people then get rid of the blondes then the brunettes or get right of the brunettes then blondes, either way you got a bunch of red heads.
David Chambers
@davidchambers
Oct 08 2015 01:26
That looks very much like:
compose(add(4), add(2)) === compose(add(2), add(4))
Hardy Jones
@joneshf
Oct 08 2015 01:27
Oh, I see @CrossEye wrote that above :)
I was thrown off by the escaped characters
Scott Sauyet
@CrossEye
Oct 08 2015 01:27
@crosseye tried to write that above...
David Chambers
@davidchambers
Oct 08 2015 01:28
@jethrolarson, it undoubtedly makes sense, I'm just looking for an intellectual-sounding name for the law. ;)
Scott Sauyet
@CrossEye
Oct 08 2015 01:29
@jethrolarson, and why this prejudice against the baldies? :smile:
Hardy Jones
@joneshf
Oct 08 2015 01:29
well it's the function composition that's commutative, not the filter.
David Chambers
@davidchambers
Oct 08 2015 01:30

Does

compose(add(4), add(2)) === compose(add(2), add(4))

demonstrate associativity or commutativity?

Hardy Jones
@joneshf
Oct 08 2015 01:30
or I guess more formally, filter is commutative under function composition
I'm pretty sure that's a free theorem though.
Scott Sauyet
@CrossEye
Oct 08 2015 01:30
demonstrates commutativity, but as @joneshf said, it's more about composition than about the filter itself
associativity has to do with how you group operations.
Scott Christopher
@scott-christopher
Oct 08 2015 01:31
associativity would be:
compose(filter(f), compose(filter(g), filter(h))) === compose(compose(filter(f), filter(g)), filter(h))
Hardy Jones
@joneshf
Oct 08 2015 01:31
meaning the proof is probably not bad...
Jethro Larson
@jethrolarson
Oct 08 2015 01:31
Filter Commutativity Law: filter is commutative under composition
David Chambers
@davidchambers
Oct 08 2015 01:32

But

compose(add(4), add(2)) === compose(add(2), add(4))

is my attempt to encode

(2 + 3) + 4 === 2 + (3 + 4)

which is about associativity.

Scott Christopher
@scott-christopher
Oct 08 2015 01:32
also:
compose(filter(f), filter(g)) === filter(both(f, g))
Hardy Jones
@joneshf
Oct 08 2015 01:33
you'd have to prove four cases: x satisfies p and x satisfies q, x satisfies p and x not satisfies q, x not satisfies p and x satisfies q, and x not satisfies p and x not satisfies q.
but the middle two cases are the same WLOG.
David Chambers
@davidchambers
Oct 08 2015 01:33
@scott-christopher, that's another one!
Jethro Larson
@jethrolarson
Oct 08 2015 01:33
That one is probably more useful, since it's less iterations
mirrors
compose(map(f), map(g)) == map(compose(f,g))
Hardy Jones
@joneshf
Oct 08 2015 01:34
@scott-christopher that's even better, since you can use the commutativity of both as a lemma in the filter commutativity proof!
compose(filter(p), filter(q)) === filter(both(p, q)) === filter(both(q, p)) === compose(filter(q), filter(p))
David Chambers
@davidchambers
Oct 08 2015 01:36

Filter Commutativity Law: filter is commutative under composition

I think we can all agree on this one. It doesn't make sense to talk about associativity, because we can't write both

(a `filter` b) `filter` c

and

a `filter` (b `filter` c)

It doesn't make sense to talk about commutativity (except under function composition) because we can't write both

a `filter` b

and

b `filter` a
Thank you for a stimulating conversation, folks. As always, I'm learning. :)
Hardy Jones
@joneshf
Oct 08 2015 01:38

why not:

compose(filter(p), compose(filter(q), filter(r))) === compose(compose(filter(p), filter(q)), filter(r))

?

which then reduces to unnesting the composes.
Jethro Larson
@jethrolarson
Oct 08 2015 01:39
TIL that creating a pure stream implementation is harder than it looks
Hardy Jones
@joneshf
Oct 08 2015 01:39
@jethrolarson oh?
Sounds interesting :)
David Chambers
@davidchambers
Oct 08 2015 01:39
@joneshf, I don't understand your question.
Jethro Larson
@jethrolarson
Oct 08 2015 01:39
I can gist my WIP if you want to see my failings
Hardy Jones
@joneshf
Oct 08 2015 01:40
@davidchambers to say that filter is associative under function composition.
though, I'm not sure if you even need to say that.
Scott Sauyet
@CrossEye
Oct 08 2015 01:49
@joneshf: I'm trying to decide the same thing. It's easy enough to find functions which don't commute under composition. But I can't think of ones that don't associate. I'm pretty sure that it's a simple property of composition.
Does this do it?
(f o (g o h))(x) = (f(\y -> g(h(y)))(x) = f(g(h(x)) = (f(g(\y -> h(y)))(x) = ((f o g) o h)(x) 
Scott Sauyet
@CrossEye
Oct 08 2015 01:55
So function composition is always associative, and filter has nothing to do with it.
Jethro Larson
@jethrolarson
Oct 08 2015 02:20
Oh, duh lol
Its not certainly commutative tho
Scott Sauyet
@CrossEye
Oct 08 2015 02:22
no, of course not
Jethro Larson
@jethrolarson
Oct 08 2015 02:23
Sometimes i get stuck in the abstract and forget the basics
Scott Sauyet
@CrossEye
Oct 08 2015 02:23
n => n + 1 and n => n * n don't commute (unless n = 0)
Jethro Larson
@jethrolarson
Oct 08 2015 02:25
I commute. Doing so now
Scott Sauyet
@CrossEye
Oct 08 2015 02:34
I go to bed. Doing so now. Good night.
Niloy Mondal
@niloy
Oct 08 2015 11:05
Any particular reason why R.__ uses 2 underscore instead of 1?
Scott Christopher
@scott-christopher
Oct 08 2015 11:09
Not 100% sure, but if I were to guess I'd say it was to prevent confusion with underscore/lodash.
Niloy Mondal
@niloy
Oct 08 2015 11:15
Kinda sucks that it requires typing one extra character since the underscore would already be in the R namespace
Raine Virta
@raine
Oct 08 2015 11:17
I kind of like how __ stands out more
Niloy Mondal
@niloy
Oct 08 2015 11:20
R.lt has the parameter list wrong, const lessThan10 = R.lt(10); lessThan10(9) // false :(
Raine Virta
@raine
Oct 08 2015 11:21
that has been a topic of discussion
currently you need to use the placeholder
Niloy Mondal
@niloy
Oct 08 2015 11:21
awww okay, consensus is keep it the current way?
Martin Algesten
@algesten
Oct 08 2015 11:22
ramda always curries left to right
R.bla(a,b,c,d)
is always curried a -> b -> c -> d
Niloy Mondal
@niloy
Oct 08 2015 11:22
yes sir, thats why I said the parameter list is wrong
I mean parameter order
Martin Algesten
@algesten
Oct 08 2015 11:24
it's that way to be entirely consistent when not using partial application.
R.div(10,2) is another one.
Niloy Mondal
@niloy
Oct 08 2015 11:24
ok, I get it
Raine Virta
@raine
Oct 08 2015 11:25
ramda/ramda#1363
ramda/ramda#388
Martin Algesten
@algesten
Oct 08 2015 11:29

i struggle making my model code functional. are there any good examples around of something simple, like the TODO-list that is used in lots of front end code. it needs to show me:

  1. how to model a state without mutation
  2. how to persist this state using an asynchronous back end
  3. how to draw this state in a view

especially 2 is where i get stuck.

Martin Algesten
@algesten
Oct 08 2015 11:31
thanks @raine
Raine Virta
@raine
Oct 08 2015 11:31
offers solutions to at least 1. and 3.
Martin Algesten
@algesten
Oct 08 2015 11:31
xD .... ok it's a start
Hardy Jones
@joneshf
Oct 08 2015 15:08
@jethrolarson hmm, since you're kind of stuck, maybe this is a good time to learn about the cofree comonad. Then your stream is Stream a = Cofree Identity a
Plus you get tons of free stuff.
Like, since Stream a is built on Cofree, you know it's a Functor, an Extend and a Comonad.
And since Identity a is a Monoid you also have that Stream a is an Apply, an Applicative, a Chain, and a Monad.
Eric Gjertsen
@ericgj
Oct 08 2015 15:48
@algesten , re your question "2. how to persist this state using an asynchronous back end", the repo that raine linked to has examples of this using a variety of techniques. Take a look at the zip-codes example, zip-codes-future, file-uploader, and autocomplete. https://github.com/paldepind/functional-frontend-architecture/tree/master/examples
Martin Algesten
@algesten
Oct 08 2015 15:50
yes. i realised that it would be there. it's a great resource. i need to plan some time in to go through the examples in detail. much appreciated!
Raine Virta
@raine
Oct 08 2015 16:04
yep, it's good stuff. after sitting down to understand the whole architecture I created https://www.habbo.com/mosaic/ as a small experiment
David Chambers
@davidchambers
Oct 08 2015 16:07
I like it, @raine!
Martin Algesten
@algesten
Oct 08 2015 16:07
trippy :)
Eric Gjertsen
@ericgj
Oct 08 2015 16:18
also the Elm Architecture document is a good reference, most of those functional-frontend-arch examples translate its concept of Effects: https://github.com/evancz/elm-architecture-tutorial/ (making heavy use of ramda-fantasy futures I should add...)
Jethro Larson
@jethrolarson
Oct 08 2015 17:26
@joneshf I'm open to that. You have a resource that'll teach it without getting too academic?
Jethro Larson
@jethrolarson
Oct 08 2015 18:42
I read a couple articles, I feel dumber than before I started