These are chat archives for ramda/ramda

6th
Oct 2018
Jonah
@jonahx
Oct 06 2018 19:30
Is there a name in FP for a function that wraps a value if it’s not already wrapped, and returns it as is otherwise. e.g.:
const wrapped = ifElse(is(Array), identity, x => [x])

wrapped(1)   // [1]
wrapped([1]) // [1]
Ben Briggs
@ben-eb
Oct 06 2018 20:27
@jonahx Ramda has of for that https://ramdajs.com/docs/#of
Jonah
@jonahx
Oct 06 2018 20:28
@ben-eb looks like that adds another layer if it’s already an array, though. from the docs:
R.of([42]); //=> [[42]]
Ben Briggs
@ben-eb
Oct 06 2018 20:28
Ah yes, you're right :)
Jonah
@jonahx
Oct 06 2018 20:32
fwiw, I’m more curious if the concept has a canonical name than in finding a specific existing function for it.
Ben Briggs
@ben-eb
Oct 06 2018 20:32
@jonahx
const wrapped = unless(is(Array), of)
Not sure what the canonical name might be!
Jonah
@jonahx
Oct 06 2018 20:33
Nice implementation though :)
Ben Briggs
@ben-eb
Oct 06 2018 20:37
:)