Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap singleton value with iterate() #35

Open
mattbishop opened this issue Nov 6, 2022 · 0 comments
Open

Wrap singleton value with iterate() #35

mattbishop opened this issue Nov 6, 2022 · 0 comments

Comments

@mattbishop
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant