These are chat archives for ramda/ramda

7th
Dec 2015
boxofrox
@boxofrox
Dec 07 2015 02:57
@ricburton :thumbsup: that's what i'm talking about :smile:. sorry for the late response
Tobias Pflug
@gilligan
Dec 07 2015 07:26
morning folks
Hardy Jones
@joneshf
Dec 07 2015 07:46
@scott-christopher right, but shouldn't the same be true of generators?
Scott Christopher
@scott-christopher
Dec 07 2015 08:49
Perhaps I misunderstand, but the list in your example is just a generator constructor, which produces something with a next method that can be repeatedly called, returning something like { done: Boolean, value: a } until done eventually returns true.
(ignoring generator.throw() and generator.return())
Aldwin Vlasblom
@Avaq
Dec 07 2015 08:57
Anyone happen to be at dotJS Paris today? :)
Hardy Jones
@joneshf
Dec 07 2015 09:44
@scott-christopher Sounds plausible. :) I haven't boned up on the internals of generators.
Hardy Jones
@joneshf
Dec 07 2015 09:49
I just can't really think of a reason for generators to not act Functorially.
Scott Christopher
@scott-christopher
Dec 07 2015 10:31
var R = require('ramda');

const Gen = gen => ({
  map: fn => Gen(function*() {
    const g = gen();
    var next = g.next();
    while (!next.done) {
      yield fn(next.value);
      next = g.next();
    }
  }),
  ap: gA => Gen(gen).chain(fn => gA.map(fn)),
  chain: fn => Gen(function*() {
    const g = gen();
    var next = g.next();
    while (!next.done) {
      yield* fn(next.value).gen();
      next = g.next();
    }
  }),
  gen: gen
});

const list = function*() {
  yield 1;
  yield 2;
  yield 3;
};

const plusMinus = x => Gen(function* () { yield x; yield -x; });

const gMap   = R.map(R.inc, Gen(list));
const gAp    = R.lift(R.add)(Gen(list), Gen(list));
const gChain = R.chain(plusMinus, Gen(list));

console.log([...gMap.gen()]);   // [ 2, 3, 4 ]
console.log([...gAp.gen()]);    // [ 2, 3, 4, 3, 4, 5, 4, 5, 6 ]
console.log([...gChain.gen()]); // [ 1, -1, 2, -2, 3, -3 ]
close enough ;)
Scott Christopher
@scott-christopher
Dec 07 2015 10:47
Tobias Pflug
@gilligan
Dec 07 2015 10:51
best typo of the day R.pope
Craig Dallimore
@craigdallimore
Dec 07 2015 11:49
@gilligan R.pope(R.communionWith)
Tobias Pflug
@gilligan
Dec 07 2015 12:18
@craigdallimore ;-}
Scott Sauyet
@CrossEye
Dec 07 2015 12:57
@scott-christopher: what I'd like to see, though, is the ability to use a generator pretty much any place we'd use a list.
Our long-ago LazyList extension worked something like your code. The trouble with that approach is that you need to add to it every function you want to support. filter, find, take, etc. would all need dedicated code.
Scott Sauyet
@CrossEye
Dec 07 2015 13:04
I'd prefer to have some generic way to loop and simply declare caveat emptor for cases where a user did something crazy like trying to zip an infinite generator with a finite list.
But to do this would probably involve rewriting every list function to handle a more abstract notion of itrtation. It's certainly possible, and write likely worth doing, but it's a big job.
Scott Sauyet
@CrossEye
Dec 07 2015 13:11
If we were supporting es6 only, I'd happily replace our while loops with for-of ones and be done with it. But I don't see anything so convenient at the moment.
Keith Alexander
@kwijibo
Dec 07 2015 13:18
would using babel to transpile down, relinquish too much control over the "actual" javascript?
Scott Sauyet
@CrossEye
Dec 07 2015 13:53
I'm not sure. I'd like to see how well it might work.
Tobias Pflug
@gilligan
Dec 07 2015 15:28
i'm quite happy with babel for my projects at work at least
Scott Sauyet
@CrossEye
Dec 07 2015 15:32
I'm very happy with Babel for creating working code. The question, though, is how readable us the code it generates?
@CrossEye not exactly beautiful ;-)
Hardy Jones
@joneshf
Dec 07 2015 16:59
@scott-christopher I don't think chain is right there.
Stefano Vozza
@svozza
Dec 07 2015 17:00
the babel transpilation for for...of loops is quite ugly looking but other than that it's fine especially when the code is as vanillajs heavy as ramda is.
Hardy Jones
@joneshf
Dec 07 2015 17:22
@CrossEye that's precisely what Traversable gives you. The ability to write the vast majority of iterations once and forall. If a data type has traverse, you can implement almost all of what ramda provides for arrays.
speaking ofbabel
it's kind of become the defacto for compiling js as of late
but its documentation is pretty much non-existent.
What other options are there for compiling js that have halfway decent documentation?
Tobias Pflug
@gilligan
Dec 07 2015 17:37
I don't think that there is any worthwhile alternative
Well at least not that I know. Babel has a ton of support
Scott Sauyet
@CrossEye
Dec 07 2015 18:41
@joneshf: of course, Iterable is similar, with some advantage of language support.
Tobias Pflug
@gilligan
Dec 07 2015 19:54
evening
Scott Christopher
@scott-christopher
Dec 07 2015 20:53
@joneshf What looks off about it? It seems to satisfy the monad laws: https://gist.github.com/scott-christopher/4f9ff47fee00feca88d3#file-tests-js
Brian Gates
@brian-gates
Dec 07 2015 21:56
var log = function(){ console.log(arguments); };

var test = R.nAry(2, R.tap(log));

test(1,2); // expected { '0': 1, '1': 2 } got { '0': 1 }
what am I doing wrong here?
David Chambers
@davidchambers
Dec 07 2015 21:59
@brian-gates, what's your high-level objective?
Brian Gates
@brian-gates
Dec 07 2015 22:01
accept two params and call those into a function as an array
basically exactly my example up there
test(1,2) -> log([1, 2])
This message was deleted
David Chambers
@davidchambers
Dec 07 2015 22:10
var test = R.apply(log); might be what you're after.
Brian Gates
@brian-gates
Dec 07 2015 22:10
the opposite, I think
I want to convert the arguments into an array, not the other way around
but
unapply doesn't seem to do what I want either
jk it does.
I swear I tested that
my example was terrible, sorry
var log = function(){ console.log(arguments); };

var test = R.unapply(log);

test(1,2);// { '0': [ 1, 2 ] }
that's what I was going after, I'm too tired apparently
thanks :)
Fulton Byrne
@Freyert
Dec 07 2015 22:13
Anyone have any recommendations for writing documentation?
David Chambers
@davidchambers
Dec 07 2015 22:25
API documentation do you mean, @Freyert?
Fulton Byrne
@Freyert
Dec 07 2015 22:25
Correct
David Chambers
@davidchambers
Dec 07 2015 22:25
I'm pleased you got something working, @brian-gates.
Fulton Byrne
@Freyert
Dec 07 2015 22:25
For instance, what is Ramda using, and would you prefer something else?
David Chambers
@davidchambers
Dec 07 2015 22:25
I prefer Transcribe, but I'm biased. ;)
Fulton Byrne
@Freyert
Dec 07 2015 22:26
That's actually what I was looking for haha
Where can I see some examples?
I love the terseness of the markdown
David Chambers
@davidchambers
Dec 07 2015 22:27
Here's a nice example.
Fulton Byrne
@Freyert
Dec 07 2015 22:27
Actual output as well?
so simple to read
Holy cow
I need to go home and read through this source code
David Chambers
@davidchambers
Dec 07 2015 22:28
The output is README.md.
Fulton Byrne
@Freyert
Dec 07 2015 22:28
And then you can mark it down however you like
I see
I'm trying to come up with a good strategy for internal documentation.
Something we could host locally
And would be searchable, and categorized
David Chambers
@davidchambers
Dec 07 2015 22:30
Ah, that sounds broader in scope than Transcribe. I don't have a recommendation for you, in that case.
Fulton Byrne
@Freyert
Dec 07 2015 22:30
How do you use Transcribe yourself? Do you just CTRL+F?
David Chambers
@davidchambers
Dec 07 2015 23:02
When I want to read the documentation for a given function, do you mean?
Fulton Byrne
@Freyert
Dec 07 2015 23:52
Yes haha sorry
zoned out