Skip to content

Instantly share code, notes, and snippets.

@alejandrobabio
Last active December 11, 2017 12:09
Show Gist options
  • Save alejandrobabio/4578ed310cb4a16cea7902f8f454a99e to your computer and use it in GitHub Desktop.
Save alejandrobabio/4578ed310cb4a16cea7902f8f454a99e to your computer and use it in GitHub Desktop.
Using flat_map to flatten a nested array
flat = (l = ->(x) { x.flat_map {|e| Array === e ? l.(e) : e } })
flat.([1, 2, 3, [4, 5, [6], [ ] ] ])
#==> [1,2,3,4,5,6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment