These are chat archives for ramda/ramda

13th
Feb 2017
David Chambers
@davidchambers
Feb 13 2017 00:22

Cross-post from the Sanctuary room:

:heart: sanctuary-js/sanctuary#332 :heart:

Jonah
@jonahx
Feb 13 2017 00:57
@kwijibo, @alex-deas here’s my attempt at separating out the validation and then delegating to it in the type ctor, using paldepind’s union-types. I’m still not happy with it, mainly because the dependent types constraint of min < max forces me repeat logic that I’d rather union-types be handling. Any feedback appreciated:
const Any = always(true);

function Range(min, max) {
  const res = Range.validate(min, max);
  return Range.RangeValidationResult.case({
    Range: () => res,
    InvalidMin: () => {throw 'Invalid min'},
    InvalidMax: () => {throw 'Invalid min'},
    MinGreaterThanMax: () => {throw 'Min cannot be greater than max'}
  }, res);
}

Range.RangeValidationResult = Type({
  Range: [Number, Number],
  InvalidMin: [Any],
  InvalidMax: [Any],
  MinGreaterThanMax: [Number, Number]
});

Range.validate = function(min, max) {
  const Result = Range.RangeValidationResult;
  return (!isNumber(min)) ? Result.InvalidMin(min) :
         (!isNumber(max)) ? Result.InvalidMax(max) :
         (min > max)      ? Result.MinGreaterThanMax(min, max) :
                            Result.Range(min, max);
}
Gabe Johnson
@gabejohnson
Feb 13 2017 14:36
@davidchambers :tada:
Mick Dekkers
@mickdekkers
Feb 13 2017 19:53
I'd like to use the return value of R.view in an object destructuring assignment, but the problem is that it could be null (and thus cause a TypeError). e.g.:
const { foo, bar } = R.view(foobarLens, data)
Any advice? I'd prefer not to wrap it in a try/catch or have an if statement check the return value first because I'd like to keep the code concise.
Keith Alexander
@kwijibo
Feb 13 2017 19:55
R.defaultTo({}) ?
Mick Dekkers
@mickdekkers
Feb 13 2017 19:57
Nice, thanks guys! :smile:
Drew
@dtipson
Feb 13 2017 21:22
@joneshf "What I'm saying is, it's okay to not stretch the "container" metaphor..." so I think you're saying that a metaphor is like a burrito: trying to stretch it is a bad idea
Rick Medina
@rickmed
Feb 13 2017 21:25
:laughing: ohh, I would so much love a burrito I could stretch and eat forever.
Brad Compton (he/him)
@Bradcomp
Feb 13 2017 21:30
:laughing:
Bravi
@Bravilogy
Feb 13 2017 22:54
hi guys
how can I make this bit simpler?
map(map(this.props.fetchedData))
first map is applied to Future from ramda-fantasy. Second map is applied to Maybe, also from ramda-fantasy
Alex Deas
@alex-deas
Feb 13 2017 22:58
So you have a [Future[Maybe[A]]] and you want to map over it to construct what?
Bravi
@Bravilogy
Feb 13 2017 22:58
yeah
I want to
umm well.. this.props.fetchedData actually dispatches a redux action
and sends off the data that is inside that [Future[Maybe[A]]]
so I have something like this:
        Future.of(likesToProjects => [likesToProjects])
            .ap(fetchLikesToProjects
                .map(compose(Maybe, prop('data'))))
            .fork(console.error,
                map(this.props.fetchedData));
I specifically need likesToProjects to be inside an array
at the moment the server returns an object
I will be using .ap on other Futures soon and basically for the end result I want to have a bunch of data inside an array
so it would look something like this:
        Future.of(likesToProjects => someOtherData => [someOtherData, likesToProjects])
            .ap(fetchLikesToProjects
                .map(compose(Maybe, prop('data'))))
            .ap(fetchOtherStuff)
            .fork(console.error,
                map(this.props.fetchedData));
hope that makes sense
Alex Deas
@alex-deas
Feb 13 2017 23:12
Sorry, can't seem to wrap my head around it; and I don't have a pen on me at the moment (I usually need one to think) - I'll take a look at it tomorrow morning if someone else doesn't come up with an answer before then
Bravi
@Bravilogy
Feb 13 2017 23:12
no problem :)
thanks
Hardy Jones
@joneshf
Feb 13 2017 23:23
@dtipson meta
Rick Medina
@rickmed
Feb 13 2017 23:29