These are chat archives for ramda/ramda

4th
Dec 2015
Martin Algesten
@algesten
Dec 04 2015 01:52
folktale about page hello world example is hilarious. if you're fp curious and end up there, you'd be running away screaming.
Scott Sauyet
@CrossEye
Dec 04 2015 04:09

@joneshf: Sorry for the late reply. I just got a chance to look at this. I'm not sure I understand what difficulty you see.

I can't tell if you mean "stream" here in a fairly generic way, as just a sequential collection of elements, of if you had somthing more precise in mind. I am proceding under the assumption that you could use an extremely simply stream implementation, with just push to add an element, onEach to listen for new elements, and map to create a new stream by mapping a function over this one.

With that, I think I can answer the question. It seems fairly simple, which makes me wonder if I'm misunderstanding your requirements:

const averager = () => {
  let count = 0;
  let total = 0;
  return obj => {
    count += 1;
    total += obj.val;
    return R.assoc('avg', total / count, obj);
  };
};

const s1 = stream();
const s2 = s1.map(averager());
s2.onEach(console.log);

s1.push({name: 'a', val: 8}); // logs { name: "a", val: 8, avg: 8 }
s1.push({name: 'b', val: 6}); // logs { name: "b", val: 6, avg: 7 }
s1.push({name: 'c', val: 7}); // logs { name: "c", val: 7, avg: 7 }
s1.push({name: 'd', val: 5}); // logs { name: "d", val: 5, avg: 6.5 }
s1.push({name: 'e', val: 3}); // logs { name: "e", val: 3, avg: 5.8 }
s1.push({name: 'f', val: 0}); // logs { name: "f", val: 0, avg: 4.833333333333333 }
s1.push({name: 'g', val: 9}); // logs { name: "g", val: 9, avg: 5.428571428571429 }

So are you looking for something different? (You can see a version of this in the REPL.

Raine Virta
@raine
Dec 04 2015 08:02
algesten: where is that? about page
Tobias Pflug
@gilligan
Dec 04 2015 08:04
Well it looks nice, the content is imho at least questionable at times- in general: why the heck use greek letters for the type signatures?
Its like, it does all look quite polished but nobody who is not already into FP would want to read anything on that website
I am convinced that my colleagues at work who already have problems with some of the more ctryptic signatures of ramda will show me the finger if i led them to folktale
Tobias Pflug
@gilligan
Dec 04 2015 09:43
do any folktale authors/contributors hang out here by the way ?
Raine Virta
@raine
Dec 04 2015 09:44
i think folktale stuff is written exclusively by sorella
Keith Alexander
@kwijibo
Dec 04 2015 10:11
The intro to the folktale book looks really promising http://docs.folktalejs.org/en/latest/book/index.html#table-of-contents
Ricardo Pallas
@RPallas92
Dec 04 2015 10:19
yes, but it's almost empty
Keith Alexander
@kwijibo
Dec 04 2015 10:42
which is a shame
Constantin Dumitrescu
@dumconstantin
Dec 04 2015 11:59
hi guys, this might be a side topic, but I made a Flow interface for Ramda based on the typescript version (its not tested yet, but Flow seems to like it :) )
https://gist.github.com/dumconstantin/c73effc8cede95f9b1cb
Scott Sauyet
@CrossEye
Dec 04 2015 13:06
@dumconstantin: perfectly on-topic, although, since I've never even played with Flow, I'm personally not competent to comment except to note that, "Wow, that's a lot of signatures! " :smile:
Tobias Pflug
@gilligan
Dec 04 2015 13:09
@dumconstantin does it handle currying ?
one of the reasons i gave up on flow (apart from the fact that i don't like the type system and the ugly signatures) was that i didn't see how efficiently describing curried functions would be possible
Eric Gjertsen
@ericgj
Dec 04 2015 13:30
re folktale, I can't speak for the author, but I am fairly sure it represents many hours of unpaid labor on their part. I would really hesitate to criticize it for being hard to understand or incomplete.
Especially when it has some of the most solid JS implementations of various monads out there, and the author has written a number of tutorials which are extremely good.
I am new to FP and I did not find the documentation off-putting, in fact quite the opposite.
Scott Sauyet
@CrossEye
Dec 04 2015 13:36
@ericgj: I only half-agree. The library is absolute gold. And its documentation is certainly no worse than Ramda-fantasy. But most open source is a labor of love. Generally the way it improves is for people to find something to criticize, then take it on themselves to fix it. The criticism is a necessary part in my mind.
Eric Gjertsen
@ericgj
Dec 04 2015 13:39
of course, but surely you have to take into account that this is a one person project with very little visibility
Scott Sauyet
@CrossEye
Dec 04 2015 13:42
My thought though is that if these critiques prompt people to offer sorella some documentation pull requests, they mostly do good.
The only reason Ramda's manual is not subject to similar criticism is that we haven't published anything about it. It's pretty much stalled, and u think I'm the only one who's written anything for it yet. It's honestly pathetic at this point.
Eric Gjertsen
@ericgj
Dec 04 2015 13:44
I didn't see anyone offering to do that, which is part of what seemed unbalanced
Scott Sauyet
@CrossEye
Dec 04 2015 13:48
Perhaps. But I think the critique necessarily comes first.
Eric Gjertsen
@ericgj
Dec 04 2015 13:52
well there's constructive critique and there's pot-shots...
anyway, there is a gitter channel for folktale which occasionally I've seen sorella on - https://gitter.im/folktale/discussion. I think there may be an IRC channel too.
Scott Sauyet
@CrossEye
Dec 04 2015 13:55
I think there is IRC. Gitter is moribund.
Tobias Pflug
@gilligan
Dec 04 2015 13:59
i don't see how i am not allowed to give critique on a project merely because it is a F/OSS project
would it be OK if it was a commercial library ?
If I tell someone to use data.task the first contact will be :
type Task(α, β)

new ((α → Unit), (β → Unit) → γ), (γ → Unit)

implements
  Chain(β), Monad(β), Functor(β), Applicative(β),
  Semigroup(β), Monoid(β), ToString
Denis Stoyanov
@xgrommx
Dec 04 2015 14:04
@gilligan :worried:
Tobias Pflug
@gilligan
Dec 04 2015 14:04
you don't honestly want to tell me that this is not utterly excluding anyone who has not previously concerned himself with FP and category theory
Eric Gjertsen
@ericgj
Dec 04 2015 14:06
the way I understood that, as a FP newbie, is that it's documentation that I don't understand yet, that may be helpful in the future when I understand the concepts better
I don't think folktale has quite the same approach as ramda in terms of "gradualism", it's been discussed here before there are different approaches.
I can't count the number of times I've tried to get started in purescript and failed
It doesn't work for me (yet), but I don't blame the documentation, which I can tell is quite good
Tobias Pflug
@gilligan
Dec 04 2015 14:12
there is basically no documentation but only type signatures which are good for those that already know what they are about. I can parse/understand the documentation. My colleagues at work certainly can't. That basically reduces the possibility of me introducing it to my team
Well that is likely because the purescript documentation is lacking and not because you are stupid
Hardy Jones
@joneshf
Dec 04 2015 14:17
@gilligan where are you looking where you are not finding any documentation?
Tobias Pflug
@gilligan
Dec 04 2015 14:18
what i am trying to communicate is that to "a javascript developer" @Task(α, β) => Task(α, β) → Task(α, β) is not documentation
Hardy Jones
@joneshf
Dec 04 2015 14:19
is Selects the earlier of two Tasks. documentation to "a javascript developer"?
Tobias Pflug
@gilligan
Dec 04 2015 14:21
maybe, does not make sense to me at least.
especially considering that it belongs to concat i actually am not sure how that makes sense
what i am saying is "documenting your library with a lot of assumed prior knowledge is imho problematic. the folktale documentation can be hard to grasp" - what you are saying is "nope its fine"
i guess
Hardy Jones
@joneshf
Dec 04 2015 14:24
that's not what i'm saying at all.
I don't believe it's fine documentation.
Tobias Pflug
@gilligan
Dec 04 2015 14:24
sorry, i meant @ericgj
in that case
@joneshf i'm doing too many things at once - sorry ;)
Hardy Jones
@joneshf
Dec 04 2015 14:25
no worries
Raine Virta
@raine
Dec 04 2015 14:26
gilligan: i completely see what you're saying
Tobias Pflug
@gilligan
Dec 04 2015 14:26
I watched that video on youtube from DrBoolean yesterday which was great. That inspired me to have a look at some of the cool projects such as folktale/daggy/etc
Raine Virta
@raine
Dec 04 2015 14:26
which video was that?
@raine ah sorry, i assumed it had made it to here already. it's quite lovely (apart from the very annoying voice-over. I actually watched it at 0.5x speed which was much better)
@raine @joneshf So I think the difficult part is to keep a balance between not compromising the theoretical soundness that you are likely aiming for in your FP project while at the same time not alienating people that are interested but have no idea what Foldable or Catamorphism means
Eric Gjertsen
@ericgj
Dec 04 2015 15:24
@gilligan I think there's a lot of room for improvement of the folktale documentation, sure. But it maybe you missed all that's there -- some of the UI is a bit clever on that site.
Tobias Pflug
@gilligan
Dec 04 2015 15:25
believe me it is not the amount, it is the wording
Eric Gjertsen
@ericgj
Dec 04 2015 15:25
and Task documentation is a bit sparser than Either for instance
have you seen the author's blog posts? http://robotlolita.me/
Two of them are like guide-style documentation of Task and Maybe/Either/Validation
Tobias Pflug
@gilligan
Dec 04 2015 15:32
nice, but has nothing to do with the folktale documentation hehe
but yes - i realized she has a nice blog with interesting topics
Denis Stoyanov
@xgrommx
Dec 04 2015 15:34
Tobias Pflug
@gilligan
Dec 04 2015 15:35
@xgrommx nice one!
Eric Gjertsen
@ericgj
Dec 04 2015 15:37
my only point is those serve as quite good folktale documentation in the absence of the "getting started"
you might see what you/your team think of them reading through them. They definitely got me inspired to start using the library.
Arve Knudsen
@aknuds1
Dec 04 2015 16:34
I love Ramda, that is all
Scott Sauyet
@CrossEye
Dec 04 2015 16:36
Ramda loves you too.
Arve Knudsen
@aknuds1
Dec 04 2015 16:36
Aww
Tobias Pflug
@gilligan
Dec 04 2015 16:44
:heart:
:ram: :heart:
Stefano Vozza
@svozza
Dec 04 2015 16:54
i love lamp
Constantin Dumitrescu
@dumconstantin
Dec 04 2015 17:55
@gilligan, regarding the flow interface, haven't tested yet with curry (will soon and let you know), but I thought that defining all the possible combinations for functions and arguments would do the trick:
declare function divide(a: number, b: number): number;
declare function divide(a: number): (b: number) => number;
declare function divide(a: placeholder, b: number): (b: number) => number;
Brian Gates
@brian-gates
Dec 04 2015 21:30
[1,2,3] --> [[1,2], [2,3], [3,4]] how?
Brian Gates
@brian-gates
Dec 04 2015 21:31
<3
Brian Gates
@brian-gates
Dec 04 2015 21:47
do('a', ['b', 'c']) --> ['a', 'b', 'c'] what do?
I want to do R.of, then concat/flatten all arguments
I imagine
> R.pipe(R.of, R.concat)('a', ['b', 'c'])
[Function]
I'm guessing this is because it's only effectively running R.concat(R.of('a'))
need to extract the arguments as an array first
or something
somehow get at the second arg
Brian Gates
@brian-gates
Dec 04 2015 21:53
maybe pipe isn't the right call here.
Scott Sauyet
@CrossEye
Dec 04 2015 22:00
R.pipe(R.unapply(R.map(R.of)), R.flatten)
Brian Gates
@brian-gates
Dec 04 2015 22:00
var args = ['a', ['b', 'c']];
var test = R.pipe(R.pair, R.flatten);

test.apply(null, args);
Scott Sauyet
@CrossEye
Dec 04 2015 22:00
Maybe. Can't test on my phone.
Brian Gates
@brian-gates
Dec 04 2015 22:00
> var args = ['a', ['b', 'c']];
undefined
> var test = R.pipe(R.pair, R.flatten);
undefined
> 
> test.apply(null, args);
[ 'a', 'b', 'c' ]
seems to get the end result I desire
I think I like unapply better though
minus the not-working side
> var args = ['a', ['b', 'c']];
undefined
> var test = R.pipe(R.unapply, R.flatten);
undefined
> 
> test.apply(null, args);
[]
pair is sufficient though
Scott Sauyet
@CrossEye
Dec 04 2015 22:04
Ok. I can test: http://bit.ly/1N8Ylye
Brian Gates
@brian-gates
Dec 04 2015 22:13
['a', 'b,c'] --> [['a', 'b'], ['a', 'c']]
could map a split by comma
then what?
[ [ 'a' ], [ 'b', 'c' ] ] -> [['a', 'b'], ['a', 'c']]
is what I need
xprod looks like a good candidate
Brian Gates
@brian-gates
Dec 04 2015 22:24
success!
var array = ['a', 'b,c'];

var test = R.pipe(R.map(R.split(',')), R.apply(R.xprod));

test(array); // goal: [['a', 'b'], ['a', 'c']]
Brian Gates
@brian-gates
Dec 04 2015 23:20
var input = ['a', 'b,c.d'];
var expected = [['a', 'b'], ['a', 'c'], ['c', 'd']];
trying to build a 'graph' if you will
as specified by dot/comma separated relationship paths
Brian Gates
@brian-gates
Dec 04 2015 23:49
      it('test', () => {
        var inflection  = require('inflection');
        var input    = ['rolls', 'captures,scenes.archives'];
        var expected = [['roll', 'capture'], ['roll', 'scene'], ['scene', 'archive']];
        var test = R.pipe(
          R.over(
            R.lensIndex(1),
            R.pipe(
              R.split(','),
              R.map(R.split('.')),
              R.map(R.map(inflection.singularize))
            )
          ),
          R.over(
            R.lensIndex(0),
            R.pipe(inflection.singularize, R.of)
          ),
          R.apply(R.xprod),
          R.map(R.flatten),
          R.map(R.aperture(2)),
          R.unnest,
          R.uniq
        );
        test(input).should.eql(expected);
      });
if there's any cleaner way to do this, love to hear it :)