These are chat archives for ramda/ramda

11th
Sep 2015
Johnny Everson
@everson
Sep 11 2015 01:36
Hi. where I can find examples of lens for deeper property levels?
David Chambers
@davidchambers
Sep 11 2015 01:38
Johnny Everson
@everson
Sep 11 2015 01:39
@davidchambers thanks
Scott Sauyet
@CrossEye
Sep 11 2015 01:47
How did I miss that thread? A very nice explanation, David. (As usual!)
David Chambers
@davidchambers
Sep 11 2015 01:47
Thanks!
Martin Algesten
@algesten
Sep 11 2015 03:58
@davidchambers great! i think I get lenses now.
David Chambers
@davidchambers
Sep 11 2015 04:30
I'm pleased to hear it! Lenses are great.
Raine Virta
@raine
Sep 11 2015 07:49
should the docs mention if a function dispatches to a method? have there been plans for consistent way to present it?
Ludwig Magnusson
@TheLudd
Sep 11 2015 08:09
@raine I think they should mention it if it is a feature of the function, not if it is an implementation detail
Scott Sauyet
@CrossEye
Sep 11 2015 10:59
@TheLudd agreed. We should figure out how to present this. Current discussions in #1367 seem relevant too.
Raine Virta
@raine
Sep 11 2015 11:43
a special jsdoc annotation perhaps?
@dispatches filter 2
=> Dispatches to the filter method of the second argument if applicable.
hemanth @hemanth just made a fun little module https://github.com/hemanth/ramda-repl ;)
Raine Virta
@raine
Sep 11 2015 11:45
@hemanth I have a custom repl that extends context with all ramda functions
hemanth.hm
@hemanth
Sep 11 2015 11:47
@raine WOW nice, will you help me to extend this ;) ? I did try to use vm and runInContext
hemanth.hm
@hemanth
Sep 11 2015 11:49
@raine nice, treis is ain't mandatory right?
Raine Virta
@raine
Sep 11 2015 11:50
nah
hemanth.hm
@hemanth
Sep 11 2015 11:51
nice
@raine what are you on npm, I want to add you as a maintainer, if you have no issue about that :)
hemanth.hm
@hemanth
Sep 11 2015 12:04
Done, released a newer version, FOSS FTW!
BTW this month I am doing a talk on going functional with javascript, using ramda as the base lib :)
Hmm, say you need to introduce someone to functional programming concepts with JavaScript, you get to pick up an imperative JS code and convert it to FP paradigm...which JS code would you pick ?
Tobias Pflug
@gilligan
Sep 11 2015 13:13
uhm. i am somewhat dumbfolded right now.. R.join(' ', [1,2,3])
that should yield '1 2 3' i suppose
and not TypeError: [1, 2, 3] does not have a method named "join"
David Chase
@davidchase
Sep 11 2015 13:18
how did you get that error?
Tobias Pflug
@gilligan
Sep 11 2015 13:19
just playing around in a node repl
which is weird because this works just fine : http://ramdajs.com/repl/#R.join('~'%2C%20%5B1%2C2%2C3%5D)
Scott Sauyet
@CrossEye
Sep 11 2015 13:19
Works in the Ramda REPL.
Tobias Pflug
@gilligan
Sep 11 2015 13:20
yup.
its just quite bizarre that the repl would somehow screw something up
Raine Virta
@raine
Sep 11 2015 13:20
I get it too, but only in my custom repl
Tobias Pflug
@gilligan
Sep 11 2015 13:20
@raine yeah sort of custom here as well.. using 'repl' node module ..
Raine Virta
@raine
Sep 11 2015 13:21
if I recall correctly, this isn't the first weird inconsistency I've had in repl
Tobias Pflug
@gilligan
Sep 11 2015 13:21
i see
i was just seriously starting to doubt myself hehe
Scott Sauyet
@CrossEye
Sep 11 2015 13:23
I wonder if there's something weird about invoker in those environments.
Raine Virta
@raine
Sep 11 2015 13:24
[].join returns a function at least
Scott Sauyet
@CrossEye
Sep 11 2015 13:27
How about R.is(Function, [].join) ?
David Chase
@davidchase
Sep 11 2015 13:27
this returned false for me R.is(Function, [1,2,3]['join']);
but in the ramda repl true
Scott Sauyet
@CrossEye
Sep 11 2015 13:27
timing
G
I think we may have to revisit is. It sounds something like typical cross-frame issues.
Tobias Pflug
@gilligan
Sep 11 2015 13:30
R.is(Function, [1,2,3]['join']); returns true here
Johnny Everson
@everson
Sep 11 2015 15:39
Hi, In a List, how do I replace an element matching a predicate, while retaining the position? (the way I know is filter + append, which does not retain position or map with if() else)
Hardy Jones
@joneshf
Sep 11 2015 15:44
@khronnuz you've got it right
map then handle each element.
Johnny Everson
@everson
Sep 11 2015 15:46
@joneshf thanks
Hardy Jones
@joneshf
Sep 11 2015 15:50
Like if you wanted to replace evens with the number 12
function even(x) { return x % 2 === 0; }
R.map(R.ifElse(even, R.always(12), R.identity), R.range(1, 10)) //=> [1, 12, 3, 12, 5, 12, 7, 12, 9]
Johnny Everson
@everson
Sep 11 2015 15:58
awesome, thanks.
Jethro Larson
@jethrolarson
Sep 11 2015 16:28
@hemanth something that's not super dry but mechanically simple
Jethro Larson
@jethrolarson
Sep 11 2015 16:39
Transforming arrays of records is a good use case
Matthew Steedman
@knubie
Sep 11 2015 17:47
I've run into an odd problem that I can't quite figure out: http://goo.gl/bNIGc3
I'm not sure why the two function calls at the end return different values
(also, the url shortener on the repl appears to be broken)
Chet Harrison
@ChetHarrison
Sep 11 2015 17:53
why does the Ramtuary Repl flag const is there an option I'm missing?
Jethro Larson
@jethrolarson
Sep 11 2015 17:56
@knubie that's a good question. I don't know either
Matthew Steedman
@knubie
Sep 11 2015 18:30
Same behavior without the placeholders: http://goo.gl/MwWdRl
Alex Schenkman
@alesch
Sep 11 2015 18:30

Hi folks,
Is there a better way to write this?
Thanks in advance!

function idEquals (x) {
  return R.pipe(R.prop('id'), R.equals(x));
}

I want to test if an object’s id property equals x.

Jethro Larson
@jethrolarson
Sep 11 2015 18:30
maybe
Matthew Steedman
@knubie
Sep 11 2015 18:33
Alex Schenkman
@alesch
Sep 11 2015 18:34
@knubie Nice!
Jethro Larson
@jethrolarson
Sep 11 2015 18:35
var idEquals = function(x, o){
  return  R.equals(x)(R.prop('id')(o))
}
tacit:
var idEquals = R.useWith(R.equals, R.prop('id'))
And then what @knubie said is even smaller
var idEquals = R.propEq('id')
Drew
@dtipson
Sep 11 2015 18:45
does the useWith version need to be R.flip(R.useWith(R.equals, R.prop('id'))); ? To be able to specify the target first and the data later like propEq takes it? http://bit.ly/1OjjWHN
Tobias Pflug
@gilligan
Sep 11 2015 18:57
hrm, is anyone here experienced with jsverify ?
Kevin Wallace
@kedashoe
Sep 11 2015 19:14
@knubie , the function returned by either is not curried
in your 2nd invocation, which returns false
you first call either with the single argument foo
either than applies this to the first function you gave it earlier, curriedFunc('biz')
curriedFunc is a curried function which takes 3 arguments
so either is calling curriedFunc('biz')('foo'), which returns a function waiting for that 3rd argument
the function is then coerced to true in either, so it short circuits, never calls the second function, and returns the curried function
you then pass curriedFunc('biz')('foo') its last parameter, bar, and curriedFunc('biz')('foo')('bar') evaluates to false
Kevin Wallace
@kedashoe
Sep 11 2015 19:19
at least that is what i think is happening :)
Jethro Larson
@jethrolarson
Sep 11 2015 19:40
gahh losing context in js makes OOP+FP a f'n pain
Either you .bind every damn thing(unperformant) or pass context everywhere(negates value of OOP)
Matthew Steedman
@knubie
Sep 11 2015 22:01
@kedashoe wow, that actually makes perfect sense
thanks so much for that haha
Kevin Wallace
@kedashoe
Sep 11 2015 22:35
i think we could actually curry the function returned from both and either, since the same argument are applied to the functions it receives
for now, you could just call curryN on the function you get back from either