Quick one: nicer way to do this? #3358
-
This is mostly just for fun or for cleaner code, but I have something that looks funky:
As you can see, I have the same thing on both sides of a I just wondered if I'd missed a nicer way to put this that doesn't do the same computation twice. Maybe this is just how |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
why would you need cond() for this? a simple if you need some default you could even just do propOr(defaultColor, c.value, colorMap) |
Beta Was this translation helpful? Give feedback.
-
I missed out the rest of the conditions. That's what the ... represent.
…On Tue, 21 Mar 2023, 20:45 Andreas Herd, ***@***.***> wrote:
why would you need cond() for this a simple colorMap[c.value] does
exactly what you want, if map lacks the color, it will be undefined.
if you need some default you could even just do propOr(defaultColor,
c.value, colorMap)
—
Reply to this email directly, view it on GitHub
<#3358 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFFQW54R25L6ATZO7O6RYDW5IHPLANCNFSM6AAAAAAWCOICXE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
you could just update the first part color = cond([
...
[c => c.value in colorMap, c => colorMap[c.value]],
...
]) or more ramda-y color = cond([
...
[pipe(prop('value'), has(__, colorMap)), pipe(prop('value'), prop(__, colorMap))],
...
]) |
Beta Was this translation helpful? Give feedback.
-
Weirdly, I've been doing JavaScript for years and I don't think I've ever
used the keyword `in` except for inside a `for` loop. I like it, thanks,
I'll use that!
…On Tue, 21 Mar 2023 at 23:11, Kevin Wallace ***@***.***> wrote:
you could just update the first part
color = cond([
...
[c => c.value in colorMap, c => colorMap[c.value]],
...
])
or more ramda-y
color = cond([
...
[pipe(prop('value'), has(__, colorMap)), pipe(prop('value'), prop(__, colorMap))],
...
])
—
Reply to this email directly, view it on GitHub
<#3358 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFFQW7QZ3SFFSLRKIWWBILW5IYP5ANCNFSM6AAAAAAWCOICXE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
you could just update the first part
or more ramda-y