These are chat archives for ramda/ramda

18th
Apr 2016
Raine Virta
@raine
Apr 18 2016 06:46
@That-David-Guy partial when you want to make a new function with all arguments of the original one predefined. most of the time you'll use curry
Aldwin Vlasblom
@Avaq
Apr 18 2016 07:51

@That-David-Guy curry is a convenience over partial. You can view curry as a sort of auto-partial. With curry you're able to create a function which will always return a partially applied version of itself when you don't provide it all of its arguments. This means the consumer of the function doesn't have to go through the trouble of wrapping the function in partial when they only have part of its arguments.

This may seem an underwhelming convenience at first, until you realize that in Functional Programming, you partially apply almost every function all the time.

Dalibor Novak
@BorePlusPlus
Apr 18 2016 17:02
Hello ramda folks, how to do this in pointfree efficient manner?
function codeOf(obj) {
  return R.path(['err', 'code'], obj) || R.path(['err', 'status'], obj) || R.path(['err', 'statusCode'], obj);
}
essentially I want to try few different paths and return first truthy value
Brad Compton (he/him)
@Bradcomp
Apr 18 2016 17:30
@BorePlusPlus You could try something like this: http://goo.gl/CUhnX0
It's point free, but less readable than what you have going on.
Dalibor Novak
@BorePlusPlus
Apr 18 2016 17:31
@Bradcomp thanks - you're right on both
Also it will traverse all the options rather than just what it needs to. Not that I am writing any kind of high performance code...
Sergey Yavnyi
@blacktaxi
Apr 18 2016 21:26
Hi everyone! A question about the lens implementation in Ramda. I see that it is the van Laarhoven encoding of the lens. Any particular reason for this implementation? I know that in statically typed languages like Haskell this encoding gives you the ability to do polymorphic updates, but there doesn't seem to be a problem with this in JavaScript.
Scott Christopher
@scott-christopher
Apr 18 2016 21:57
@blacktaxi Part of the reason was to be able to reuse compose for lens composition.
It also has the potential for traverse to be used in lens compositions.
Scott Christopher
@scott-christopher
Apr 18 2016 22:02
(albeit we'd need to expose the internal types to make that closer to being usable)
Sergey Yavnyi
@blacktaxi
Apr 18 2016 22:44
Thanks. And what do you think about performance/efficiency, when comparing this impl vs naive getter + setter in an objects?
Chet Harrison
@ChetHarrison
Apr 18 2016 22:46
If I do a
Scott Christopher
@scott-christopher
Apr 18 2016 22:46
There is an overhead to the van Laarhoven approach, however I haven't personally had issues where that was contributing to a bottlenck.
Chet Harrison
@ChetHarrison
Apr 18 2016 22:48
getMajorAmount = R.divide( R.prop( 'a' ), R.prop( 'b' ) );
getMajorAmount( { a : 10, b : 2 } );
should I get 5?
Or is the Obj arg not fed to the prop calls?
Scott Christopher
@scott-christopher
Apr 18 2016 22:49
@ChetHarrison Nope, you're attempting to divide two partially applied functions there.
Chet Harrison
@ChetHarrison
Apr 18 2016 22:49
ok. is there a point free way to do this?
Scott Christopher
@scott-christopher
Apr 18 2016 22:50
R.converge(R.divide, [R.prop('a'), R.prop('b')]) should do it.
Chet Harrison
@ChetHarrison
Apr 18 2016 22:50
:+1: thanks!
Scott Christopher
@scott-christopher
Apr 18 2016 22:51
@ram-bot
const getMajorAmount = R.converge(R.divide, [R.prop('a'), R.prop('b')])
getMajorAmount({a: 10, b: 2})
ram-bot
@ram-bot
Apr 18 2016 22:51
5
Scott Christopher
@scott-christopher
Apr 18 2016 22:53
This message was deleted
Alternatively
@ram-bot
const divideBy = R.lift(R.divide)
const getMajorAmount = divideBy(R.prop('a'), R.prop('b'))
getMajorAmount({a: 10, b: 2})
ram-bot
@ram-bot
Apr 18 2016 22:53
5
Chet Harrison
@ChetHarrison
Apr 18 2016 22:54
hmm I do kinda like that one
David Langford
@That-David-Guy
Apr 18 2016 23:49
Thanks @raine @Avaq . So in general I should use R.curry over R.partial