These are chat archives for ramda/ramda

27th
Feb 2015
Hardy Jones
@joneshf
Feb 27 2015 00:51
Scott Sauyet
@CrossEye
Feb 27 2015 03:36
Until a few weeks ago, ramda-fantasy was very much experimental. @buzzdecafe has been giving it some love and it's definitely improving. But some of the other implementations are clearly better established.
Raine Virta
@raine
Feb 27 2015 09:16
just wondering. is it an antipattern to access .value directly in a Just if you've first pattern matched Just vs. Nothing?
with instanceof
Ludwig Magnusson
@TheLudd
Feb 27 2015 09:55
@rane I think Maybe should have an access method to get the value inside. Currently, no such method exists so accessing .value would be the only way now it seems
Michael Hurley
@buzzdecafe
Feb 27 2015 12:07
:tada:
scott is ramda's philosopher king :smile:
Ludwig Magnusson
@TheLudd
Feb 27 2015 12:07
congrats
Hardy Jones
@joneshf
Feb 27 2015 12:19
@raine yes, you should almost never need or want to directly access value. As @TheLudd said, the api could stand to grow some more.
with a good api, you should almost never need or want to pattern match either
Raine Virta
@raine
Feb 27 2015 12:22
joneshf: that's what i thought
i think i've used .orElse in data.maybe before, but i didn't see something like that in sanctuary
Hardy Jones
@joneshf
Feb 27 2015 12:30
I was not aware you could indent the body of a case like that in ls
Ludwig Magnusson
@TheLudd
Feb 27 2015 12:32
@CrossEye Congratulations to the javascript weekly inclusion. I read your entire post now, very well written.
Michael Hurley
@buzzdecafe
Feb 27 2015 14:00

@joneshf this looks to me like a super useful pattern:

var objLens = function(p) { return R.lens(R.prop(p), R.assoc(p)); };

i wonder if it is worth including in the lib, e.g. as lensOn or some such. Then it might also be possible to bind the map function on lens to the object p and use any a -> b mapper

Hardy Jones
@joneshf
Feb 27 2015 14:28
sure
those lenses are Functors
Raine Virta
@raine
Feb 27 2015 15:27
the Fork button on ramdajs.com is against the general convention of "Fork me on GitHub" which is to go to github page, not actually fork the project
because people use those ribbons to go checkout the project on github
Michael Hurley
@buzzdecafe
Feb 27 2015 15:30
fair enough, probably better just to have the octocat icon and point to the repo
Ludwig Magnusson
@TheLudd
Feb 27 2015 16:38
Just noticed that there is not parse method in ramda. Would such a thing be of interest?
String -> Number
Michael Hurley
@buzzdecafe
Feb 27 2015 16:39
like parseInt and parseFloat?
Ludwig Magnusson
@TheLudd
Feb 27 2015 16:41
indeed
But without the baggage
like radix
John-David Dalton
@jdalton
Feb 27 2015 16:41
partial it
Michael Hurley
@buzzdecafe
Feb 27 2015 16:42
i assume you mean apply the radix param?
John-David Dalton
@jdalton
Feb 27 2015 16:42
yah
there's other baggage but its like edge baggage dealing with parseInt behavior in ES3 vs ES5 enviros
partial or capping its arguments would do
if you do partial use the radix of 0
the engine will then pick the one approp for it
Ludwig Magnusson
@TheLudd
Feb 27 2015 16:45
better than 10?
John-David Dalton
@jdalton
Feb 27 2015 16:45
If radix is undefined or 0, it is assumed to be 10 except when the number begins with the character pairs 0x or 0X, in which case a radix of 16 is assumed.
Robin Lambertz
@roblabla
Feb 27 2015 16:46
I thought RamdaJS suppoted es3 though ?
Michael Hurley
@buzzdecafe
Feb 27 2015 16:46
interesting. is the behavior specified pre-es5?
Ludwig Magnusson
@TheLudd
Feb 27 2015 16:46
is it just es3 that has the lovely "if it begins with 0 I assume radix 8"-feature?
Michael Hurley
@buzzdecafe
Feb 27 2015 16:48
@roblabla yes, at present the lib is es3 compliant
would love to get rid of that albatross
Ludwig Magnusson
@TheLudd
Feb 27 2015 16:48
@buzzdecafe +1^100
John-David Dalton
@jdalton
Feb 27 2015 16:48
the es3/es5 thing has to do with leading zeros
Ludwig Magnusson
@TheLudd
Feb 27 2015 16:49
Then parseInt works fine
Michael Hurley
@buzzdecafe
Feb 27 2015 16:49
@TheLudd 1^100 === 1 :smile:
Ludwig Magnusson
@TheLudd
Feb 27 2015 16:49
;)
Robin Lambertz
@roblabla
Feb 27 2015 16:49
+2^53+1 ?
John-David Dalton
@jdalton
Feb 27 2015 16:49
the 0 radix thing should be es3 too
Michael Hurley
@buzzdecafe
Feb 27 2015 16:51
seems like two bad choices, though
either apply the radix in and let the engine interpret
or do some sort of flip(parseInt) and let the use pass in radix
John-David Dalton
@jdalton
Feb 27 2015 16:52
for simple cases they can just Number(value)
ya providing the radix is fine too
Michael Hurley
@buzzdecafe
Feb 27 2015 16:54
@TheLudd this is the first time it's come up, so probably not a rush item
John-David Dalton
@jdalton
Feb 27 2015 16:54
currently thats what I do for lodash-fp _.parseInt(radix)(string)
Michael Hurley
@buzzdecafe
Feb 27 2015 16:54
do you assign _.parseInt(0) to another fn?
Ludwig Magnusson
@TheLudd
Feb 27 2015 16:55
I asked because I needed it now, which is usually the time when I make contributions =). But now that I know that parseInt works better in ES5 I see no need for it
John-David Dalton
@jdalton
Feb 27 2015 16:56

do you assign _.parseInt(0) to another fn?

auto-curry? ya (in the -fp flavor)

Michael Hurley
@buzzdecafe
Feb 27 2015 16:56
sounds reasonable. what i don't want is parseInt10/parseInt8 etc
John-David Dalton
@jdalton
Feb 27 2015 16:56
lol gross
but ya it gets a little tricky fp doesnt favor optional params
Michael Hurley
@buzzdecafe
Feb 27 2015 16:57
only this flavor of fp
LISP is all about variadic functions
although i guess optional params is a bit different
John-David Dalton
@jdalton
Feb 27 2015 16:58
ya (ot I love the github emoji integration here :sparkles: )
Michael Hurley
@buzzdecafe
Feb 27 2015 16:58
but it is just about impossible to have optional params and default curry
ot I love the github emoji integration here
agreed, it's a pretty nice interface
Raine Virta
@raine
Feb 27 2015 18:50
luckily gitter has irc interface
Danny Fritz
@dannyfritz
Feb 27 2015 18:50
no emoticons or markdown for you @raine ;)
Raine Virta
@raine
Feb 27 2015 18:51
or editing messages or code highlighting
although i do sometimes open gitter in browser when posting code just to not be a pain in the ass for others
Jethro Larson
@jethrolarson
Feb 27 2015 19:31
I see lodash is getting _.add. I'm sure more operators will follow
John-David Dalton
@jdalton
Feb 27 2015 19:35
Yap
Added based on demand. In this case the demand of _.sum. _.add is a side effect of that.
Jethro Larson
@jethrolarson
Feb 27 2015 19:47
Cool. With the auto-curry style, operator functions are more handy than they would otherwise be
John-David Dalton
@jdalton
Feb 27 2015 19:48
Rock, if you have good examples open a doc issue & we'll add them as usage examples.
Jethro Larson
@jethrolarson
Feb 27 2015 19:49
R.sum = R.reduce(R.add, 0); is the first that came to mind :)
John-David Dalton
@jdalton
Feb 27 2015 19:51
Yap if shortness was the only goal. We'll balance dependencies and depth of dependencies for those wanting to cherry-pick modules.
e.g. require('lodash/math/sum') or require('lodash.sum')
David Chambers
@davidchambers
Feb 27 2015 21:17

@raine:

just wondering. is it an antipattern to access .value directly in a Just if you've first pattern matched Just vs. Nothing?

I agree with @joneshf's reply, but I'll add that I have found it necessary to do something along these lines in unit tests:

// Does not work since .equals() uses === equality.
assert(S.Just([1, 2, 3]).map(function(n) { return n + 1; }).equals(S.Just([2, 3, 4])));

// Icky workaround.
var result = S.Just([1, 2, 3]).map(function(n) { return n + 1; });
assert.strictEqual(result.constructor, S.Just);
assert.deepEqual(S.fromMaybe(null, result), [2, 3, 4]);

This approach at least avoids accessing the value property directly.

i've used .orElse in data.maybe before, but i didn't see something like that in sanctuary

Sanctuary provides or :: f a -> f a -> f a which should do the trick:

S.or(S.Nothing(), S.Nothing());  // => S.Nothing()
S.or(S.Nothing(), S.Just('default'));  // => S.Just('default')
S.or(S.Just('blah'), S.Nothing());  // => S.Just('blah')
S.or(S.Just('blah'), S.Just('default'));  // => S.Just('blah')
Hardy Jones
@joneshf
Feb 27 2015 21:20
could equals be implemented with ramda's eqDeep?
then you should be able to use the first line
David Chambers
@davidchambers
Feb 27 2015 21:31

I've been thinking we want some sort of equivalence function which dispatches to equals if present, otherwise checks for deep equality. Perhaps rather than R.eq and R.eqDeep we could have R.identical and R.equivalent:

R.identical(42, 42);  // => true
R.identical(NaN, NaN);  // => true
R.identical([1, 2, 3], [1, 2, 3]);  // => false

R.equivalent([1, 2, 3], [1, 2, 3]);  // => true
R.equivalent(S.Just(42), S.Just(42));  // => true
R.equivalent(S.Just([1, 2, 3]), S.Just([1, 2, 3]));  // => true (ideally)

What do you think?

Hardy Jones
@joneshf
Feb 27 2015 21:33
I'm not sure what is different
Eero Saynatkari
@rue
Feb 27 2015 21:43
I’d substitute same (or something) for identical, which to me has the explicit connotation of not being the same
John-David Dalton
@jdalton
Feb 27 2015 21:49
QUnit has equal and strictEqual
Hardy Jones
@joneshf
Feb 27 2015 21:50
how does ==/=== work in js when it's a user defined object?
John-David Dalton
@jdalton
Feb 27 2015 21:51
objects will compare false
unless they are the same object
Hardy Jones
@joneshf
Feb 27 2015 21:51
for any object?
John-David Dalton
@jdalton
Feb 27 2015 21:51
yap
Hardy Jones
@joneshf
Feb 27 2015 21:51
k
John-David Dalton
@jdalton
Feb 27 2015 21:51
try this
[1] == [1] // false
[1] == '1' // true
that's why libs have equivalence sugar
Robin Lambertz
@roblabla
Feb 27 2015 21:53
heh.
{} + {} == NaN
John-David Dalton
@jdalton
Feb 27 2015 21:54
thats actually an empty block and +{} literal I believe
compare to +({})+({})
Robin Lambertz
@roblabla
Feb 27 2015 21:57
not the same result
that does 'NaN[object Object]'
John-David Dalton
@jdalton
Feb 27 2015 21:58
yap
Robin Lambertz
@roblabla
Feb 27 2015 21:58
IDK enough js internals really :P
I just know enough about the type system to know that if you take objects/arrays does really weird stuff when coerced :P
Jethro Larson
@jethrolarson
Feb 27 2015 23:26
One strange thing about using coffeescript and ramda is that if I forget a comma on a curried function arg it'll often still work
I wont exactly call that a feature as it can lead to hard to identify bugs but it amused me.
John-David Dalton
@jdalton
Feb 27 2015 23:41
es6 instead? https://babeljs.io/
Robin Lambertz
@roblabla
Feb 27 2015 23:42
some people use coffeescript for braces-less syntax :P
Robin Lambertz
@roblabla
Feb 27 2015 23:42
(That's actually the thing that made me try it out at first. Tho it turns out I ended up hating it for that)
Raine Virta
@raine
Feb 27 2015 23:47
in livescript curried functions, partial application and compose are first-class citizens