iterare icon indicating copy to clipboard operation
iterare copied to clipboard

Wrap singleton value with `iterate()`

Open mattbishop opened this issue 2 years ago • 0 comments

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.

mattbishop avatar Nov 06 '22 23:11 mattbishop