DEV Community

Discussion on: What is Lodash/fp, even?

Collapse
 
mitramejia profile image
Mitra Mejia

For an slighly cleaner alternative:



import {cond, inRange, subTrue} from 'lodash/fp'

const getColor = cond([
  [inRange(0, 5), () => 'red'],
  [inRange(5, 10), () => 'blue')],
  [stubTrue, () => 'green']
])
Enter fullscreen mode Exit fullscreen mode
Collapse
 
ifarmgolems profile image
Patrik Jajcay • Edited

I did not assume imports to be present. I guess the methods could also be destructured from _ like

const {cond, inRange, ...} = _;
...
Enter fullscreen mode Exit fullscreen mode

And using them without _. prefix.