These are chat archives for ramda/ramda

Feb 2017
Keith Alexander
Feb 11 2017 08:00
@dtipson @xgrommx great observation! - Reader is basically a function right? with map and chain as combinators for composition
Denis Stoyanov
Feb 11 2017 09:19
@kwijibo yes, actually this is just Function with wrapper like Reader
Rick Medina
Feb 11 2017 14:34
I liked that Reader note! fp is so awesome! :)
Keith Alexander
Feb 11 2017 18:01

@dtipson I think you said something the other day about how it was helpful to understand Task by doing a minimal implementation (which you did very nicely in a few lines)
If you do the same for Reader, it's something like:

const Reader = run => ({
    map: f => Reader(env => f(run(env))),
    chain: f => Reader(env => f(Reader(run).run(env)).run(env)),

So the basic value of the reader is the run function, right? Just like in Task it's the fork function.
And run is just a normal unary function that takes one argument and returns a value
And then if you go for a staticland implementation, it's even clearer:

const Reader = {
  of: a => { return _ => a },
  map: f => run => {
    return x => f(run(x))
  chain: f => run => {
    return x => f(run(x))(x)
  run: x => run => run(x)
pipe( => x * 2),
  Reader.chain(x => Reader.of(x * 10)),
)(x => x) //=> 60
@rickmed and I think that also explains why composes when it treats Function as a functor
(sorry if I'm teaching grandmothers to suck eggs here, just that these things didn't click for me until I read @dtipson's remark about Reader being a monadic Function, and I thought it was really interesting)
Feb 11 2017 18:55

Im trying to compose a function like so:

function safeSomething(context, value){
    try {
        return doSomething(context)(value);
    catch (e){
        return reportError(context)(value);

I've gotten as far as:

const safeSomething = context => tryCatch(doSomething(context), reportError(context));

Can anyone help making this point free?

Keith Alexander
Feb 11 2017 19:03
Feb 11 2017 19:14
So, like this?
const safeSomething = converge(tryCatch, [doSomething, reportError]);
Feb 11 2017 19:39
Thanks :)
Denis Stoyanov
Feb 11 2017 21:48
converge ~= liftN