These are chat archives for ramda/ramda

24th
Jun 2015
Scott Sauyet
@CrossEye
Jun 24 2015 01:29
I don't fully understand the transducers stuff myself, so I may be no help. But you seem to be missing Identity.prototype.map.
Did you want something like this?
Identity.prototype.map = function(fn) {
  return Identity(fn(this.runIdentity()));
};
Scott Christopher
@scott-christopher
Jun 24 2015 01:33
From what I understand (which isn’t a lot when it comes to transducers), you shouldn’t have to define map if you’ve defined init, step and result, because R.map will dispatch to internal/_xmap.js.
Scott Sauyet
@CrossEye
Jun 24 2015 01:39
Well, clearly you understand more than I do. If so, then something's broken, as neither of those final lines works at all.
Hardy Jones
@joneshf
Jun 24 2015 01:46
yeah, that was a snippet, map's in there in the actual code.
so yeah, the regular R.map works
but it doesn't seem to do what I'd expect it to do.
Scott Sauyet
@CrossEye
Jun 24 2015 01:47
Is this in a Gist somewhere?
Hardy Jones
@joneshf
Jun 24 2015 01:47
if i dump a bunch of logs in there it's applying the function to the initial value
one sec
Scott Sauyet
@CrossEye
Jun 24 2015 01:49
So it's the into that's failing?
Hardy Jones
@joneshf
Jun 24 2015 01:50
well, I dunno
I don't get the protocol at all.
Scott Sauyet
@CrossEye
Jun 24 2015 01:50
Have you read the tranducers articles? I need to go back to them. Just after reading them, I really feel I understand it all! :-)
Scott Christopher
@scott-christopher
Jun 24 2015 01:52
Wouldn’t Identity require a reference to the next transducer in the chain?
Hardy Jones
@joneshf
Jun 24 2015 01:52
Yeah that's foggy for me too. For me, the words make things less clear than just having some type signatures.
Scott Sauyet
@CrossEye
Jun 24 2015 01:54
One of the things I remember from when the Clojure folks first started introducing transducers was how confused all the Haskell folks were by the signatures. I think the very notion has somehow not been considered very useful for Haskell.
... or that.
Scott Christopher
@scott-christopher
Jun 24 2015 01:55
Do they perhaps translate to composition of profunctors?
Hardy Jones
@joneshf
Jun 24 2015 01:58
probably, I remember people saying they're a simpler version of some of the data types from folds, foldl, and lens.
my problem is that the protocol doesn't really explain rigorously enough what each function does.
at least, not rigorously enough for me
:point_up: June 23, 2015 6:52 PM what does this mean?
Hardy Jones
@joneshf
Jun 24 2015 02:08
Oh, something is messing things up
looks like since I also defined iterator it's not playing nicely.
Scott Christopher
@scott-christopher
Jun 24 2015 02:21
If a transformer is intended to be composed with other transformers they should either close over the next transformer or store it in a field.
var Map = function(f, xf) {
    return {
       "@@transducer/init": function() { 
           return xf["@@transducer/init"](); 
       },
       "@@transducer/result": function(result) { 
           return xf["@@transducer/result"](result); 
       },
       "@@transducer/step": function(result, input) {
           return xf["@@transducer/step"](result, f(input)); 
       }
    };
};
note the next transformer xf is a parameter of Map
Hardy Jones
@joneshf
Jun 24 2015 02:23
So does that mean I have to change the way I construct Identity?
Scott Christopher
@scott-christopher
Jun 24 2015 02:24
¯_(ツ)_/¯
I think an Identity transducer would just be the identity function itself.
Scott Christopher
@scott-christopher
Jun 24 2015 02:29
Transducers are simply a function of one arity. The only argument is another transducer transformer (labeled xf in the code base)
So their map example is:
var map = function map(f) {
    return function mapTransducer(xf) {
        return Map(f, xf);
    };
};
Hardy Jones
@joneshf
Jun 24 2015 02:31
Jethro Larson
@jethrolarson
Jun 24 2015 02:51
So we have an implementation of transducers in ramda but none of us really understand them
Scott Christopher
@scott-christopher
Jun 24 2015 02:54
Other folks here have a good understanding. I’m just poking at them trying to understand a little better.
Scott Sauyet
@CrossEye
Jun 24 2015 02:58
@kevinbeaty, @buzzdecafe, @kedashoe all seemed to have very strong grips on it. I seem to get a strong grip that fades pretty quickly, I'm afraid.
David Chambers
@davidchambers
Jun 24 2015 03:55
I have no idea yet! I do now have an idea of how lenses work, which is something.
The "point up" links in Gitter don't work for me in iOS. Anyone else have the same issue?
Scott Christopher
@scott-christopher
Jun 24 2015 03:59
A number of things frustrate me using gitter on ios
Kevin Wallace
@kedashoe
Jun 24 2015 04:34
it does appear to be possible to create an identity transducer in ramda
it basically amounts to R.map(R.Identity)
I liked this article when I was first reading about transducers http://phuu.net/2014/08/31/csp-and-transducers.html
Kevin Wallace
@kedashoe
Jun 24 2015 04:43
if you want to read some source code to better understand them, i do think cognitect's implementation is the most straightforward (definitely not ramda's, haha)
@kevinbeaty wrote most of ramda's, he also has his own library: https://github.com/transduce/transduce
Kevin Wallace
@kedashoe
Jun 24 2015 04:49
to be more explicit, this line https://github.com/kedashoe/ramda/blob/xf-identity/src/internal/_xidentity.js#L14 could also be written return this.xf['@@transducer/step'](result, R.identity(input));
Hardy Jones
@joneshf
Jun 24 2015 06:04
@kedashoe any tips where i went wrong with my implementation?
Hardy Jones
@joneshf
Jun 24 2015 06:11
oh, apparently i have even more clashes causing issues.
Hardy Jones
@joneshf
Jun 24 2015 06:27
Things get more interesting.
It'll fail for ramda and transducers.js without the iterator spec being implemented
fail as in throw an exception.
But for transducers-js it's always Identity(0).
So I think there's something i'm missing here.
Hardy Jones
@joneshf
Jun 24 2015 06:33
If the iterator spec is implemented, then ramda and transducers.js both return Identity(3).
Scott Christopher
@scott-christopher
Jun 24 2015 06:59
The iterator is allowing into to reduce over your Identity (inside internal/_reduce.
var i0 = Identity(0);
console.log('%s', into(i0, map(add(1)), [5])); // Identity(6)
Hardy Jones
@joneshf
Jun 24 2015 07:19
Do I have a bad version of something? I don't get Identity(6) with that example.
transducer@1.0.0 /home/joneshf/programming/javascript/transducer
├── ramda@0.15.1 extraneous
├── transducers-js@0.4.174 extraneous
└── transducers.js@0.3.2 extraneous
Scott Christopher
@scott-christopher
Jun 24 2015 07:20
'use strict';

var add  = require('./src/add');
var into = require('./src/into');
var map  = require('./src/map');

function Identity(x) {
  if (!(this instanceof Identity)) {
    return new Identity(x);
  };

  this.runIdentity = function() {
    return x;
  };
}

Identity.prototype.toString = function() {
  return 'Identity(' + this.runIdentity().toString() + ')';
};

Identity.prototype['@@transducer/init'] = function() {
  return this;
};

Identity.prototype['@@transducer/result'] = function(x) {
  return x;
};

Identity.prototype['@@transducer/step'] = function(x, y) {
  return Identity(y);
};

// The following two lines fail if the iterator spec is not implemented.
var i0 = Identity(0);
console.log('%s', into(i0, map(add(1)), [5, 6]));
where add, into and map are the plain ol’ Ramda functions
(I removed the iterator function)
Hardy Jones
@joneshf
Jun 24 2015 07:25
What the heck?
console.log('%s', into(i0, map(add(1)), Identity(6))); //=> Identity(7);
Scott Christopher
@scott-christopher
Jun 24 2015 07:26
… ignore the following two lines comment in my copy/paste
Hardy Jones
@joneshf
Jun 24 2015 07:27
after adding the iterator back
Scott Christopher
@scott-christopher
Jun 24 2015 07:27
yeah, I removed it because I couldn’t be bothered getting the generator to run with Node
Hardy Jones
@joneshf
Jun 24 2015 07:27
oh, it's map that breaks things?
i'm super confused now.
i just use node --harmony identity.js, btw.
Scott Christopher
@scott-christopher
Jun 24 2015 07:30
For me, if I removed the iterator method from your Identity, while passing an Identity in the list position of into, it would fail because it didn’t know how to reduce over it.
Hardy Jones
@joneshf
Jun 24 2015 07:30
yeah
Asaf
@asaf-romano
Jun 24 2015 09:32
For whatever reason I find this amusing: http://bit.ly/1NhS84i
I guess sugar isn't always bad!
Raine Virta
@raine
Jun 24 2015 09:33
point free is the way to go!
Asaf
@asaf-romano
Jun 24 2015 09:36
the es6-way there is a very repetitive pattern in our code (after toPairs); my coworker was wondering if there's no "ramda way" to get the same effect, so I took the challenge :)
Raine Virta
@raine
Jun 24 2015 09:36
should do point free golf, puzzles where only rule is to never use lambdas
asaf-romano @asaf-romano notes to self to add pairToObject to the cookbook
Asaf
@asaf-romano
Jun 24 2015 09:49
heh, I could just zip
zipObj that is
Kevin Wallace
@kedashoe
Jun 24 2015 17:06
@joneshf i think maybe using into is complicating things
to me it is unclear if the type of the first argument to into is ever properly explained
as i understand it, that first argument is a "terminating" transformer, that is, its step function does not call step
it is fundamentally different from a "composable" transformer, for example xmap: https://github.com/ramda/ramda/blob/master/src/internal/_xmap.js#L13
xmap calls the ['@@transducer/step'] of xf, so you can compose it with other transducers
on the other hand, you can see the intoable, "terminating" transformers in ramda in internal/_stepCat.js, for example: https://github.com/ramda/ramda/blob/master/src/internal/_stepCat.js#L13
you can also see an ad hoc one in a ramda test here: https://github.com/ramda/ramda/blob/master/test/into.js#L9
so what you have defined looks to me like a terminating transformer, as your step does not reference step of xf
however you are using it as both types of transformer: into(i0, map(add(1)), Identity(6))
it actually seemed like @tgriesser was asking about the intoable type here cognitect-labs/transducers-js#20 but i was too cowardly to speak up :/
Hardy Jones
@joneshf
Jun 24 2015 17:09
Alright, I'll buy that.
So what would be a better function to start with?
Kevin Wallace
@kedashoe
Jun 24 2015 17:11
well, i probably didn't phrase that well, into is as good a place to start as any.. the question maybe is if you want this identity to be something you can transduce into, or if you want it to be a transformer that can be part of a composition
Hardy Jones
@joneshf
Jun 24 2015 17:12
okay.
how would I make that sort of decision?
what about my object would lead me down one path versus the other?
Kevin Wallace
@kedashoe
Jun 24 2015 17:15
did you have something you wanted to accomplish with identity? or basically just trying to explore transducers with something that seemed like it might be a simple starting point?
Hardy Jones
@joneshf
Jun 24 2015 17:15
exploration
Kevin Wallace
@kedashoe
Jun 24 2015 17:18
i think about that first argument to into as a collection, so to me it makes more sense to define identity (..if using identity in a transducer context makes sense) not as a collection but as a transformer (which just doesn't do any transformation)
Hardy Jones
@joneshf
Jun 24 2015 17:22
Okay, so what would change in the implementation then?
would it have to take the next transformation as an argument?
or is that what the value in Identity would be?
Kevin Wallace
@kedashoe
Jun 24 2015 17:26
my stab at the transformer version is what i pushed here https://github.com/kedashoe/ramda/blob/xf-identity/src/internal/_xidentity.js
so xmap takes a function and returns a transducer, eg map(inc)
my take on xidentity was to just take no argument and return a transducer
(doing this in ramda is more complicated because of currying/dispatching)
Kevin Wallace
@kedashoe
Jun 24 2015 17:33
here is map vs identity using cognitect's source: https://www.diffchecker.com/jxaf3zgo
Hardy Jones
@joneshf
Jun 24 2015 17:33
okay that identity transformer makes sense
Kevin Wallace
@kedashoe
Jun 24 2015 17:34
(f is not used and will simply be undefined)
Hardy Jones
@joneshf
Jun 24 2015 17:36
what's the point of f btw?
Kevin Wallace
@kedashoe
Jun 24 2015 17:36
in identity or in tranducers in general?
it doesn't seem to be used anywhere
is someone down the road expecting it?
Kevin Wallace
@kedashoe
Jun 24 2015 17:38
no, you are correct, there is no point :)
Hardy Jones
@joneshf
Jun 24 2015 17:38
oh, okay
So I think I get the transformer idea.
what about viewing Identity as a collection?
Kevin Wallace
@kedashoe
Jun 24 2015 17:38
(i just copied the source from another xf and put null there)
Hardy Jones
@joneshf
Jun 24 2015 17:39
:)
Kevin Wallace
@kedashoe
Jun 24 2015 17:40
so, just thinking outloud, when viewed as a collection, it might be more problematic
because transducers deal with a series of values, right? arrays, streams, etc
Hardy Jones
@joneshf
Jun 24 2015 17:42
I'd like to think of Identity as a collection with exactly one value.
Kevin Wallace
@kedashoe
Jun 24 2015 17:42
ok so what would be the result ofinto(R.xidentity, R.map(inc), [1, 2, 3])
Hardy Jones
@joneshf
Jun 24 2015 17:42
like how Tuple is a collection with exactly two values.
or Maybe is a collection with either no values or exactly on value.
that should be either Identity(2) or Identity(4).
depending on how it's eimplemented.
either favoring the first value or the last.
i'd expect anyway
Kevin Wallace
@kedashoe
Jun 24 2015 17:44
ok, i think identity(4) will be easier so lets try that first
Hardy Jones
@joneshf
Jun 24 2015 17:44
my implementation appears to favor the last value.
Kevin Wallace
@kedashoe
Jun 24 2015 17:47
var iXf = {
    '@@transducer/step': R.nthArg(1),
    '@@transducer/init': R.identity,
    '@@transducer/result': R.identity
};

var inc = function(x) { return x + 1 };
    it('ixf', function(){
    console.log('into?', R.into(iXf, R.map(inc), [1, 2, 3]));
});
i threw that in test/into.js and ran it and got back into? 4
to get 2, you can do
var ifirstXf = {
    '@@transducer/step': R.once(R.nthArg(1)),
    '@@transducer/init': R.identity,
    '@@transducer/result': R.identity
};
Hardy Jones
@joneshf
Jun 24 2015 17:54
So the last argument of into can't be Identity?
Kevin Wallace
@kedashoe
Jun 24 2015 17:59
i guess if it is an iterator it could be?
Hardy Jones
@joneshf
Jun 24 2015 18:02
So is that's what is missing from the spec?
Kevin Wallace
@kedashoe
Jun 24 2015 18:04
Hardy Jones
@joneshf
Jun 24 2015 18:19
this spec really needs a good deal more fleshing out
Hardy Jones
@joneshf
Jun 24 2015 18:40
@kedashoe thanks for the help though. I sort of understand it a bit more.
Vladimir Starkov
@iamstarkov
Jun 24 2015 21:27
hi all
thanks for great lib
i frequently developing offline so i’m using readme in node_modules as API docs, but ramda doesnt have it. it makes me kinda sad
David Chambers
@davidchambers
Jun 24 2015 21:49
@iamstarkov, which platform do you develop on?
I hear Dash is a pretty nice way to access documentation offline for those on OS X.
David Chambers
@davidchambers
Jun 24 2015 21:58
Funny problem: Is there a nice way in Ramda to make a list of N placeholders?
[R.__, R.__, R.__, R.__, R.__]
This does not work, of course:
R.repeat(R.__, n)
Vladimir Starkov
@iamstarkov
Jun 24 2015 22:01
@davidchambers OS X, but dash is paid software
David Chambers
@davidchambers
Jun 24 2015 22:02
Would you like to see all the functions documented in the README?
Vladimir Starkov
@iamstarkov
Jun 24 2015 22:02
maybe not in readme
but yes in repo
also one of solution is to add offline support to ramda docs
David Chambers
@davidchambers
Jun 24 2015 22:03
Oh, that’s a good idea!
Vladimir Starkov
@iamstarkov
Jun 24 2015 22:03
☺️
David Chambers
@davidchambers
Jun 24 2015 22:03
Vladimir Starkov
@iamstarkov
Jun 24 2015 22:04
✔︎ done ramda/ramda.github.io#16
David Chambers
@davidchambers
Jun 24 2015 22:04
Thanks!
Solved the placeholder puzzle!
R.times(() => R.__, n)
Raine Virta
@raine
Jun 24 2015 22:11
iamstarkov: perhaps you could build a local copy of ramda docs
git clone git@github.com:ramda/ramda.github.io.git
cd ramda.github.io
npm install
grunt docs
open out/docs/index.html
Vladimir Starkov
@iamstarkov
Jun 24 2015 23:36
@raine the problem is that I don’t need it everytime. But when I need it im offline, so git clone and obviously npm i are not option for me
basically docs in readme in most npm packages are helpful
but ramda has no docs in readme