Module: Enumerable
- Defined in:
- lib/gooddata/extensions/enumerable.rb
Overview
Copyright (c) 2010-2017 GoodData Corporation. All rights reserved. This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree.
Instance Method Summary collapse
- #ljust(n, x) ⇒ Object
- #mapcat(initial = [], &block) ⇒ Object
- #pmapcat(initial = [], &block) ⇒ Object
- #pselect(&block) ⇒ Object
- #rjust(n, x) ⇒ Object
Instance Method Details
#ljust(n, x) ⇒ Object
36 37 38 |
# File 'lib/gooddata/extensions/enumerable.rb', line 36 def ljust(n, x) dup.fill(x, length...n) end |
#mapcat(initial = [], &block) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/gooddata/extensions/enumerable.rb', line 8 def mapcat(initial = [], &block) reduce(initial) do |a, e| block.call(e).each do |x| a << x end a end end |
#pmapcat(initial = [], &block) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/gooddata/extensions/enumerable.rb', line 17 def pmapcat(initial = [], &block) intermediate = pmap(&block) intermediate.reduce(initial) do |a, e| e.each do |x| a << x end a end end |
#pselect(&block) ⇒ Object
27 28 29 30 |
# File 'lib/gooddata/extensions/enumerable.rb', line 27 def pselect(&block) intermediate = pmap(&block) zip(intermediate).select { |x| x[1] }.map(&:first) end |
#rjust(n, x) ⇒ Object
32 33 34 |
# File 'lib/gooddata/extensions/enumerable.rb', line 32 def rjust(n, x) Array.new([0, n - length].max, x) + self end |