Methods
elements elements! elementwise every every! ewise per threaded_map threaded_map_send to_elem
Classes and Modules
Class Enumerable::Elementor
Class Enumerable::Enumerator
Public Instance methods
elements()

Alias for every

elements!()

Alias for every!

elementwise(count=1)

Returns an elementwise Functor designed to make R-like elementwise operations possible.

  [1,2].elementwise + 3          #=> [4,5]
  [1,2].elementwise + [4,5]      #=> [5,7]
  [1,2].elementwise + [[4,5],3]  #=> [[5,7],[4,5]
This method is also aliased as ewise
# File lib/more/facets/elementwise.rb, line 16
  def elementwise(count=1)
    @_elementwise_functor ||= []
    @_elementwise_functor[count] ||= Functor.new do |op,*args|
      if args.empty?
        r = self
        count.times do
          r = r.collect{ |a| a.send(op) }
        end
        r
      else
        r = args.collect do |arg|
          if Array === arg #arg.kind_of?(Enumerable)
            x = self
            count.times do
              ln = (arg.length > length ? length : arg.length )
              x = x.slice(0...ln).zip(arg[0...ln]).collect{ |a,b| a.send(op,b) }
              #slice(0...ln).zip(arg[0...1n]).collect{ |a,b| b ? a.send(op,b) : nil }
            end
            x
          else
            x = self
            count.times do
              x = x.collect{ |a| a.send(op,arg) }
            end
            x
          end
        end
        r.flatten! if args.length == 1
        r
      end
    end
  end
every()

Returns an elemental object. This allows you to map a method on to every element.

  r = [1,2,3].every + 3  #=> [4,5,6]
This method is also aliased as elements
# File lib/more/facets/elementor.rb, line 57
  def every
    @_every ||= to_elem
  end
every!()

In place version of every.

This method is also aliased as elements!
# File lib/more/facets/elementor.rb, line 63
  def every!
    raise NoMethodError unless respond_to?(:map!)
    @_every_inplace ||= to_elem(:map!)
  end
ewise(count=1)

Alias for elementwise

per()
# File lib/more/facets/elementor.rb, line 46
  def per
    @__per__ ||= Functor.new do |op|
      Elementor.new(self, op)
    end
  end
threaded_map( {|| ...}

Like Enumerable#map but each iteration is processed via a separate thread.

 CREDIT Sean O'Halpin
# File lib/more/facets/thread.rb, line 37
  def threaded_map #:yield:
    map{ |e| Thread.new(e){ |t| yield(t) } }.map{ |t| t.value }
  end
threaded_map_send(meth, *args, &block)

Like Enumerable#map_send but each iteration is processed via a separate thread.

 CREDIT Sean O'Halpin
# File lib/more/facets/thread.rb, line 46
  def threaded_map_send(meth, *args, &block)
    map{ |e| Thread.new(e){ |t| t.send(meth, *args, &block) } }.map{ |t| t.value }
  end
to_elem(meth=nil)

Create Elementor.

# File lib/more/facets/elementor.rb, line 42
  def to_elem(meth=nil)
    Elementor.new(self, meth || :map)
  end