These are chat archives for ramda/ramda

27th
Apr 2016
James Forbes
@JAForbes
Apr 27 2016 03:44
Great article @davidchambers :clap:
David Langford
@That-David-Guy
Apr 27 2016 05:28
Is there a more concise way to write this?:
@ram-bot
``````const ids = [1, 2, 3]
const data = [1, 2, 3, 4]
const rejectIds =
(values, toRemove) => R.reject(R.contains(R.__, toRemove), values)

rejectIds(data, ids) // => [4]``````
Apr 27 2016 05:51
@ram-bot
``R.difference([1,2,3,4], [1,2,3])``
ram-bot
@ram-bot
Apr 27 2016 05:51
``[ 4 ]``
David Langford
@That-David-Guy
Apr 27 2016 05:53
That is very nice. Thanks!
Jigar Gosar
@jigargosar
Apr 27 2016 07:25
This message was deleted
This message was deleted
``````const createProp = R.curry((name, value) => ({[name]: value}))
const createXProp = createProp("x")
const createYProp = createProp("y")

const vector = (x, y) => R.merge(createXProp(x), createYProp(y))``````
Need help with writing in point free style
how can I write vector function in PFS
or the func rejectIds above
I generally get into these cases and can’t figure a way out
this is a trivial example, on purpose. so that I can get some answer that will help me derive generalized solution
Ivan Demchenko
@raqystyle
Apr 27 2016 07:29
``const vector = R.converge(R.merge, [createProp("x"), createProp("y")])``
Jigar Gosar
@jigargosar
Apr 27 2016 07:30
yes that works, thanks.
I will try to use it to define createProp method.
Ivan Demchenko
@raqystyle
Apr 27 2016 07:30
even more, you don't need `createProp` fn
``const vector = converge(merge, [objOf("x"), objOf("y")])``
:)
sorry, german keyboard...
Jigar Gosar
@jigargosar
Apr 27 2016 07:31
ooh wow, thanks.
was not aware of objOf.
Ivan Demchenko
@raqystyle
Apr 27 2016 07:31
;)
Jigar Gosar
@jigargosar
Apr 27 2016 07:31
I need a way to use every singe method in the library. only then I shal remember
but you and the community in general is awesome !!!
Stefano Vozza
@svozza
Apr 27 2016 08:17
anyone know why is the activity bar filled with information about phantom comments on really old issues? is it a bug on github/gitter?
Risto Stevcev
@Risto-Stevcev
Apr 27 2016 08:31
looks like gitter crapped out
the unread functionality craps out a lot for me too
Jigar Gosar
@jigargosar
Apr 27 2016 08:35
@raqystyle hey following doesn’t work :(
```
``````const vector = R.converge(R.merge, [R.objOf("x"), R.objOf("y")])
console.log(vector(5, 1));``````
output is {x:5, y:5}
Ivan Demchenko
@raqystyle
Apr 27 2016 08:37
@jigargosar Oh, sorry, instead of `converge`, use `useWith`. It's just the other way to pass arguments.
Jigar Gosar
@jigargosar
Apr 27 2016 08:38
intresting
converge, passes all the arguments, right?
and usewith one at a time?
Ivan Demchenko
@raqystyle
Apr 27 2016 08:38
@ram-bot
``R.useWith(R.merge, [R.objOf("x"), R.objOf("y")])(3, 7)``
ram-bot
@ram-bot
Apr 27 2016 08:38
``{ x: 3, y: 7 }``
Jigar Gosar
@jigargosar
Apr 27 2016 08:39
thanks
Ivan Demchenko
@raqystyle
Apr 27 2016 08:42

converge will pass arguments to each function in the array of functions. So,

``R.converge(add3, [multiply, add, subtract])(1, 2)``

is just like

``add3( multiply(1,2), add(1,2), subtract(1,2) ) => add3(2, 3, -1)``

useWith is a bit different

``R.useWith(pow, [R.dec, R.inc])(3, 6) => pow( R.dec(3), R.inc(6) ) => pow(2, 7)``
@ram-bot
``useWith(merge, [objOf("x"), objOf("y")])(3, 7)``
ram-bot
@ram-bot
Apr 27 2016 08:42
``{ x: 3, y: 7 }``
Ivan Demchenko
@raqystyle
Apr 27 2016 08:43
Cool, rambot can be used without `R.` prefix
Jigar Gosar
@jigargosar
Apr 27 2016 09:07
thanks a lot
Jigar Gosar
@jigargosar
Apr 27 2016 10:24
Unable to convert this to point-free style
``const applyFnToVector = (fn, angle, length)=> R.multiply(R.call(fn, angle), length)``
```
``R.multiply(R.call(R.__, R.__), R.__)``
donesn’t work
Jigar Gosar
@jigargosar
Apr 27 2016 10:39
useWith won’t work since call needs two arguments :worried:
Aldwin Vlasblom
@Avaq
Apr 27 2016 10:45

Let's start by removing `R.call`, because that just adds obscurity:

``const applyFnToVector = (fn, angle, length) => multiply(fn(angle), length)``

Now let's identify what we're really doing:

``const applyFnToVector = (f, g, a, b) => f(g(a), b)``

Which is equal to:

``const applyFnToVector = (f, g, a, b) => f(g(a), identity(b))``

That looks familliar!

``useWith(pow, [dec, inc])(3, 6) => pow( dec(3), inc(6) ) => pow(2, 7)``

So we could:

``const applyFnToVector = fn => useWith(multiply, [fn, identity])``

Now, to get `fn` into position:

``````const applyFnToVector = compose(useWith(multiply), prepend(__, [identity]))

...That works, but is it really better than the lambda I started with? I'm not sure. Personally I'm of the opinion that as soon as you find yourself struggling to make it pointfree, you should probably not be doing it.

Jigar Gosar
@jigargosar
Apr 27 2016 11:15
Wow, wow. This is super helpful
How do you think like this. That is what I want to learn.
The reason, I am trying to convert every part of my code into its functional equivalent, and in a point free style, is because I am new. I wan’t to learn. I want to know the boundaries. I want to push it.
@Avaq thanks a tonnes, and please point me in some direction, so that I can learn about this decomposition process, it is so beautiful and elegant.
Jigar Gosar
@jigargosar
Apr 27 2016 11:23
that is some good use of prepend that I learned today. This is such a rewarding experience.
I am very new to PFS, and most people recommend me not to go too far with it, because it makes code unredable. Many times there is a tradeoff between redability and PFS.
Aldwin Vlasblom
@Avaq
Apr 27 2016 11:27
Yeah, that whole process I walked through to get to a pointfree implementation would have to be walked in reverse by someone trying to understand the code. It's pretty harsh on your colleagues. ;)
Gleb Bahmutov
@bahmutov
Apr 27 2016 11:28
@jigargosar this could sound like a shameless plug but I have a bunch of FP examples in Ramda, for example
Jigar Gosar
@jigargosar
Apr 27 2016 11:30
I understand that, but I have a hypothesis: The reason we don’t get clear and readable code with PFS is because, either we haven’t discovered/named a pattern or a higher level of abstraction, or we haven’t split up our pointfree code into smaller chunks. Any thoughts? @Avaq @CrossEye @raqystyle @bahmutov
Gleb Bahmutov
@bahmutov
Apr 27 2016 11:31
I think splitting is the key
Aldwin Vlasblom
@Avaq
Apr 27 2016 11:32
@jigargosar If you're interested in pointfree programming from an academic/impractical point of view (as I am too ;)) I would recommend looking into combinators. It's pointfree pushed to the very boundaries (to the point that everything is composed pointfree of only two base functions). A cool introduction is this programming with nothing talk.
Jigar Gosar
@jigargosar
Apr 27 2016 11:44
@bahmutov you are probably right, given the long history, chances of some easy and clear abstraction not being discovered is very low ;) Although, if PFS and FP had been previliged enough to gain wider mind share, like imperative style, c/c++/java/.net, early on, who know where the world of software computing would be today. I can’t even imagine. This can be named as one of the biggest "lost opportunit cost" in history of mankind :thought_balloon:
;)
Jigar Gosar
@jigargosar
Apr 27 2016 11:53

@Avaq I am intrested in everything that, might appear impractical but, will expand my mind towards new way of thinking. This is my dearest and most practical mind hack ;) And at times, the most practical thing is to have fun. Won’t you agree?

And thanks a lot for the link, it looks promissing, and what an inspiring title “NOTHING”, love it :) I have been hearing a lot about combinators since I have enterd the world of FP. And now after your recommendation, its time to take a dive, or test the waters at least. I might ask for further help, thanks. You have been very kind.

@bahmutov I found your articles helpful, couple of new tricks I learned, partialRight ;) of course I will have to spend more time digging into them. Thanks. More specifically, I was intrested in the way @Avaq decomposed the problem, and composed it back to form a solution, that was super cool. What say you? What is the theory behing it, what are the principles? is there a method to this madness? Since you love to write, and if you do regarding this thinking style in particular, feel free to let me know. I would love to learn.
Gleb Bahmutov
@bahmutov
Apr 27 2016 12:00
if I write something like that will definitely post it (twitter or RSS is the best way to get the updates for that). Meanwhile maybe look at functional programming books for JS? Look at Allonge and Functional javaScript https://glebbahmutov.com/blog/javascript-books/
Ivan Demchenko
@raqystyle
Apr 27 2016 12:05

@jigargosar Well, I'm also new to FP. Actually, from my point of view, FP and, as a consequense, PFS is not crazy at all. In fact, it is the simpliest thing I've ever seen. I'd recommend to read about Lambda Calculus and proceed to Combinators as @Avaq mentioned. Try to implement some functions and structures and you'll see the root. That's what I did.

The only problem with FP I can see is that people just don't know that certain function exists or how a function works. That was my problem, at least. But sooner of later, you'll cover documentation and things go smoother.

I'd also recommend to take a look at haskell.

Jigar Gosar
@jigargosar
Apr 27 2016 12:08
@raqystyle great advice, I should pickup haskell again. Learning a popular purely funcitonal lang, like haskell, will give me great insights. And the active community will have tones of more resources. How could I miss that. Sometimes all we need is a simple reminder. Perfect. Great many thanks.
Ivan Demchenko
@raqystyle
Apr 27 2016 12:10
@jigargosar good luck! I'm not the one to give advice. But I know your pain ;)
Jigar Gosar
@jigargosar
Apr 27 2016 12:10
@bahmutov wow, that is what I needed, thanks. You have contributed a great deal. I think I should start building a page with all these links. So, that me and others can find it easily.
@bahmutov and yes, Allonge is what I have started reading since yesterday. Then got distracted by racket, and now haskell. Too many great choices. :)
@bahmutov your blog is great in general, lot of good stuff. I am subscribing. :)
Gleb Bahmutov
@bahmutov
Apr 27 2016 12:57
thanks! Allonge has really changed the way I look at JS programming, since I am originally from C++
Julien Goux
@jgoux
Apr 27 2016 13:19
@bahmutov Great posts !
I'd also add that PFS is much easier in a typed language because you just have to connect the dots between the types (at least for me)
Gleb Bahmutov
@bahmutov
Apr 27 2016 13:23
thank you! I agree with you that it is easier, but I always fight extra "type fluff" to hack things I want :)
Julien Goux
@jgoux
Apr 27 2016 13:24
And I strongly agree about the right splitting of computations. As soon as I can clearly name a computation with something meaningful => extract
Gleb Bahmutov
@bahmutov
Apr 27 2016 13:24
that's the spirit - it should be meaningful to read I think
GÁBOR Áron Zsolt
@ashnur
Apr 27 2016 15:18
is there a complement for mergeWith, an intersect for objects?
David Chambers
@davidchambers
Apr 27 2016 15:23
@raqystyle, @jigargosar, earlier you discussed this expression:
``R.useWith(R.merge, [R.objOf("x"), R.objOf("y")])(3, 7)``
I thought I'd mention that there's a function which would avoid `useWith`.
@ram-bot
``R.zipObj(['x', 'y'])([3, 7])``
ram-bot
@ram-bot
Apr 27 2016 15:25
``{ x: 3, y: 7 }``
David Chambers
@davidchambers
Apr 27 2016 15:26
It's not quite the same, though, since the values must be provided as a list.
@ashnur, could you provide example inputs and outputs for the function you have in mind?
Apr 27 2016 15:37
This message was deleted
@ram-bot
``R.unapply(R.zipObj(['x', 'y']))(3, 7)``
ram-bot
@ram-bot
Apr 27 2016 15:37
``{ x: 3, y: 7 }``
Ivan Demchenko
@raqystyle
Apr 27 2016 15:57
thanks!
`zipObj` is really nice, especially when combining reactive streams.
Tim Navrotskyy
@dypsilon
Apr 27 2016 16:44
Hi, could someone point me to an explanation of why promises are impure?
David Chambers
@davidchambers
Apr 27 2016 17:19
@dypsilon, the reason is that creating a promise triggers the side effects immediately. So `readFile :: Path -> Promise String` is impure because `readFile('/Users/dc/.npmrc')` will trigger the file system operation immediately.
Gleb Bahmutov
@bahmutov
Apr 27 2016 17:21
@dypsilon I can offer my post https://glebbahmutov.com/blog/difference-between-promise-and-task/ - the simple act of creating a Promise starts the computation immediately
Lewis
@6ewis
Apr 27 2016 17:59
Hi is ramda 100% immutable
does it always return new objects?
David Chambers
@davidchambers
Apr 27 2016 18:00
Yes.
Lewis
@6ewis
Apr 27 2016 18:01
@davidchambers weird I can't figure out why my react/redux component is not re-rendering (it only happens if there's been a mutation in the reducers)
6ewis @6ewis is thinking out loud
Apr 27 2016 18:56
@6ewis The only thing I can think of would be if you're using `R.forEach` instead of `R.map` for some reason?
Lewis
@6ewis
Apr 27 2016 19:58
@Bradcomp im using R.dissoc assoc ?
Apr 27 2016 19:58
Huh, that should be returning a new object then.
Lewis
@6ewis
Apr 27 2016 21:01
@Bradcomp the issue was somewhere else. thanks guys
what's the best way to get the difference between two objects?
Aldwin Vlasblom
@Avaq
Apr 27 2016 21:08
@6ewis There's a section about object diffing in the Cookbook.
Lewis
@6ewis
Apr 27 2016 21:08
@Avaq where is diff coming from the code example you linked me to
Lewis
@6ewis
Apr 27 2016 21:17
@Avaq @Bradcomp also the suggested solution for object diffing is overly complicated. am i the only one who think so?
Tim Navrotskyy
@dypsilon
Apr 27 2016 22:29
@davidchambers thanks that makes sense.
@bahmutov thank you, that's exactly what I was looking for.
functional community is surprisingly large in js
Scott Sauyet
@CrossEye
Apr 27 2016 23:38
@davidchambers: Nice blog post!
David Chambers
@davidchambers
Apr 27 2016 23:38
Thanks, Scott! Nice avatar update!
Scott Sauyet
@CrossEye
Apr 27 2016 23:38