These are chat archives for ramda/ramda

1st
Dec 2016
Denis Stoyanov
@xgrommx
Dec 01 2016 01:03
@LeonineKing1199 welcome to PR =)
Hardy Jones
@joneshf
Dec 01 2016 05:02
@rjhilgefort you might also benefit from changing the data type. You're basically using an array of objects as though it's a Map. Might as well make a Map.
I'm willing to bet that you don't modify just one object in the array throughout your whole program.
You might. But It's likely that you either do the modification more than once, or do it with multiple elements of the array.
In either case, you benefit more from just using a Map rather than an array.
If it's a Map, you could then lens up the solution a bit.
Hardy Jones
@joneshf
Dec 01 2016 05:08
I mean, I guess you could lens up the solution even if it's not a Map, but whatever :wink:.
Nate Abele
@nateabele
Dec 01 2016 07:19
Good morrow, Ramda friends. I have made a thing: https://gist.github.com/nateabele/9c55ef3942a8b24f2140d8f05ec257bf
Basically, you pass in pipe() or compose(), and when a subsidiary function throws an error, you get something like Error in pipe() sequence <friendly name> at step 3 (f1()): <original error>.
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 10:33
Morning everyone, is there a nicer way to express this? https://goo.gl/pyWCBI
Kurt Milam
@kurtmilam
Dec 01 2016 11:32
@aaronmcadam not point-free, but a little more concise: https://goo.gl/fqS6zy
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 11:33
Yeah, thanks @kurtmilam
Kurt Milam
@kurtmilam
Dec 01 2016 11:33
np
Kurt Milam
@kurtmilam
Dec 01 2016 11:56
Or a little more declarative: https://goo.gl/EFNNTW
Not sure what common practice is, but I like to use function names that make it very clear what the function is doing. Then the code reads more like prose that's easier for me to follow.
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 11:59
For me, I think it depends on re-use and what the abstraction represents. When it comes to business rules, I think sometimes the higher level function ('shouldFooterBeDisplayed') is the important part whereas lower level policy can be read within the function
Kurt Milam
@kurtmilam
Dec 01 2016 12:00
Agreed. I guess the question is whether you'd ever want to know whether the probe had that status without also being interested in whether the footer should be displayed or not.
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 12:00
But there are times where aliases are very useful
Actually this bring me onto another point we've been hitting recently. Should we just have objects we can send messages to (like probe.isRespondable() instead of functions. I think the functions are really nice to compose together though and show up logical duplication and possibly lower-level abstractions
A better example is how we handle the media our users upload. Sending media.isReady() (we have to transcode it), along with other messages might make more sense than the module of functions we wrote that let us query different states.
Kurt Milam
@kurtmilam
Dec 01 2016 12:03
Or just rename the displayFooter function to isProbeRespondable
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 12:03
I know FP doesn't preclude object usage, but it is a little bit hard to decide when to fall back onto objects
Kurt Milam
@kurtmilam
Dec 01 2016 12:03
(or whatever the business rule indicates)
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 12:04
If there were a couple of different rules used to show different parts of the UI, traditionally I would write a view model object to abstract them
Kurt Milam
@kurtmilam
Dec 01 2016 12:08
Not sure how it looks when the codebase becomes large, but it seems to me grouping functions specific to itemX-specific actions would be similar to defining methods on itemX objects.
So, media.isReady() or isMediaReady(). The only difference is that you don't have access to this in the function.
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 12:11
and gladly so!
It's a bit funny though, cause I used to use functions taking the same argument as a heuristic for introducing new objects. For example isReady(media), hasFailed(media) would make me add an object with those functions as methods instead. Now I'm going the other way because I really like how compositions read, and break up a process into nice logical steps and pipelines
So I need a bit more practice to work out how to get the best of both message sending and composition. I'm sure there's a balance to be found
Kurt Milam
@kurtmilam
Dec 01 2016 12:15
I like how compositions read, as well, and I'd go for isMediaReady and hasMediaFailed or mediaIsReady, mediaHasFailed (second version may be more useful for code-completion).
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 12:15
Yeah, but I do like a consistent prefix of is or has from a style-guide point of view for boolean functions
Kurt Milam
@kurtmilam
Dec 01 2016 12:16
I usually write them that way, as well. Was just thinking about the benefits of using an object over a group of functions, and code-completion is one benefit that media.hasFailed has over hasMediaFailed.
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 12:17
yep, I agree
Kurt Milam
@kurtmilam
Dec 01 2016 12:18
Otherwise, if you're not accessing this from within the object methods, it seems like you'd be using the object purely as a way to group related methods by name and location in the code, which you could also accomplish by using object-specific function names and grouping the definitions of those functions in your code.
If you're not using this inside media.hasFailed, it seems you could compose media.hasFailed, anyway.
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 12:24
hmm I see what you're seeing
Kurt Milam
@kurtmilam
Dec 01 2016 12:26
I can't think of a good reason not to use an object as a collection of composable methods (not accessing this) that are specific to one type of data. Interesting idea that I hadn't considered.
I guess the only question would be whether a method might seem specific today but be more general tomorrow, in which case it might be a little less work to just rename a function.
Denis Stoyanov
@xgrommx
Dec 01 2016 12:30
['participant_responded', 'probe_resolved'].some(prop => {
 return { probeStatus: 'participant_responded' }['probeStatus'] === prop;
})
one line
['participant_responded', 'probe_resolved'].includes({ probeStatus: 'participant_responded' }['probeStatus'])
I need to port all methods of Ramda via standard methods of js like (map, filter, reduce, includes, some, every, etc...)
Kurt Milam
@kurtmilam
Dec 01 2016 12:38
Nice!
Wait, the one-liner isn't working for me in the REPL.
Cannot read property 'includes' of undefined
Anton Strömkvist
@ahstro
Dec 01 2016 12:42
Is there a way to skip the first parameter a function gets? Kind of similar to what unary is doing, except not. So I could write functionThatGetsTwoArguments = skipFirst(doStuffToSecondArgument) instead of functionThatGetsTwoArguments = (first, second) => doStuffToSecondArgument(second)?
Kurt Milam
@kurtmilam
Dec 01 2016 12:44
@ahstro You can flip the function and pass a dummy value in, first.
I do this with third-party library functions that are binary, where the second argument is an optional options argument.
For instance: const unaryHBParse = R.flip(Handlebars.parse)({})
Then I can call unaryHBParse with the actual value I want to parse.
@ahstro The original signature is Handlebars.parse(stringToParse, optionalOptionsObject) I can call the flipped version like unaryHBParse(stringToParse) and it's composable.
Hm, wait. That's not what you're asking. Apologies.
Anton Strömkvist
@ahstro
Dec 01 2016 12:49
Not quite, but it did help me a lot. Turns out I could just wrap my pipe with flip and it all worked out. Thank you!
Kurt Milam
@kurtmilam
Dec 01 2016 12:50
np!
Denis Stoyanov
@xgrommx
Dec 01 2016 12:55
@kurtmilam try it in chrome console
Kurt Milam
@kurtmilam
Dec 01 2016 13:01
Interesting
Works there. Must be an issue in the REPL.
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 13:02
I wonder if those array methods are in corejs
James Forbes
@JAForbes
Dec 01 2016 13:06
@nateabele nice!
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 13:10
Yeah thanks @kurtmilam, I've heard of those before, but I'd need to add corejs back to my build for x-browser support
oh hold on, it seems some is IE9+
It's includes that is new, it's not supported in IE at all.
Kurt Milam
@kurtmilam
Dec 01 2016 13:11
Ah, I see. I'm not familiar with corejs. I don't generally have to worry about cross-browser support these days.
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 13:12
corejs is a package that shims the "standard library" of JS
Kurt Milam
@kurtmilam
Dec 01 2016 13:12
I build to a single browser and tell my clients that's what they'll have to use.
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 13:12
hehe nice, just like 1997
:P
Kurt Milam
@kurtmilam
Dec 01 2016 13:12
Or two browsers - chrome on the desktop and chrome on Android.
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 13:13
Do you also include recommended resolutions too? ;)
Kurt Milam
@kurtmilam
Dec 01 2016 13:13
They're business applications, so not open to the general public.
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 13:13
I build the same, yeah
Though we try to support IE10+, most of our users are on Chrome
Kurt Milam
@kurtmilam
Dec 01 2016 13:16
I worked for an interactive ad agency back in 2000. It was horror, with the designers demanding pixel-perfect adherence to their designs in all available browsers and plenty of features requiring javascript (that also had to work the same across all browsers). Not fun.
Try explaining to a designer that IE's drop-down box can't be styled.
Denis Stoyanov
@xgrommx
Dec 01 2016 13:50
@ram-bot
Reflect.ownKeys(Array.prototype)
ram-bot
@ram-bot
Dec 01 2016 13:50
Reflect is not defined
Denis Stoyanov
@xgrommx
Dec 01 2016 13:51
@ram-bot
Object.keys(Array.prototype)
ram-bot
@ram-bot
Dec 01 2016 13:51
[]
Denis Stoyanov
@xgrommx
Dec 01 2016 13:51
oh
LeonineKing1199
@LeonineKing1199
Dec 01 2016 15:57
I think you need this
@ram-bot
Object.getOwnPropertyNames(Array)
ram-bot
@ram-bot
Dec 01 2016 15:57
[ 'length',
  'name',
  'arguments',
  'caller',
  'prototype',
  'isArray',
  'from',
  'of',
  'observe',
  'unobserve' ]
LeonineKing1199
@LeonineKing1199
Dec 01 2016 15:58
@ram-bot
Object.getOwnPropertyNames(Array.prototype)
ram-bot
@ram-bot
Dec 01 2016 15:58
[ 'length',
  'constructor',
  'toString',
  'toLocaleString',
  'join',
  'pop',
  'push',
  'concat',
  'reverse',
  'shift',
  'unshift',
  'slice',
  'splice',
  'sort',
  'filter',
  'forEach',
  'some',
  'every',
  'map',
  'indexOf',
  'lastIndexOf',
  'reduce',
  'reduceRight',
  'entries',
  'keys',
  'copyWithin',
  'find',
  'findIndex',
  'fill' ]
Aaron Mc Adam
@aaronmcadam
Dec 01 2016 17:11
Hi everyone, I've got a few functions here that build CSS classes. I'm looking for tips on how I could improve this module a bit: https://goo.gl/q286oP
I'm thinking I could use join or concat to simplify things a bit
Francisco Ryan Tolmasky I
@tolmasky
Dec 01 2016 17:51
How do I run just one ramda test?
Kevin Wallace
@kedashoe
Dec 01 2016 18:32
@tolmasky you can eg mocha test/add.js
Just RAG
@justrag
Dec 01 2016 19:10
In my componentWillReceiveProps I need a check for change in several props. I've managed to use R.any but I'm looking for a way to elegantly express the predicate function:
  R.any(p => (nextProps.pagination[p] !== this.props.pagination[p]),
    ['page', 'perPage', 'searchColumn', 'searchPhrase', 'sortColumn', 'sortDirection']);
(All my Ramda problems come from not really understanding how currying works...)
This should probably be some form of eqProps
R.eqProps(p, nextProps.pagination, this.props.pagination)
But how to put the "p" in there?
Brad Compton (he/him)
@Bradcomp
Dec 01 2016 19:25
At least for now you can use:
R.__
Huh, no ram-bot on that
R.eqProps(R.__, nextProps.pagination, this.props.pagination)(p)
Just RAG
@justrag
Dec 01 2016 19:29
Do I need the (p) at the end?
Brad Compton (he/him)
@Bradcomp
Dec 01 2016 19:30
To do what you have above, something like:
R.none(R.eqProps(R.__, nextProps.pagination, this.props.pagination), [/**/])
Just RAG
@justrag
Dec 01 2016 19:37
Oh, yeah, I actually have a problem with simple logical negation ;)
Brad Compton (he/him)
@Bradcomp
Dec 01 2016 19:38
R.complement
Brad Compton (he/him)
@Bradcomp
Dec 01 2016 19:38
is often helpful for that
Just RAG
@justrag
Dec 01 2016 19:45
BTW, eqProps is == or ===?
Brad Compton (he/him)
@Bradcomp
Dec 01 2016 19:57
R.eqProps
Brad Compton (he/him)
@Bradcomp
Dec 01 2016 19:57
Neither. It's deep value equality
using R.equals