iterare
iterare copied to clipboard
Wrap singleton value with `iterate()`
I find I sometimes have to wrap single values from a data source as an IterableWithOperators for consumption later, and it would be nice if I could pass one into iterate as-is, like this:
const thing = single ? "Hi, I'm single!" : ["Hi, I'm with ->", "Hi, I'm with <-"]
// this throws an error
return iterate(thing)
// my workaround
if (Array.isArray(thing) {
return iterate(thing)
}
return iterate([thing])
I do this test in multiple places, and often I don't know if it is an array or not because the value comes from outside data. I would like to not have to test for this and just wrap it automatically in an iterable.