These are chat archives for ramda/ramda

30th
Mar 2017
Arve Knudsen
@aknuds1
Mar 30 2017 11:53
Is there some function in Ramda for ignoring more than N arguments? F.ex. to ensure that a function receives only the first argument
I guess I can use curryN
Kurt Milam
@kurtmilam
Mar 30 2017 11:57
@aknuds http://ramdajs.com/docs/#nAry should do the trick.
Arve Knudsen
@aknuds1
Mar 30 2017 11:59
Thanks @kurtmilam! My assertion about curryN was wrong...
Rafi
@Rafi993
Mar 30 2017 15:53
Hi
how do I do this https://goo.gl/vdj3NU
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 15:54
Is there a simple refactoring for this:
const translationKey = (userRole) => {
  if (userRole === 'staff') {
    return 'dashboard';
  }

  return 'discussion';
};
Rafi
@Rafi993
Mar 30 2017 15:54
I am trying to achieve solution for it in point free form
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 15:55
Can you add your desired output?
Rafi
@Rafi993
Mar 30 2017 15:57
I did I the comments
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 15:57
I can't tell what you're trying to do though
Kurt Milam
@kurtmilam
Mar 30 2017 15:57
@Rafi993 Quick and dirty - sure it can be cleaned up: https://goo.gl/4W4IMv
Gabe Johnson
@gabejohnson
Mar 30 2017 15:57
const translationKey = ifElse(equals('staff'),  always('dashboard'), always('discussion'));
@aaronmcadam :point_up:
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 15:58
thanks, I was thinking about always :)
Kurt Milam
@kurtmilam
Mar 30 2017 15:59
@Rafi993 sorry, seems I may have misread what you want.
Rafi
@Rafi993
Mar 30 2017 16:01
no problem
Brad Compton (he/him)
@Bradcomp
Mar 30 2017 16:03
@Rafi993 Like this: https://goo.gl/i8Xz31 ?
Rafi
@Rafi993
Mar 30 2017 16:04
thanks @Bradcomp
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 16:07
Hey @gabejohnson, if I wanted to use a custom function for my predicate instead of equals, how would I do that?
Rafi
@Rafi993
Mar 30 2017 16:07
I had to put not while mapping over aa so the result is inverse of aa
zipWith(assoc('error'), map(not,aa), as)
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 16:08
I take it my function would need to curried so it could take the input as its second argument?
Gabe Johnson
@gabejohnson
Mar 30 2017 16:09
replace the equals('staff') with the placeholder __
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 16:10
Here's my other func:
const getComponent = (userRole) => {
  if (isParticipantApp(userRole)) {
    return ParticipantNotification;
  }

  return StaffNotification;
};
Gabe Johnson
@gabejohnson
Mar 30 2017 16:11
@aaronmcadam read above
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 16:11
Oh, I would pass my isParticipantApp as the first argument?
Gabe Johnson
@gabejohnson
Mar 30 2017 16:11
yes
const translationKey = ifElse(__,  always('dashboard'), always('discussion'));
translationKey(equals('staff'))('staff');
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 16:12
const getComponent = ifElse(
 __,
  always(ParticipantNotification);
 always(StaffNotification)
)(isParticipantApp);
Gabe Johnson
@gabejohnson
Mar 30 2017 16:12
That should work
Though I'm sure someone else could come up w/ something better
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 16:13
why can I not pass isParticipantApp directly in, instead of the placeholder?
It seems to work?
my tests still pass :D
Gabe Johnson
@gabejohnson
Mar 30 2017 16:15
Hey @gabejohnson, if I wanted to use a custom function for my predicate instead of equals, how would I do that?
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 16:15
const getComponent = R.ifElse(
  isParticipantApp,
  R.always(ParticipantNotification),
  R.always(StaffNotification),
);
I stupidly thought the function needed to be binary :(
Gabe Johnson
@gabejohnson
Mar 30 2017 16:16
i thought you wanted a generic function that you could just pass a predicate to and get the translation function
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 16:16
ahhh sorry!!
cool, yeah that makes sense!
my fault :)
thanks @gabejohnson, I get it now :)
Gabe Johnson
@gabejohnson
Mar 30 2017 16:26
no worries. glad to help!
Denis Stoyanov
@xgrommx
Mar 30 2017 16:27
@Bradcomp I think this is better https://goo.gl/er1KZd
Gabe Johnson
@gabejohnson
Mar 30 2017 16:31
@xgrommx that doesn't give the expected output
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 16:31
When the argument itself is boolean, this is right, yeah?
const getPlayControlClasses = R.ifElse(
  R.identity,
  R.always('c-pause-button'),
  R.always('c-play-button'),
);
Gabe Johnson
@gabejohnson
Mar 30 2017 16:35
yes. but I know there has to be a better way than that
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 16:35
yeah I'm feeling that too
Gabe Johnson
@gabejohnson
Mar 30 2017 16:45
@aaronmcadam
const eitherOr = (t, c, a) => x => t(x) ? c : a; 

const getPlayControlClasses = eitherOr(
  R.identity,
  'c-pause-button',
  'c-play-button',
);

getPlayControlClasses(false)
Raine Virta
@raine
Mar 30 2017 16:57
const getPlayControlClass = c => c ? 'c-pause-button' : 'c-play-button'
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 16:57
Yeah, I sort of hate ternaries :)
and I'm fixing ESLint violations around ambiguous arrows (http://eslint.org/docs/rules/no-confusing-arrow)
Is anybody using prettier here?
Raine Virta
@raine
Mar 30 2017 16:59
strongly disagree with that rule
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 17:00
I can see how it's a little bit overly-strict
as for me, it's highlighting ternary usage that I want to avoid
Robert Mennell
@skatcat31
Mar 30 2017 17:00
the idea of eslint is at it's strictest it will feel familiar to a C/++ programmer
Raine Virta
@raine
Mar 30 2017 17:01
go for if-else then, it's much more verbose but if you find it more readable
Robert Mennell
@skatcat31
Mar 30 2017 17:01
this rule applies if you need it, otherwise no confusing arrows is a silly rule for a first order language
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 17:01
I prefer if-else because it makes the conditional really obvious, and can help highlight refactoring
Raine Virta
@raine
Mar 30 2017 17:01
what is highlight refactoring?
or typo?
oh right
Robert Mennell
@skatcat31
Mar 30 2017 17:02
@aaronmcadam if you don't like tenaries, instead just declare them as functions?
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 17:02
I mean it can help find code that may make sense to be refactored towards polymorphism, for example
Ryan Stegmann
@rstegg
Mar 30 2017 17:02
that rule makes no sense. => and <= would not be equivalent conditions
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 17:03
I think it's because they look similar lexically
I know very few people would really make that mistake though
Raine Virta
@raine
Mar 30 2017 17:04
I usually wrap lambda arguments always in parens, even if it's a single one. that alone makes it obvious it's an argument left to the arrow, and not a value of comparison
Ryan Stegmann
@rstegg
Mar 30 2017 17:04
don't write what you can't read :P
Aaron Mc Adam
@aaronmcadam
Mar 30 2017 17:04
me too, yeah I enforce parens all the time
Raine Virta
@raine
Mar 30 2017 17:05
I find it silly that no arg: (), multiple args: (x,y), yet one arg is allowed without parens
Robert Mennell
@skatcat31
Mar 30 2017 17:07
:+1:
Ryan Stegmann
@rstegg
Mar 30 2017 17:07
because when you use placeholders like _
_ => _ vs (_) => _
its easier to see the readability when it's nested: map((_) => console.log(":("))
Rick Medina
@rickmed
Mar 30 2017 18:14
I :heart: ternary expressions. I split them into lines to make them more readable (more than ifElse most of the times, imo). The same with lamdas to not confuse them with comparisons.
Rónán
@ronanyeah
Mar 30 2017 19:32
yeah i like formatting them like this a lot, but i understand the dislike
x =>
  x > 2
    ? 'ok'
    : 'not ok'
Robert Mennell
@skatcat31
Mar 30 2017 19:42
I prefer writing them like switch statments
x =>
  x > 2 ?
    '3 or more'
  : x < 1 ?
    '0'
  : '1 or 2'
Rick Medina
@rickmed
Mar 30 2017 20:20
x =>
  x > 2 ? '3 or more' :
  x < 1 ? '0' : 
 '1 or 2'
Robert Mennell
@skatcat31
Mar 30 2017 20:42
:+1: yeah that style is pretty agreeable as well
Jonah
@jonahx
Mar 30 2017 22:38
is this a decent way to create enums?
const Enum = (...keys) => pipe(map(x => [x, Symbol(x)]), fromPairs)(keys);
const Fruit = Enum('Apple', 'Orange', 'Banana');
Rónán
@ronanyeah
Mar 30 2017 23:28
@skatcat31 surely its better to use condthan nested ternaries?
Robert Mennell
@skatcat31
Mar 30 2017 23:29
@ronanyeah meh? Whe you're nesting any sort of conditionals it will always... nest
Rónán
@ronanyeah
Mar 30 2017 23:30
Cond accepts an array
Ryan Stegmann
@rstegg
Mar 30 2017 23:31
whats the need to nest conditionals?
Rónán
@ronanyeah
Mar 30 2017 23:32
@rstegg contrived examples :smile:
Rick Medina
@rickmed
Mar 30 2017 23:54
@ronanyeah why better?