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

[Feature Request] Add Flatten function #79

Open
alexmozaidze opened this issue Oct 25, 2023 · 1 comment
Open

[Feature Request] Add Flatten function #79

alexmozaidze opened this issue Oct 25, 2023 · 1 comment

Comments

@alexmozaidze
Copy link

alexmozaidze commented Oct 25, 2023

It would be very cool to have. I sometimes face problems where I have a table of tables like

{
  { "thing1", "thing2" },
  { "thing3", "thing4" },
  -- ...
}

And want to flatten this mess out using just one simple operation:

fun.flatten(mess)

And get this majestic data structure in the end:

{
  "thing1",
  "thing2",
  "thing3",
  "thing4",
  -- ...
}

I realize that I can simulate flatten with reduce and chain, but it's far less intuitive

fun.reduce(function(acc, x) return fun.chain(acc, x) end, {}, mess)

in Fennel it's a bit nicer, but still noisy

(fun.reduce #(fun.chain $1 $2) [] mess)
@svermeulen
Copy link

Using reduce also seems to result in a table instead of another iterator. I'd expect flatten() to produce an iterator

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

2 participants