These are chat archives for ramda/ramda

19th
Mar 2018
Kielan
@Kielan
Mar 19 2018 07:31
I am trying to recursively omit 'id' prop from a nested object structure point free in ramda
Kielan
@Kielan
Mar 19 2018 07:41
i will provide exactly what I want using r.evolve with a sample data structure and let me know a better way to do any time anybody
Shawn Talbert
@ShawnTalbert
Mar 19 2018 20:31
stole this from the typescript channel, but wondering if there is a ramda idiomatic way of writing an expression like: Dimensions.width ? 'width=' + Dimensions.width + 'px' : ''
this reminds me of Maybe or Option in scala but the essense is to choose either a value concat with "px" , else empty string.
Shawn Talbert
@ShawnTalbert
Mar 19 2018 21:21
that was a good idea, though I'm hoping for something simpler than the standard ternary operator in js
it's possible that the plain ternary operator is as good as it can get
Kurt Milam
@kurtmilam
Mar 19 2018 23:10

@ShawnTalbert something like this should work

o(ifElse(isNil, always(''), x => `width=${x}px`), prop('width'))(Dimensions)

but I think you're better off with the ternary operator. If you're interested in Maybe and Option, you might want to take a look at Maybe and Either from sanctuary-js.

Kurt Milam
@kurtmilam
Mar 19 2018 23:31

I think you could shorten the above to this (although it's less composable):

ifElse(isNil, always(''), x => `width=${x}px`)(Dimensions.width)

The equivalent with a ternary operator is still a little shorter:

(x => isNil(x) ? '' :  `width=${x}px`)(Dimensions.width)
Kurt Milam
@kurtmilam
Mar 19 2018 23:45
@Kielan something like this https://goo.gl/yCJsLi ?
You can't make a recursive function completely point free in javascript, though.