These are chat archives for ramda/ramda

6th
Apr 2016
Julien Goux
@jgoux
Apr 06 2016 14:49
What's the benefits of using R.curry vs manually currying function using ES6 arrow function ?
Keith Alexander
@kwijibo
Apr 06 2016 14:49
@jgoux R.curried functions can be called in different ways
Julien Goux
@jgoux
Apr 06 2016 14:49
R.curry((a, b, c) => {}) vs a => b => c => {}
David Chambers
@davidchambers
Apr 06 2016 14:49
Functions curried Ramda-style are more versatile.
Keith Alexander
@kwijibo
Apr 06 2016 14:50
eg f(a,b,c)
or f(a,b)(c)
David Chambers
@davidchambers
Apr 06 2016 14:50
f(a)(b)
f(a, b)
f(_, b)(a)
Julien Goux
@jgoux
Apr 06 2016 14:50
Is there any downside of using R.curry if I want to use sanctuary ?
David Chambers
@davidchambers
Apr 06 2016 14:50
I don't think so. What is your concern?
Julien Goux
@jgoux
Apr 06 2016 14:53
I was just curious, I know that sanctuary enforces more rules than ramda no ?
so I wanted to know about the currying ^^
let's go for R.curry \o/
David Chambers
@davidchambers
Apr 06 2016 14:54
Sanctuary is stricter, that's true.
There are a few Sanctuary functions which require a curried function.
Julien Goux
@jgoux
Apr 06 2016 14:54
I'm using Future btw, it's so much better than Promise
David Chambers
@davidchambers
Apr 06 2016 14:54
But functions curried Ramda-style are at once curried and uncurried. ;)
Julien Goux
@jgoux
Apr 06 2016 14:55
@Avaq did a great work with fluture ! :clap:
David Chambers
@davidchambers
Apr 06 2016 14:55
That's great to hear! Promise is flawed.
Julien Goux
@jgoux
Apr 06 2016 14:56
I tried the reader monad but I found it comes with more downsides than benefits when you want to use multiple monads
Keith Alexander
@kwijibo
Apr 06 2016 14:56
@jgoux fwiw, personally I almost always prefer multi-step arrow functions
Julien Goux
@jgoux
Apr 06 2016 14:56
@kwijibo My issue with multi-step arrow function is that I can't use R.__ to easily adapt my partial applications
Keith Alexander
@kwijibo
Apr 06 2016 14:56
unless exposing an API where you can't predict what the most useful way of applying arguments will be
that's true
I mostly find I know how the arguments will be applied (within my own code), and find it clearer to have one way to do it
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 15:10
@davidchambers Nice, I didn't know about this one: f(_, b)(a)
Denis Stoyanov
@xgrommx
Apr 06 2016 15:12
@Risto-Stevcev this is placeholder)
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 15:13
Oh, nvm, lol
I must be getting tired or something, didn't realize its just R.__
Julien Goux
@jgoux
Apr 06 2016 15:13
^^
Does anyone use monad transformers in JS ?
I'd like to use Maybe and Either, but as I also use Future, the code becomes quickly noisy x)
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 15:15
It's basically the same functionality as my LazyEither "Future" lib, though I have to admit I like it quite a bit more than mine
it's more flexible
Julien Goux
@jgoux
Apr 06 2016 15:18
yes I use fluture and I really like it
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 15:23
yeah he did a good job on it
Julien Goux
@jgoux
Apr 06 2016 15:25
Also, how would you represent Haskell let...in or expression...where notation in JS ? Nested functions ?
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 15:26
es6 has let, you wouldn't need the in part because the let is bound for the remainder of that block
there's no equivalent to where notation
though you could use const actually for where
because const is variable hoisted
Julien Goux
@jgoux
Apr 06 2016 15:28
I like the where notation the most :(
I assume I can do it using var ?
Neither const nor let are hoisted as far as I know
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 15:31
const is hoisted
Brad Compton (he/him)
@Bradcomp
Apr 06 2016 15:34
@Risto-Stevcev I don't think const is hoisted in a way that would allow for where. The definition is hoisted but assignment is not.
http://goo.gl/QNal52
Julien Goux
@jgoux
Apr 06 2016 15:36
@Bradcomp yes
Stefano Vozza
@svozza
Apr 06 2016 15:37
const was hoisted in older versions of the V8 but not anymore i think.
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 15:38
@Bradcomp Yeah, you're right
Brad Compton (he/him)
@Bradcomp
Apr 06 2016 15:38
I don't think variable assignments were ever hoisted in javascript
only variable definitions
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 15:38
That's right
@jgoux I guess you would have to resort to closures or making a small function wrapper
You could probably use generators to achieve what you want
Julien Goux
@jgoux
Apr 06 2016 15:42
generators ?
interesting
simplest example : http://goo.gl/epSE1f
how would you put the steps after the program ?
we can't use a function if we want to use R.curry
James Forbes
@JAForbes
Apr 06 2016 15:50

What's the benefits of using R.curry vs manually currying function using ES6 arrow function ?

Just wanted to jump in and say there are benfits to sticking with arrow functions. Debugging, less indirection, type inference. (probably) performance.

I'd love a ramda build that was just arrow functions.

As infeasible as that may be
Julien Goux
@jgoux
Apr 06 2016 15:51
I think I'd like arrow function by default, and a function to transform it to use the R.__ somehow
so in 90% of the cases you can use the arrow function approach, and when you need flexibility you use a function to transform it
for the expression...where I don't see how to do it without using var
James Forbes
@JAForbes
Apr 06 2016 15:54
I'm really not a fan of placeholders, but I guess, the arrow function approach breaks things like flip
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 15:54
@jgoux You would yield them, but in all honesty considering how JS binds this, you're probably better off using arrows
James Forbes
@JAForbes
Apr 06 2016 15:55
but you could have a flip that worked
const flip = (fn) => (a) => (b) => fn(b)(a)
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 15:56
@ram-bot ((a, b) => console.log(a + b))(2, 5)
ram-bot
@ram-bot
Apr 06 2016 15:56
ReferenceError: console is not defined
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 15:56
@ram-bot ((a, b) => a * b)(2, 5)
ram-bot
@ram-bot
Apr 06 2016 15:56
10
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 15:56
where would just be calling the function with (2, 5)
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 16:13
@jgoux Or you could do something like this:
const def = fn => ({
  where: obj => (function(obj) {
    Object.keys(obj).forEach(key => this[key] = obj[key])
    fn()
  })(obj)
})

def(() => {
  console.log(a + b)
}).where({ a: 2, b: 5 })
Lewis
@6ewis
Apr 06 2016 16:19
do we have something along those lines R.isFalse(value)
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 16:21
@6ewis R.when
Lewis
@6ewis
Apr 06 2016 16:23
@Risto-Stevcev what I was looking for was isNil
Risto Stevcev
@Risto-Stevcev
Apr 06 2016 16:24
gotcha
Lewis
@6ewis
Apr 06 2016 17:29
what am I doing wrong here?http://goo.gl/KBeRlo
Denys Mikhalenko
@prontiol
Apr 06 2016 17:33
updateEntityType expects the only param to be a string, while map will pass whole object
also, for your purposes R.evolve seems to fit better
Lewis
@6ewis
Apr 06 2016 17:35
@prontiol it is a string. did i copy the wrong version of the link
hmm
Denys Mikhalenko
@prontiol
Apr 06 2016 17:35
ah okay
take a look at my version:
http://goo.gl/6u21qi
Lewis
@6ewis
Apr 06 2016 17:38
@prontiol right way to go but id like to know what im doing wrong
@prontiol thanks
Denys Mikhalenko
@prontiol
Apr 06 2016 17:38
okay, gimme a sec to find out
you're missing the third parameter in R.assoc call
Brad Compton (he/him)
@Bradcomp
Apr 06 2016 17:42

@6ewis Here:

let updateEntityType = (entity) => R.assoc('entity_type', serializeEntityType(entity));

R.assoc takes 3 parameters: the field, the value, and the object. the updateEntityType function is only passing it 2 values.
It should look like this:

let updateEntityType = (entity) => R.assoc('entity_type', serializeEntityType(entity), entity);

Once I did that the code worked.

Denys Mikhalenko
@prontiol
Apr 06 2016 17:43
that's right
Lewis
@6ewis
Apr 06 2016 17:44
@Bradcomp I thought it was going to curry by default
Brad Compton (he/him)
@Bradcomp
Apr 06 2016 17:46
@6ewis R.assoc will curry by default, but you are using it inside the updateEntityType function. That function takes a single parameter, entity, and returns the curried function.
@6ewis You can see in your results that you get an array of functions, these are the curried R.assocs that you are returning from updateEntityType
Lewis
@6ewis
Apr 06 2016 17:51
@Bradcomp I see, thanks
Scott Sauyet
@CrossEye
Apr 06 2016 18:19
@Bradcomp: "I don't think variable assignments were ever hoisted in javascript only variable definitions". Arguably, function declarations are a form of hoisted assignment.
Brad Compton (he/him)
@Bradcomp
Apr 06 2016 18:21
@CrossEye You got me there. That doesn't really help in the context of mimicking where syntax though
Scott Sauyet
@CrossEye
Apr 06 2016 18:24
Not at all. Just an interesting point, as I try to read several hours worth of Gitter while dodging traffic (on foot), Maybe bit a good idea. :smile:
Maybe NOT a good idea.
Brad Compton (he/him)
@Bradcomp
Apr 06 2016 18:55
:)
Lewis
@6ewis
Apr 06 2016 19:53
is there a shortcute for R.evolve to chanve multiple keys at once with the same function?
key values
Denys Mikhalenko
@prontiol
Apr 06 2016 19:56
it works this way by default
like 30
I intend to have multiple properties where i wanna transform 'null' to null
Also did i use R.curry appropriately or theres a better way
Denys Mikhalenko
@prontiol
Apr 06 2016 19:57
you don't need R.curry there
Lewis
@6ewis
Apr 06 2016 19:58
ok so it just invoke the function and pass the parameter right away
Walle Cyril
@GrosSacASac
Apr 06 2016 19:58
is there a more simple way to express
    let scopeName,
        variableName;
    for (scopeName of Object.keys(commentsData)){
        if (!D.vr[scopeName]) {
            D.vr[scopeName] = {};
        }
        for (variableName of Object.keys(commentsData[scopeName])){
            D.vr[scopeName][variableName] = commentsData[scopeName][variableName];
        }
    }
Denys Mikhalenko
@prontiol
Apr 06 2016 19:59
@6ewis you have to provide a transformation function for each key in the first parameter you pass to R.evolve
Lewis
@6ewis
Apr 06 2016 20:02
@prontiol you didnt change anything
thats exactly what i add without the curry
Walle Cyril
@GrosSacASac
Apr 06 2016 20:02
commentsData look like this
    let commentsData = { //intial
    comment1: {
        text: "I am the first to comment, well written! Bravo!",
        date: "In the year 2016"
    },
    comment2: {
        text: "I really appreciate your work",
        date: "yesterday" 
    }
};
Denys Mikhalenko
@prontiol
Apr 06 2016 20:03
i changed serializeNullValue implementation
Lewis
@6ewis
Apr 06 2016 20:04
@GrosSacASac : you could use R.map and R.evolve?
@prontiol for what purpose? you just removed the return key
it's shorter
Denys Mikhalenko
@prontiol
Apr 06 2016 20:05
I removed R.curry, you don't need it
Lewis
@6ewis
Apr 06 2016 20:05
@prontiol i understood that part
Denys Mikhalenko
@prontiol
Apr 06 2016 20:05
so what's the problem then?
Lewis
@6ewis
Apr 06 2016 20:05
@prontiol that wasn't my main question
thanks though
Brad Compton (he/him)
@Bradcomp
Apr 06 2016 20:24
@6ewis Are you wanting to run serializeNullValue over all the keys?
Brad Compton (he/him)
@Bradcomp
Apr 06 2016 20:29
Map can work on an object as well as an array
Scott Sauyet
@CrossEye
Apr 06 2016 21:07
@GrosSacASac: on my mobile so I can't test anything now, but does this do anything more than D.vr = R.merge(D.vr, commentsData)?
Brad Compton (he/him)
@Bradcomp
Apr 06 2016 21:29
@GrosSacASac or potentially R.mergeWith if there are already comments in D.vr