These are chat archives for ramda/ramda

7th
Jun 2015
Hardy Jones
@joneshf
Jun 07 2015 06:40
I think Tuple might be lying about being Applicative in ramda-fantasy
coffee> RF.Tuple.of(R.identity).ap(RF.Tuple([1], [2]))
/home/joneshf/node_modules/ramda-fantasy/src/Tuple.js:27
          throw new TypeError(display + " must be a semigroup to perform this
i don't think you can implement of this way.
or even at all in js.
Hardy Jones
@joneshf
Jun 07 2015 06:47
I think im going to have a go at moving more tests over to jsverify again
Scott Christopher
@scott-christopher
Jun 07 2015 08:27
@joneshf : It looks like it is following the Haskell definition of applicative for a tuple, where given (a, x) and (b, y), aand b are mappended together (requiring the first elements of each tuple to be a semigroup) while x is applied with y.
Scott Christopher
@scott-christopher
Jun 07 2015 09:07
Though that example expects the first element to also be a monoid, such that it pure/of can initialise it using mempty/empty.
Hardy Jones
@joneshf
Jun 07 2015 11:52
yeah, that's the problem. there's no compiler implicitly creating and passing around the Monoid in js. So of cannot be implemented this way.
map, apply and chain should be fine though
Michael Hurley
@buzzdecafe
Jun 07 2015 11:54
are you saying this implementation is wrong, or that Tuple cannot be applicative?
(in js)
hmmm
_Tuple.prototype.ap = function(m) {
  ensureConcat([this[0]]);
  return Tuple(this[0].concat(m[0]), this[1](m[1]));
};
Hardy Jones
@joneshf
Jun 07 2015 11:55
the latter
the implementation can do whatever it wants, but it's not law abiding
Michael Hurley
@buzzdecafe
Jun 07 2015 11:56
in your example m is a function, so it doesn't concat
but the second item in the tuple must be a function for ap
Hardy Jones
@joneshf
Jun 07 2015 11:57
well function not having concat is another thing that could be fixed, but that's a discussion for another time.
correct
Michael Hurley
@buzzdecafe
Jun 07 2015 11:58
yes, i'm just catching up on the conversation so far
Hardy Jones
@joneshf
Jun 07 2015 11:58
ap still gives you a law abiding Apply
k
Michael Hurley
@buzzdecafe
Jun 07 2015 11:58
yes, if i have Tuple([], function f(x) { return x; }), i can ap with it
but i see how of is borked
could we implement of in terms of Identity? e.g. of = function(x) { return new Tuple(new Identity(x), new Identity(x)); }
or does that that kick the problem down the road a bit
Hardy Jones
@joneshf
Jun 07 2015 12:34
yeah
the second part
it actually is equivalent to what's in there now
maybe there's a way to use the dynamicism to have some universal monoid...
though, that'll probably cause problems elsewhere
Another option is to change ap, chain and map to match semantics of of
but i think you are better off not doing that
Michael Hurley
@buzzdecafe
Jun 07 2015 12:38
ok, so simplest thing may be to just uncheck the Apply box for Tuple
Hardy Jones
@joneshf
Jun 07 2015 12:38
Applicative
it's still a valid Apply
Michael Hurley
@buzzdecafe
Jun 07 2015 12:39
right, apologies
Asaf
@asaf-romano
Jun 07 2015 12:45
Is there something like range, which takes a function for each step.
(e.g. for generating dates between start and end dates)
Michael Hurley
@buzzdecafe
Jun 07 2015 12:47
wouldn't you just map over the range?
Asaf
@asaf-romano
Jun 07 2015 12:47
i've just start and end dates, which I'm going to process with moment.js
ideally their recur plugin wouldn't suck :-/
I could do this with reduce (looking at the last element)
Hardy Jones
@joneshf
Jun 07 2015 12:50
can you provide some sample input output?
Asaf
@asaf-romano
Jun 07 2015 12:54
let's simplify this to (1, 10) => [2, 4, 6. 8] (but not through range and filter/reject :) )
Hardy Jones
@joneshf
Jun 07 2015 12:57
why not use range, or filter?
Raine Virta
@raine
Jun 07 2015 12:57
it's LS but which one do you think is more readable? http://git.io/vIcQZ the difference is basically that in the first one the first level is part of the recursive function
Asaf
@asaf-romano
Jun 07 2015 13:01
because I'm not dealing with numbder
numbers*
Hardy Jones
@joneshf
Jun 07 2015 13:06
okay
what operations do you expect numbers and dates to share?
Asaf
@asaf-romano
Jun 07 2015 13:07
I'm using numbers just to simplify things here, in practice, my (current) setup is something like this:
  1. ES6 generator function takes a start-date plus the step argument (e.g Date.now, "1 day")
Hardy Jones
@joneshf
Jun 07 2015 13:10
i think @buzzdecafe 's suggestion is probably the easiest
Asaf
@asaf-romano
Jun 07 2015 13:11
  1. into([], takeWhile(d => { ... checking end-date }), myGeneratorFunction(start, inc))
Hardy Jones
@joneshf
Jun 07 2015 13:12
you should be able to just map over the range you generate.
Asaf
@asaf-romano
Jun 07 2015 13:12
The thing is I don't have the range (it's what I'm trying to generate), so there's nothing I could map over
let me sketch up something with js dates.
Hardy Jones
@joneshf
Jun 07 2015 13:14
var startMoment = ...
var interval = ...
R.map(function(x) { return startMoment.add(x, 'days'); }, interval);
oh
i see
well there's a few ways to go about that
function interval(low, high, step) {
  var stepped = R.pipe(R.modulo(R.__, step), R.eq(0));
  return R.filter(stepped, R.range(low, high));
}
or I think...
function interval(low, high, step) {
  return R.map(R.mulitply(step), R.range(low, high / step));
}
Asaf
@asaf-romano
Jun 07 2015 13:19
thanks, but I cannot use something like R.range :(
my "range" is just two iso strings
start and end
and it should "map" to an array of dates
what you have here is basically a version of R.range that takes a step argument
Hardy Jones
@joneshf
Jun 07 2015 13:20
i think i don't fully understand the problem
Asaf
@asaf-romano
Jun 07 2015 13:20
If i'm reading this correctly.
Hardy Jones
@joneshf
Jun 07 2015 13:21
can you provide some inputs and outputs?
Asaf
@asaf-romano
Jun 07 2015 13:21
sec
I'm having troubles with ES6 generators in the repl
Asaf
@asaf-romano
Jun 07 2015 13:28
look here, and look at the alerts (ignore the output because, apparently, ES6 generators are broken in REPL): http://bit.ly/1ImEkDM
Hardy Jones
@joneshf
Jun 07 2015 13:29
does that work?
for whatever reason I get the same date repeated
but should have worked, I think.
Hardy Jones
@joneshf
Jun 07 2015 13:32
what about this solution isn't what you're looking for?
Asaf
@asaf-romano
Jun 07 2015 13:35
well, first, it doesn't work for whatever reason :-/ The takewhile function gets the right dates, but the collected values are all the same (the last value yielded)
secondly, while(true) is ugly :)
oh, nvm, the first problem is my stupidness
it's the same object after all. I don't clone it
so the only thing I don't like about this is the usage of while, I guess, plus it feels like I'm missing something generic that could be leveraged here.
Hardy Jones
@joneshf
Jun 07 2015 13:42
what would you prefer instead of while?
Asaf
@asaf-romano
Jun 07 2015 14:47
Some infinite stream abstraction I guess.
Michael Hurley
@buzzdecafe
Jun 07 2015 14:54
generateDates is your infinite stream. just so happens to be implemented with a while
Scott Sauyet
@CrossEye
Jun 07 2015 17:53
This message was deleted
This message was deleted
Scott Sauyet
@CrossEye
Jun 07 2015 18:17
@asaf-romano: How about this: http://bit.ly/1FD36w7, using unfold?
Asaf
@asaf-romano
Jun 07 2015 18:48
@CrossEye excellent, thanks!