These are chat archives for ramda/ramda

28th
Feb 2016
Richard Seldon
@arcseldon
Feb 28 2016 05:46
hi, quick question regarding fantasy land algebraic types.
//  readFile :: String -> IO String
var readFile = function(filename) {
  return new IO(function() {
    return fs.readFileSync(filename, 'utf-8');
  });
};”
Excerpt From: drboolean. “mostly-adequate-guide.” iBooks.
do any libraries provide conveniences for automatically wrapping existing functions with IO or Future etc - looking for a sort of “promisify” equivalent.
(not simply Future.of)
var readFile = Promise.promisify(require("fs").readFile);
Keith Alexander
@kwijibo
Feb 28 2016 07:54
@arcseldon folktale/data.task#28
Richard Seldon
@arcseldon
Feb 28 2016 08:13
wow, i should already have known this. https://github.com/stoeffel/futurize
Thanks @kwijibo -looks like this is a popular question - folktale/data.task#30
looks like a powerful combination - data.task and futurize
Example given:
import { futurize } from 'futurize';
import { Future } from 'ramda-fantasy';
// or
import Task from 'data.task';
Keith Alexander
@kwijibo
Feb 28 2016 08:54
@arcseldon nice, looks useful
Hendrik Helwich
@hhelwich
Feb 28 2016 17:38

Ramda has this behavior when using a placeholder in a curried function:

g(_, a)(b) = g(_)(b, a) = g(b, a)

I wonder why not like this?:

g(_, a)(b) = g(_)(a, b) = g(b, a)

This would be the expected behavior for a curried function and would be useful to just turn around the parameters in the function.

Scott Sauyet
@CrossEye
Feb 28 2016 18:06
@hhelwich: Well, there's already a function for that: flip. But I think it would be odd to say, "If the placeholder is supplied in the fourth position, it reserves space for the missing fourth parameter. If it's supplied in the third position, it reserves space for the missing third parameter. If it's supplied in the second position, it reserves space for the missing second parameter. If it's supplied in the first position, it flips the order of the first two parameters."
I suppose it's not quite as bad as that, as we could distinguish something about when the placeholder is the last argument.
But there is discussion underway about removing the placeholder from curry altogether and moving it only into the partial calls.
Aldwin Vlasblom
@Avaq
Feb 28 2016 18:16
@CrossEye I think the behaviour @hhelwich is expecting would be: "If the placeholder is supplied, the argument at that position shifts and becomes the new last argument"
Currently the behaviour of the placeholder differs between calling the function like f(a, b, c) and f(a)(b)(c)
Hendrik Helwich
@hhelwich
Feb 28 2016 18:20
@CrossEye Thanks for the flip hint. I did not know that
@Avaq Yes, i think i was expecting something like this to be equal:
g(1,2,3,4)
g(1,_,3,4,2)
g(1,_,3,_,2,4)
g(_,_,_,_,1,2,3,4)
g(_,_,_,_,_,2,3,4,1)
g(_,_,_,_,_,2,_,4,1,3)
Aldwin Vlasblom
@Avaq
Feb 28 2016 18:21
Yeah, so like I described. Whenever the function encounters a placeholder, the value at that position is instead given at the "last" position. At which point it no longer makes a difference when you're calling it like f(_)(a)(b) or f(_, a, b) (either case is f(b, a))
I think it's an interesting idea.
Hendrik Helwich
@hhelwich
Feb 28 2016 18:23
@Avaq yes thats what i meant :-)
Scott Sauyet
@CrossEye
Feb 28 2016 18:24
Oh, that is interesting. That's very different from the normal notion of a placeholder, I think, but it's certainly more flexible.
Aldwin Vlasblom
@Avaq
Feb 28 2016 18:25
And in a way, more predictable, because we expect our functions to behave the same f(a)(b) and f(a, b), despite the type of arguments.
Scott Sauyet
@CrossEye
Feb 28 2016 18:26
The trouble with the discussions about losing the placeholder is that it removes some functionality. It's not terribly useful stuff, but I do use it occasionally, and don't really want to have to substitute lambdas for it.
This alternative would be very different.
I think it's too late for it, though.
If we'd done it up front, it might have made some sense.
That gives the full power of something like rearg without the nasty API. I wish we'd thought of it back when...
Aldwin Vlasblom
@Avaq
Feb 28 2016 18:32
I'm going to remember this one. If it ever comes up I'd like to implement placeholder like this.
Hendrik Helwich
@hhelwich
Feb 28 2016 18:32
I'm glad you like the idea :-)
Scott Sauyet
@CrossEye
Feb 28 2016 18:34
@hhelwich: Yes, but where were you a year ago?! :smile:
Hendrik Helwich
@hhelwich
Feb 28 2016 18:36
@CrossEye Sorry :-)
Aldwin Vlasblom
@Avaq
Feb 28 2016 19:38
@CrossEye @hhelwich Played around with the idea; http://goo.gl/OKio5S .. I got to be off. Have a nice evening or your regional equivalent. :)
Scott Sauyet
@CrossEye
Feb 28 2016 19:48
Very cool, @Avaq! Enjoy your evening!