These are chat archives for ramda/ramda

15th
Jun 2015
Raine Virta
@raine
Jun 15 2015 06:59
big changes
I don't quite like the name R.identical, although in many cases you could now use R.equals instead of the old eq?
David Chambers
@davidchambers
Jun 15 2015 07:09
Yes. R.identical is for the rare cases when one wishes to compare by identity rather than by value.
I copied the name from Clojure, but you're not the only person who doesn't like it very much.
Tobias Pflug
@gilligan
Jun 15 2015 07:12
@joneshf : haha.. re fantasy-land. yeah too bad people were total idiots and did not even try to understand what puffnfresh was suggesting apparently. Sigh
Raine Virta
@raine
Jun 15 2015 07:47
what's the purpose of dispatching equals? so that you can use it with your implementation of a tree type etc?
Simon Friis Vindum
@paldepind
Jun 15 2015 08:04
@raine It's part of fantasy land. That is also the reason for the tragic rename.
Raine Virta
@raine
Jun 15 2015 08:12
maybe that could be mentioned in the docs
Raine Virta
@raine
Jun 15 2015 08:29
:point_up: June 12 2015 11:34 AM @scott-christopher this doesn't actually remove the undefined values
Raine Virta
@raine
Jun 15 2015 08:35
var isUndefined = function(it){
  return it === void 8;
};
var pickDefined = pickBy(complement(isUndefined));
maybe that
Scott Christopher
@scott-christopher
Jun 15 2015 08:52
@raine: My apologies, you are correct.
Your isUndefined could be replaced with R.isNil if you don’t mind null values being stripped too.
Raine Virta
@raine
Jun 15 2015 08:54
true, but I think stripping just undefineds is a bit correct because some APIs might think of nulls as valid values
Scott Christopher
@scott-christopher
Jun 15 2015 08:54
Or, R.identical(void 0)
ganzuul
@ganzuul
Jun 15 2015 09:03
Hello. Why doesn't this work: http://jsfiddle.net/2s30arw8/4/ While this does work? - http://jsfiddle.net/2s30arw8/3/
Raine Virta
@raine
Jun 15 2015 09:08
well /4/ can't work because you're partially applying both pyth and R.replace and hypo is therefore a partially applied function that has not yet evaluated to the object that has hyp property
ganzuul
@ganzuul
Jun 15 2015 10:14
Is closure PA and ramda PA incompatible?
ganzuul
@ganzuul
Jun 15 2015 10:21
Or is R.repace + R. the wrong way to get this sort of bounded partial application?
Scott Christopher
@scott-christopher
Jun 15 2015 10:47
@ganzuul I don’t entirely follow what you’re trying to acheive with the structure of pyth, but if you just want a curried function then you can do something like:
var pyth = R.curry(function(x, y) {
    return Math.sqrt(x * x + y * y);
});
var hypo = pyth(3);
var result = hypo(4);
ganzuul
@ganzuul
Jun 15 2015 11:11
I think that what I'm trying to do is write code which reads like English and relies on simple concepts like closures, where I can give everything which needs it descriptive names which speak about something concrete and relatable, and when you look up the definition you can easily see the implementation.
ganzuul
@ganzuul
Jun 15 2015 11:19
I hope to write code in such a pattern that I describe the states of a state machine in JSON, and the verbose JSON together with the logic of the FSM make a protocol/API.
Or micro-protocol.
That way, the JSON always provides a map to the possible states of the code it is associated with.
Raine Virta
@raine
Jun 15 2015 11:28
This message was deleted
Scott Christopher
@scott-christopher
Jun 15 2015 11:31
@ganzuul: If you want to stick with your existing pyth function, you can partially apply it like so:
var hypo = pyth(3);
var result = hypo(4).hyp();
ganzuul
@ganzuul
Jun 15 2015 11:34
!:D
Thank you! :D
Scott Christopher
@scott-christopher
Jun 15 2015 11:34
You’re welcome :smile:
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 16:20
I am trying to figure out how to achieve this with ramda. https://gist.github.com/ashnur/3c291781d3e40ef9d557 All three versions do basically the same (first one has 0 duplicated, but that's minor). I was trying to find some kind of way to have lazy sequences generated but all tools seem to be focused for different usages.
Hardy Jones
@joneshf
Jun 15 2015 16:23
What are you trying to achieve? I'm a bit unclear.
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 16:25
joneshf: it's for a property based test, this is for shrinking integers. i got it originally from haskell quickcheck code: https://hackage.haskell.org/package/QuickCheck-2.6/docs/src/Test-QuickCheck-Arbitrary.html#shrink
obviously, there are many ways to achieve this, however I am trying to learn while I am doing it, that's why I implemented it multiple ways, although the first one is not my code just the second and the third
Hardy Jones
@joneshf
Jun 15 2015 16:27
maybe i don't understand all of operators being used
~~
Also isn't shrink : a -> [a]?
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 16:32
joneshf: that's just a way to have Math.floor but always going towards 0 instead of always to the smaller integer. Math.floor(-2.6) is -3 but ~~2.6 is -2
Hardy Jones
@joneshf
Jun 15 2015 16:32
ah
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 16:32
and yes, shrink is a -> [a] and all these return (or fill up) an array.
first one is obviously an array, the other two are pushing into an array rs
the result is always [ 0, 50, 75, 88, 94, 97, 99 ] (although the first one needs _.uniq for this)
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 16:41
well, I am not quite about a direct translation, but rather how I would have the same functionality done with ramda and maybe some other compatible tools
Hardy Jones
@joneshf
Jun 15 2015 16:44
ah, gotcha
well, I think just break it down into parts, and build up your algo from there
the basic idea with shrinking is to provide smaller values than the current value yeah?
the shrink algo you implemented seems to favor the upper half in a logarithmic sort of way
but you can shrink other ways as well
you can shrink uniformly
which is probably the easiest
I'm sure there's some sort of statistical analysis you can do which tells you what way is generally best.
but a uniform shrink could be just dividing the number in to three parts or so
and making an array of that
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 16:50
joneshf: my problem wasn't on how to shrink, it's rather, how to have these generated sequences without having it push into an array or without having this lispy kind of car/cdr joining of arrays (linked lists on top of arrays) where the head is the value and then a function is the second element
which is the first implementation, I like that a lot but I would want to avoid the [value, fn] construct
mainly because nothing works with it, and I would have to reimplement everything.
Hardy Jones
@joneshf
Jun 15 2015 16:52
oh
also uniform doesn't really work anyway, as you'll lose the upper area...
well there's R.append if you dont' want to use push
and R.prepend
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 16:57
joneshf: that's the same :). My issue is not with the name, rather than the modifying of an existing array
Hardy Jones
@joneshf
Jun 15 2015 16:57
neither of those modify an array
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 16:57
(or creating many new ones)
yes, i realized my mistake right away :)
Hardy Jones
@joneshf
Jun 15 2015 16:58
hmm, well what else is there?
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 16:59
lazy sequences
or more precisely, lazily generated sequences.
however what i found was not for recursive things, or I just couldn't find it
I was told before (here) that " Ramda doesn’t provide any lazy data structures, but many of its methods dynamically dispatch. R.take(3, seq), for example, is equivalent to seq.take(3) if seq provides a take method."
Hardy Jones
@joneshf
Jun 15 2015 17:00
What i mean is, isn't this a dichotomy? You either create a bunch of new arrays, or you modify the existing one.
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 17:01
not if you have that ^
Hardy Jones
@joneshf
Jun 15 2015 17:02
Okay I'm interested. :) How's it different?
when you force the tail, doesn't that create a new array?
or sequence i guess
sorry for the bird walk
you've piqued my interest :)
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 17:05
joneshf: but take() creates one array and that's all
Hardy Jones
@joneshf
Jun 15 2015 17:05
Oh, I see!
defer the creation of the array until the whole sequence is forced
yeah?
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 17:08
yes
i wish i thought of those words :D
Hardy Jones
@joneshf
Jun 15 2015 17:14
Okay, so back on the path, you want to use ramda for lazy sequences?
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 17:15
well, i will use ramda anyway
and it has support for these .take-y things
so either I find something which generates them, or I will have to write that myself
i was trying lazy.js but seemed like that project is dead
same with lz.js
Hardy Jones
@joneshf
Jun 15 2015 17:20
doesn't immutable.js provide laziness?
also, its probably easier to go with someone else's library than roll your own.
though it still wouldn't be hard
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 17:20
it would be hard for me, so that's why i asked for help :)
i am not good at functional things
Hardy Jones
@joneshf
Jun 15 2015 17:21
Oh.
well you can make it way less painful for yourself by implementing some abstractions.
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 17:21
and you are right, immutable.js has lazy Seq
Hardy Jones
@joneshf
Jun 15 2015 17:21
since sequences are basically lazy lists, you can do a whole mess of stuff on them
namely, Functor, Applicative, Monad, Foldable, Traversable.
Though if you basically implement the Monad and Traversable interfaces, you're golden.
you get map, reduce, and friends for free
so you can have take for free as well.
or drop or filter or any of those other things for free.
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 17:23
i think first i will try immutable.js :)
Hardy Jones
@joneshf
Jun 15 2015 17:23
sure.
though if you want to, we can work through it.
you only need to implement three functions.
one of which is supremely trivial.
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 17:24
?
i am curious
Hardy Jones
@joneshf
Jun 15 2015 17:24
so basically two functions.
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 17:25
i know some stuff about monoids and the rest, but my knowledge is very superficial
Hardy Jones
@joneshf
Jun 15 2015 17:26
So Monad needs flatMap/chain/bind implemented, and point/of/pure implemented, then you get map for free, and ap, and lift3 and all that good stuff.
GÁBOR Áron Zsolt
@ashnur
Jun 15 2015 17:26
i saw these in the fantasy land spec
which I think is followed by ramda to some degree
Hardy Jones
@joneshf
Jun 15 2015 17:27
Traversable needs sequence or traverse implemented (sequence is usually easier to implement), and then you get map, reduce, scan, take, drop, filter, all, any, sum, product, etc for free.
point/of/pure being the super simple one to implement.
yeah, ramda dispatches on most things.
obviously it can't on of or empty.
Scott Sauyet
@CrossEye
Jun 15 2015 20:53
Ramda did once have a lazy list extension, which got pulled out as not being close to the core. A search of the issues log would probably find it. I don't think it was very efficient, though.