These are chat archives for ramda/ramda

21st
Oct 2016
Michael Hurley
@buzzdecafe
Oct 21 2016 00:36 UTC
please check out the improved ramda repl: http://ramdajs.com/repl/
thanks to @craigdallimore for all the improvements
Denis Stoyanov
@xgrommx
Oct 21 2016 00:38 UTC
@buzzdecafe also will be better use Run button on demand.
Michael Hurley
@buzzdecafe
Oct 21 2016 00:40 UTC
everyone's a critic :smile:
Denis Stoyanov
@xgrommx
Oct 21 2016 00:45 UTC
@buzzdecafe Also really slooowww
@buzzdecafe Error: Failed to load http://wzrd.in/standalone/sanctuary@latest
Michael Hurley
@buzzdecafe
Oct 21 2016 00:55 UTC
hmmmm
the graceful failure is an improvement
but will look into the slowness. although nothing fundamental about how it evaluates has changed
merely how it loads on the page
slowness may be a side-effect of wzrd failing to serve sanctuary and RF
Michael Hurley
@buzzdecafe
Oct 21 2016 01:00 UTC
sigh
Denis Stoyanov
@xgrommx
Oct 21 2016 02:56 UTC
@ram-bot
Promise.resolve(10).then(x => console.log(x));
ram-bot
@ram-bot
Oct 21 2016 02:56 UTC
Promise { <pending> }
Denis Stoyanov
@xgrommx
Oct 21 2016 02:57 UTC
I like a monadic catamorphism :smile: https://goo.gl/m8e9SI
Stepan Kuzmin
@stepankuzmin
Oct 21 2016 10:05 UTC
Hi there! Is there any way to build array from function arguments using Ramda?
Something like var fn = function(){ return Array.from(arguments) }
Oh, I've found R.unapply(R.identity)
Denis Stoyanov
@xgrommx
Oct 21 2016 10:20 UTC
@stepankuzmin you don't need to use Array.from just spread const fn => (...args) => args.map(x => x * 10)
Stepan Kuzmin
@stepankuzmin
Oct 21 2016 10:44 UTC
Thanks @xgrommx!
Travis LaDuke
@laduke
Oct 21 2016 22:13 UTC
Kinda lost on re-arranging this one
  const update = todo => {

    //:: String -> Either a b
    id = toObjectId(todo._id);
  //->_Right { value: '580a86e0ccb07e6a515f1244' }

    return new Future((reject, resolve) => {
      collection.updateOne({_id: id}, {$set:{done: todo.done}})
        .then(data => resolve(data))
        .catch(err => reject(err));
    });
  };
Brad Compton (he/him)
@Bradcomp
Oct 21 2016 22:25 UTC
It would help to split up things into functions first, then see where your types are at.
//getId:: todo -> Either e ObjectId
const getId = compose(toObjectId, prop('_id'));

//updateTodo :: ObjectId -> Todo -> Future e mongoResult
const updateTodo = futurize((_id, todo) =>  collection.updateOne({_id}, {$set:{done: todo.done}})
Now we see we have a function that takes an ObjectId, but another that returns an Either
const update = (todo) => map(updateTodo(__, todo), getId(todo))
Obviously that could all be cleaned up.
You end up with an Either e (Future e MongoResult)
Brad Compton (he/him)
@Bradcomp
Oct 21 2016 22:31 UTC
Potentially, you could aggregate errors by having toObjectId return a Future instead of an Either (after all, they share the same basic shape)
Then you use chain to flatten it
Travis LaDuke
@laduke
Oct 21 2016 23:08 UTC
I was thinking about #2.
For some reason I couldn't get futurizeP to work yesterday.
Brad Compton (he/him)
@Bradcomp
Oct 21 2016 23:12 UTC
You can always write a helper function:
const updateOne = curry((coll, query, updates) => Future((rej, res) => coll.updateOne(query, updates).then(res, rej)));
Travis LaDuke
@laduke
Oct 21 2016 23:17 UTC
Ah. Should have done that first.
Do people commonly use Futures for not-async stuff?
Brad Compton (he/him)
@Bradcomp
Oct 21 2016 23:19 UTC
Speaking for myself, I will if I need to mix async code with non-async but failable code
It depends if you want to keep the errors separate
You can also convert from an Either to a Future
That's for Maybe but the same idea applies