These are chat archives for ramda/ramda

10th
Jun 2016
Bravi
@Bravilogy
Jun 10 2016 12:05
anyone alive in here?
Brad Compton (he/him)
@Bradcomp
Jun 10 2016 14:48
@Bravilogy yes :)
Bravi
@Bravilogy
Jun 10 2016 14:54
@Bradcomp Hi Brad. I remember you from somewhere :D hmm.. AmpersandJS gitter chat?
Brad Compton (he/him)
@Bradcomp
Jun 10 2016 14:54
Probably!
Bravi
@Bravilogy
Jun 10 2016 14:56
I just wanted to ask if there are any good video tutorials to follow for ramda? The documentation is huuuge :D I'm going though it, but would be awesome to see some working examples
Brad Compton (he/him)
@Bradcomp
Jun 10 2016 15:01
I don't know about video tutorials, but there are a number of good resources. The wiki lists a bunch of them : https://github.com/ramda/ramda/wiki
I like the Favoring Curry article, though it might be out of date with respect to some of the functions.
Raine Virta
@raine
Jun 10 2016 15:06
:curry:
Brad Compton (he/him)
@Bradcomp
Jun 10 2016 15:07
:sheep:
Andreas Møller
@cullophid
Jun 10 2016 15:59
@Bravilogy I think the best way is to start learning about functional programming in general.
I recommend (https://drboolean.gitbooks.io/mostly-adequate-guide/content/).
Ramda is quite large, and some of the functions are way more commonly used than others
curry, map, filter, reduce and compose will get you very far.
I use pick pluck and path a lot as well
LeonineKing1199
@LeonineKing1199
Jun 10 2016 16:09
That book is pretty good.
Brad Compton (he/him)
@Bradcomp
Jun 10 2016 16:09
Agreed, the mostly adequate guide is great
Bravi
@Bravilogy
Jun 10 2016 16:10
I'm not completely new, I've been using ramda for a while
It's just too much yeah :D
I use prop, propEq, where, whereEq, gt, gl, pipe, filter, reject, map, has, hasIn, reduce, match, test
a lot. But there are so many other useful functions in there
sometimes I want to record screencasts for ramda
especially when I refactor a crazy complex nested loops from some legacy code
and re-write it in just a few readable lines of ramda
Bravi
@Bravilogy
Jun 10 2016 16:16
I use mithril.js for a few of my frontend applications and I have to say mithril + ramda = purity :D
Brad Compton (he/him)
@Bradcomp
Jun 10 2016 16:22

sometimes I want to record screencasts for ramda
especially when I refactor a crazy complex nested loops from some legacy code
and re-write it in just a few readable lines of ramda

I would watch those :)

The cookbook and what function should I use are both good for looking at various corners of the library
Bravi
@Bravilogy
Jun 10 2016 16:57
oh well.. I guess I'm just being lazy :D
back to documentation ;(
LeonineKing1199
@LeonineKing1199
Jun 10 2016 19:57

Hey, can anyone help me understand some examples from the Mostly Adequate guide?

Namely, how can we call map if print is still a function before it becomes a functor as in their example:

//  map :: Functor f => (a -> b) -> f a -> f b
var map = curry(function(f, any_functor_at_all) {
  return any_functor_at_all.map(f);
});

var IO = function(f) {
  this.__value = f;
};

IO.of = function(x) {
  return new IO(function() {
    return x;
  });
};

IO.prototype.map = function(f) {
  return new IO(_.compose(f, this.__value));
};

// Support
// ===========================
var fs = require('fs');

//  readFile :: String -> IO String
var readFile = function(filename) {
  return new IO(function() {
    return fs.readFileSync(filename, 'utf-8');
  });
};

//  print :: String -> IO String
var print = function(x) {
  return new IO(function() {
    console.log(x);
    return x;
  });
};

// Example
// ===========================
//  cat :: String -> IO (IO String)
var cat = compose(map(print), readFile);

cat('.git/config');
// IO(IO('[core]\nrepositoryformatversion = 0\n'))
Maybe I'm misunderstanding but from my perspective, print isn't yet a functor until it's called so how can it be used when currying their version of map?
LeonineKing1199
@LeonineKing1199
Jun 10 2016 20:07
Well, I kind of get how it all works now. It's because of IO's implementation of map works. It returns another functor whose encapsulated function is a composition of readFileSync and then print.
So, when we cat, we invoke readFile which returns an IO functor that encloses the readFileSync function. We then map that functor and by doing so, we return a new IO functor that encapsulates the composition of the mapping function (should be a functor) and the originally encapsulated function.
So that's why in the map call, we return a new IO that's instantiated with an IO functor because that's what print returns. But couldn't we implement print to not return an instance of the IO functor?
LeonineKing1199
@LeonineKing1199
Jun 10 2016 20:18
It just seems needless to me to say that map takes a functor as an absolute and it also seems needless that print just isn't stored in the new IO anyway.
Weird stuff, man.
LeonineKing1199
@LeonineKing1199
Jun 10 2016 22:09
I've just resolved that they mean "callable object" when they say "functor" because you can't feed map any sort of function and it'll just apply it. There documentation for their map implementation is wrong and their use of print is over-complicated.
Shahar Or
@mightyiam
Jun 10 2016 22:54
Hi. I'm looking to make a reducer that I can compose of a pipe of reducers. Should I use R.pipe for that?
LeonineKing1199
@LeonineKing1199
Jun 10 2016 22:58
Can you start by explaining your problem first?
Shahar Or
@mightyiam
Jun 10 2016 23:01
I'm making a state machine, @LeonineKing1199 . My input is an Rx observable of change events that look like {type: 'doSomething', data: 'foo'}. I'm thinking of building my state machine like change$.scan(R.pipe(...reducers))
Only thing is that R.pipe doesn't support multiple arguments after the first reducer. So I have to transform the two arguments, state and change into a single object either before the pipe or in the first reducer in the pipe.
And then I have to add a .pluck to the stream...
Shahar Or
@mightyiam
Jun 10 2016 23:09
I see that require('ramda/src/pipe') seems to work. Is it supported?
LeonineKing1199
@LeonineKing1199
Jun 10 2016 23:13
First time I've heard of Rx observable or w/e. That's oddly specific. I really meant, can you describe your problem in an approachable and generic enough way such that we don't have to google what you're trying to do.
David Chambers
@davidchambers
Jun 10 2016 23:20

I see that require('ramda/src/pipe') seems to work. Is it supported?

It is, though it's untested. It should work. ;)

Shahar Or
@mightyiam
Jun 10 2016 23:25
Well, my input is two arguments, state and change. I'd like to run that through a bunch of reducers, in a pipe sort of way. That's pretty much it.
I think I'm just going to put those two arguments into a single object and use R.pipe to compose my reducer from all the little reducers