These are chat archives for ramda/ramda

11th
May 2017
Riderman de Sousa Barbosa
@Ridermansb
May 11 2017 00:08

There are any way to pass only once the params..

const myFunc(PARAM)  => { ... }
const regex = /^robot\/([a-zA-Z0-9]{2}:.+)/mi;
const isOk = R.test(regex);
R.when(isOk, myFunc)('PASS_HERE');

So.. isOk will execute with PASS_HERE
and myFunc will execute with PASS_HERE too.

Sorry, I'm learning about FP :)
Riderman de Sousa Barbosa
@Ridermansb
May 11 2017 00:17
I end up doing this...
 R.pipe(
  R.when(isOk , myFunc),
)('PASS_HERE')
Riderman de Sousa Barbosa
@Ridermansb
May 11 2017 01:57

How apply curry right ?

const cb = () => {};
const publish = (resp, cb) => { ... } 
const publishThis = R.curry(publish, cb); // Wrong, curry is left to right, I want right to left

I need to do this...
publishThis({ok: true}) will call publish({ok: true}, cb)

Riderman de Sousa Barbosa
@Ridermansb
May 11 2017 02:57
.. partialRight :+1:
const resolveCond = pipe(
  condToRes,
  when(HOW TO CHECK condToRes IS NOT NIL, pipe(format, publish))
);
Lucas Schejtman
@lucasschejtman
May 11 2017 02:59
R.flip could have been an option as well ?
Riderman de Sousa Barbosa
@Ridermansb
May 11 2017 04:40
Nice thanks
Lorenzo Giuliani
@aliem
May 11 2017 10:01
Hello, I have a question, is there a nicer way to do pattern matching like this? https://gist.github.com/aliem/44d3b6d754a1e02ed05145fb8d14be3e (it's not the cleanest implementation, and I hate dates)
Kurt Milam
@kurtmilam
May 11 2017 13:29
@aliem I'd probably put all of that into a cond and move the R.pathEq part out in front of the cond, so it's only called once.
Lorenzo Giuliani
@aliem
May 11 2017 13:35
thanks! I don't know how did I miss cond
Kurt Milam
@kurtmilam
May 11 2017 13:41
@aliem In a case like this, where you seem to be checking the same property for multiple different values, I'd probably reach for the trusty switch statement. We don't really have good pattern-matching in javascript or even Ramda, and I'm learning that it doesn't always make sense to try to shoehorn every problem into a Ramda-style solution.
Risto Novik
@riston
May 11 2017 13:45
Hello, how to rewrite the "compare" function more like ramda style: (a, b) => { const getID = path(["item", "id"]); return getID(a) === getID(b); }
Michael Rosata
@mrosata
May 11 2017 13:54
@aliem something like this as a start maybe https://goo.gl/07LcLd
Lorenzo Giuliani
@aliem
May 11 2017 13:58
@mrosata thanks, that's a good degree of abstraction for the first part of the conversion. that's very helpful
Michael Rosata
@mrosata
May 11 2017 14:03
@aliem no problem :smile:
@riston try
const comparePaths = (path) => R.compose(R.pathEq(path), R.path(path))
comparePaths(['item', 'id'])
it would work like:
comparePaths(['item', 'id'])(user1)(user2)
Zephilim
@Zephilim
May 11 2017 14:06
Hi, so how do you apply a transforming function to elements of an array for those elements that satisfy a predicate? The problem with filter is that it creates a new list, including only those elements that satisfy the predicate, but really I just want my original list, with only some of the elements to be transformed.
Michael Rosata
@mrosata
May 11 2017 14:08
@Zephilim You would use map and R.when most likely
R.map(R.when(predicate, transform))
Zephilim
@Zephilim
May 11 2017 14:10
Ah ok. Do the updates occur to the original collection, or does it return a new collection
Risto Novik
@riston
May 11 2017 14:13
@mrosata thank you that's, interesting approach :thumbsup:
Michael Rosata
@mrosata
May 11 2017 14:14
@riston happy to be able to help
Zephilim
@Zephilim
May 11 2017 14:43

so if I had an array:

let arr = ["-a", "b", "-c", "d"];

and I wanted to transform this array to strip off the dashes for those elements which do have dashes and return the array ["a", "b", "c", "d"], how would I do this with R.map and R.when?

I thought it should be something like:

R.map((m) => { R.when(w => w.startsWith("-")), m.slice(1) }

but this isn't quite right

Michael Rosata
@mrosata
May 11 2017 14:48
R.map(R.when(R.test(/^-/), R.replace(/^-/, '')))
I think that should do
Zephilim
@Zephilim
May 11 2017 14:51
I'm still getting confused with R. I keep thinking that you need to provide the function, eg (x)=> do something, where as that is what is replaced with an R- function. Is hat correct?
Michael Rosata
@mrosata
May 11 2017 14:53
Well you can put in a function, in fact R.when(R.test(/^-/), R.replace(/^-/, '')) is a function, equiv to writing (str) => R.test(/^-/, str) ? R.replace(/^-/, '', str) : str
Have you already learned about and become comfortable with curried functions?
Zephilim
@Zephilim
May 11 2017 14:54
yeah, I'm ok with curry
I'll get used to it after some practice though. It's weird not to see a variable, ie the 'str' in your example when expressed as an R expression
Michael Rosata
@mrosata
May 11 2017 15:08
@Zephilim Yea, it's likely something that will resolve with practice. You are 100% correct about needing to pass a function to R.map and that R.when(....) is that function. At first using R.*** is a bit confusing while you learn the utils and their arity (how many arguments they expect). When we have const summy = (a, b) => a + bthen we know "that is a function, it expects 2 arguments". We also know summy(1, 3) is the value returned after applying the function summy over 1 and 3. Eventually you'll look at expressions such as R.when(R.propEq('id', 10)) and quickly know "that is a function, it expects 2 more argument", likewise the inside R.propEq('id', 10) is "a function that expects 1 argument". The docs and the REPL both help a lot
Zephilim
@Zephilim
May 11 2017 15:10
Ok thanks, that helps a lot. I struggle with that weird mathematical notation in the documentation, but it's a work in progress
The documentation needs documentation in itself!
Michael Rosata
@mrosata
May 11 2017 15:12
No problem. Check this out for help with the notations in the docs https://github.com/ramda/ramda/wiki/Type-Signatures
Zephilim
@Zephilim
May 11 2017 15:13
Ok that looks useful, I haven't seen that before, cheers
Michael Rosata
@mrosata
May 11 2017 15:13
Don't feel compelled to read that entire thing, but try to chip away at it here or there. It's useful even beyond the scope of the Ramda library.
Michael Rosata
@mrosata
May 11 2017 15:19
@Zephilim last thing too. In the docs, there is a button "Expand parameters" in every single function. Most people probably notice it quickly. Myself, I didn't realize that was there for at least 4 or 5 months. Until you learn the "Hilney Milner"-esq notation that documents the functions better, you could just expand the parameters and there is param that you'll probably find more comfortable for now
Zephilim
@Zephilim
May 11 2017 15:20
excellent, thanks
Galileo Sanchez
@galileopy
May 11 2017 16:33
does groupWith assume transitivity?
it seems it doesn't pass (prev, current) to the comparator function, but rather (firstOfGroup, current)
Riderman de Sousa Barbosa
@Ridermansb
May 11 2017 21:43

Hi, I saw a lot of examples using Maybe.of, where I can find more information about it?
I need to parse a Json, but sometimes is invalid JSON, so I just need to return false. I think maybe is the solution

Example here

Julien Bonnin
@JulienBonnin-ABTasty
May 11 2017 22:08

Hello :) Just wanted to share some love for Ramda, I've been slowly refactoring my modules in FP using Ramda for a big project I am working on , and it allowed me to detect a lot of weird logic in my code and divide my code in such a way the my unit tests coverage is far better. I did a Ramda presentation at my company and people seemed to consider it for their projects.

I have a small practical question however :) I struggle to understand the role of transducers, in the example from the documentation, I have the same result wether I use a transducer or not :

https://goo.gl/VHxqA5

Riderman de Sousa Barbosa
@Ridermansb
May 11 2017 22:08
I put on Stackoverflow
Jason Shin
@JasonShin
May 11 2017 22:53
hey guys, FP noob here.
If I have below scenario, how would you write it into composable functions and compose them together in the end?
1) Receive a message from socket client
2) perform some database logics
3) send a message to the same socket client
4) receive a reply
5) broadcast more messages to rest of socket clients
Kevin Wallace
@kedashoe
May 11 2017 23:49
@JulienBonnin-ABTasty glad you are enjoying ramda :)
transducers were added mostly as an experiment
in theory if you are composing many functions and using a lot of data, they will be more efficient than the same composition without them
you are seeing the same result in your example because it does not matter which order your operations are performed in
if you do this, https://goo.gl/61dRbr, for example, you will see different results