Skip to content

Commit

Permalink
faster flat_map
Browse files Browse the repository at this point in the history
  • Loading branch information
kostya committed Apr 10, 2013
1 parent 8e4492d commit 11fa47d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib-topaz/enumerable.rb
Expand Up @@ -324,7 +324,16 @@ def sort_by(&block)

def collect_concat(&block)
return self.enum_for(:collect_concat) unless block
map(&block).flatten(1)
out = []
self.each do |e|
v = yield(e)
if v.respond_to?(:to_ary) && ary = Array.try_convert(v)
out.concat(ary)
else
out << v
end
end
out
end
alias flat_map collect_concat
end

0 comments on commit 11fa47d

Please sign in to comment.