These are chat archives for ramda/ramda

26th
Mar 2016
Jonah
@jonahx
Mar 26 2016 00:48
@JAForbes Thanks, I liked that article.
Jonah
@jonahx
Mar 26 2016 01:33
@JAForbes I think what I’m really after, though, is how to fit this callback style “success” or “error” path of the database into a more general sequence of things, each of which can have success/error paths (such as validation) using kleisli composition. Basically, let’s say the user sends some data. I need to 1. validate that data 2. do a DB lookup with it. Each of those steps can succeed or fail. And I want to chain them together. This can be achieve with a Validation or Either monad. But Im strugging to fit the callbacks into this style. Since we no longer have functions that are returning Success or Failure, but instead a db function that callsback to success or failure callbacks.
James Forbes
@JAForbes
Mar 26 2016 02:19
@jonahx Sounds like a perfect job for an Either/Maybe
Have you seen Railway Oriented Programming, great video: https://vimeo.com/97344498
Jonah
@jonahx
Mar 26 2016 02:52
@JAForbes Indeed, I have seen that and it’s what I want to do. It’s not clear to me how to fit the pieces with callbacks into that scheme.
Jonah
@jonahx
Mar 26 2016 03:58

A related question, about the folktale data.validation docs:

// To aggregate the failures, we start with a Success case containing
// a curried function of arity N (where N is the number of validations),
// and we just use an `.ap`-ply chain to get either the value our Success
// function ultimately returns, or the aggregated failures.
function isPasswordValid(a) {
  return Success(function(x){ return function(y){ return a }})
           .ap(isPasswordLongEnough(a))
           .ap(isPasswordStrongEnough(a))
}

The need to start with a boilerplate curried function of the same lenght as the number of validations seems odd. Is there a way to avoid this?

Aldwin Vlasblom
@Avaq
Mar 26 2016 10:04
R.sequence
Aldwin Vlasblom
@Avaq
Mar 26 2016 10:04
Maybe?
My guess would be something like sequence(Validation.of, [isPasswordLongEnough(a), isPasswordStrongEnough(a)]) might work.
GÁBOR Áron Zsolt
@ashnur
Mar 26 2016 12:11
@JAForbes huge thanks for that video, i was just in need of it without even realizing...
Hardy Jones
@joneshf
Mar 26 2016 15:31
@Avaq I think you need one last thing to get the same behavior as the original, map it and return a.
Hardy Jones
@joneshf
Mar 26 2016 15:58
Otherwise you end up with an array of the password.
Aldwin Vlasblom
@Avaq
Mar 26 2016 16:20
Ah, yes.
Michael Hurley
@buzzdecafe
Mar 26 2016 19:54
just published 0.20
ramda/ramda#1698
Aldwin Vlasblom
@Avaq
Mar 26 2016 20:51
:confetti_ball:
Denis Stoyanov
@xgrommx
Mar 26 2016 23:11
Hi guys! What do u think about this one https://github.com/ramda/ramda/pull/1564#issuecomment-201948104 ?
Scott Sauyet
@CrossEye
Mar 26 2016 23:18
Commented on the issue, where I saw it first. It looks to me more likely to be Cookbook material, but I could certainly be convinced otherwise.
I hadn't seen your demo when I responded. That's a nice way to do some easing without any complicated formulas.
Denis Stoyanov
@xgrommx
Mar 26 2016 23:20
Scott Sauyet
@CrossEye
Mar 26 2016 23:30
I guess I don't follow. clamp already works for any Ordered type.
Denis Stoyanov
@xgrommx
Mar 26 2016 23:31
oh! js is ugly! 'a' > 'c'
Scott Sauyet
@CrossEye
Mar 26 2016 23:32
... which returns false. I don't see the problem. :smile:
Denis Stoyanov
@xgrommx
Mar 26 2016 23:34
@CrossEye sure, but in fp lang you cannot do it if it don't implement Ord as I remember.
Jonah
@jonahx
Mar 26 2016 23:49
I notice in the docs clamp is under “Relaction” — is that just a typo?
Michael Hurley
@buzzdecafe
Mar 26 2016 23:58
It's the best function for relacting
yes, it's a typo :-)