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

Instance Method Details

#ljust(n, x) ⇒ Object



33
34
35
# File 'lib/gooddata/extensions/enumerable.rb', line 33

def ljust(n, x)
  dup.fill(x, length...n)
end

#mapcat(initial = [], &block) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/gooddata/extensions/enumerable.rb', line 5

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



14
15
16
17
18
19
20
21
22
# File 'lib/gooddata/extensions/enumerable.rb', line 14

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



24
25
26
27
# File 'lib/gooddata/extensions/enumerable.rb', line 24

def pselect(&block)
  intermediate = pmap(&block)
  zip(intermediate).select { |x| x[1] }.map(&:first)
end

#rjust(n, x) ⇒ Object



29
30
31
# File 'lib/gooddata/extensions/enumerable.rb', line 29

def rjust(n, x)
  Array.new([0, n - length].max, x) + self
end