These are chat archives for ramda/ramda

12th
May 2017
Rick Medina
@rickmed
May 12 2017 00:03
@JasonShin those are lots of side effects, you would need to use tasks/futures to keep it functional, are you familiar?
Jason Shin
@JasonShin
May 12 2017 00:27
@rickmed Not sure
can you show briefly guide me through it?
or any readings about it?
Rick Medina
@rickmed
May 12 2017 00:32
https://github.com/fluture-js/Fluture. go to the promises comparison link
@JasonShin
Matthew Willhite
@miwillhite
May 12 2017 01:04
@JasonShin You may find this helpful…it is a bit dated, but covers the concepts very thoroughly: http://robotlolita.me/2014/03/20/a-monad-in-practicality-controlling-time.html
Jason Shin
@JasonShin
May 12 2017 01:22
nice ! =)
I will have a look at both
probably I will try to get my head around with monads
then look at Fluture
Riderman de Sousa Barbosa
@Ridermansb
May 12 2017 01:48
How can I dynamic set a value into a property?
const fetch = () => { num: 1 };
const payloadProp = lensProp('payload');
const setPayload = set(payloadProp, fetch); // NOT WORK, set the function
setPayload({ id: 1, payload: { message: 'request' } });
Riderman de Sousa Barbosa
@Ridermansb
May 12 2017 02:24
I created a question on stackoverflow about that
Jason Shin
@JasonShin
May 12 2017 03:22
git branch
ooops
Philipp Wille
@Yord
May 12 2017 05:40

@Ridermansb There are basically two ways, I can think of, to achieve this:
1) Compose a new lens for set:

const obj = { id: 1, payload: { message: 'request' } }
const payloadProp = lensProp('payload');

set(compose(payloadProp, lensProp('num')), 1, obj)

2) Use over:

const obj = { id: 1, payload: { message: 'request' } }
const payloadProp = lensProp('payload');

over(payloadProp, assoc('num', 1), obj)
Joey Figaro
@joeyfigaro
May 12 2017 18:15
Hey guys - can anyone help me decipher why I'm getting Error: First argument to _arity must be a non-negative integer no greater than ten for the following? Have a feeling it has to do with moment. scratchpad: https://goo.gl/w2H1rA
Brad Compton (he/him)
@Bradcomp
May 12 2017 18:17
ifElse expects a function as the first argument, but isNotNil(previousDate) is a boolean
const date = R.ifElse(
        isNotNil,
        d => moment(d).add(daysToAdd, 'days').format(),
        () => moment(new Date(getRandomYear(), getRandomMonth(), getRandomDay()))
    )(previousDate);
Does that work? (just a guess)
Joey Figaro
@joeyfigaro
May 12 2017 18:19
That'd do it! Let me give it a shot.
Brad Compton (he/him)
@Bradcomp
May 12 2017 18:20
@ram-bot
R.ifElse(1, 2, 3)
ram-bot
@ram-bot
May 12 2017 18:20
First argument to _arity must be a non-negative integer no greater than ten
Joey Figaro
@joeyfigaro
May 12 2017 18:24
@Bradcomp Hmm. return curryN(Math.max(condition.length, onTrue.length, onFalse.length), -> TypeError: Cannot read property 'length' of undefined
from /ramda/src/ifElse.js:31;
Joey Figaro
@joeyfigaro
May 12 2017 18:30
Oh, wow.
isNotNull didn't exist - I swapped it to isNil and moved around the arguments and it works fine.
Would not have guessed that from the error. :)
const isNotNil = R.complement(R.isNil)
Brad Compton (he/him)
@Bradcomp
May 12 2017 18:40
Yeah the errors can be cryptic when you pass a Ramda function the wrong sort of thing
The First argument to _arity one crops up a lot. It generally you've passed a non-function thing to something expecting a function
Joey Figaro
@joeyfigaro
May 12 2017 18:44
Excellent - that's helpful. Thanks @Bradcomp
Joey Figaro
@joeyfigaro
May 12 2017 19:02
Any insight on reducing boilerplate in a situation that requires either method A or B where both situations use the same values? https://goo.gl/EVlwz1
Awful lot repeated there.
Brad Compton (he/him)
@Bradcomp
May 12 2017 19:31
Will moment let you pass in a negative number to add?
Brad Compton (he/him)
@Bradcomp
May 12 2017 19:32
Joey Figaro
@joeyfigaro
May 12 2017 19:32
HAH.
Wow.
Creative, Brad - good thinking.
That eliminates the need for taking in a direction argument, as well.
Brad Compton (he/him)
@Bradcomp
May 12 2017 19:33
yeah
You could just use one function and pass in the delta in either direction. If you wanted to keep the future / past API you can use negate like in the link above
Joey Figaro
@joeyfigaro
May 12 2017 19:34
:100: