class Array

Public Instance Methods

apply(to) click to toggle source
# File lib/ext/array.rb, line 70
def apply(to)
  map do |m|
    if m.m?
      to.send(m)
    else
      m.s!.walk(to)
    end
  end
end
earliest(&block)
Alias for: return_first
filled?() click to toggle source
# File lib/ext/array.rb, line 9
def filled?() !mt? end
Also aliased as: notempty?, full?, unempty?
first!(&block)
Alias for: return_first
full?()
Alias for: filled?
hmap(&block) click to toggle source
# File lib/ext/array.rb, line 104
def hmap(&block)
  each.with_object({}, &block)
end
ll?(method, *args) click to toggle source
# File lib/ext/array.rb, line 22
def ll?(method, *args)
  all? { |o| o.send(method, *args) }
end
mall?(op, &block) click to toggle source
# File lib/ext/array.rb, line 94
def mall?(op, &block)
  if op
    all? { |item| item.send(op) }
  elsif block
    all? { |item| item.instance_exec(item, &block) }
  else
    all? { |item| item }
  end
end
mavg(&block) click to toggle source
# File lib/ext/array.rb, line 34
def mavg(&block)
  msum(&block) / size
end
meach(*args, &block) click to toggle source
# File lib/ext/array.rb, line 80
def meach(*args, &block)
  if block
    map { |item| instance_exec(item, *args, &block) }
  elsif args.size == 1
    map(&args.first.sym)
  else
    #args.each.with_object({}) do |action, o|
    #  o[action.sym] = map(&action.sym)
    #end
    method = args.shift
    map { |item| item.send(method, *args) }
  end
end
mmid(&sorter) click to toggle source
# File lib/ext/array.rb, line 38
def mmid(&sorter)
  sorted = sort(&sorter)
  length.odd? ? sorted[length / 2].f! : (sorted[length/2 - 1].f! + sorted[length/2].f!).f! / 2
end
msum(initial = 0.0, op = :+, &block) click to toggle source
# File lib/ext/array.rb, line 26
def msum(initial = 0.0, op = :+, &block)
  if block
    inject(initial) { |m, val| m.send(op, block[val]) }
  else
    map(&:f!).inject(initial, op)
  end
end
msym() click to toggle source
# File lib/ext/array.rb, line 68
def msym() map(&:sym) end
no?(method, *args) click to toggle source
# File lib/ext/array.rb, line 18
def no?(method, *args)
  none? { |o| o.send(method, *args) }
end
notempty?()
Alias for: filled?
ny?(method, *args) click to toggle source
# File lib/ext/array.rb, line 14
def ny?(method, *args)
  any? { |o| o.send(method, *args) }
end
realize!() click to toggle source
# File lib/ext/array.rb, line 55
def realize!
  empty? ? nil : self
end
return_first(&block) click to toggle source
# File lib/ext/array.rb, line 59
def return_first(&block)
  returned = nil
  each { |item| break if (returned = block.call(item)) }
  returned
end
Also aliased as: earliest, first!
sequester!(crush = true) click to toggle source
# File lib/ext/array.rb, line 47
def sequester!(crush = true)
  if crush
    compact.size <= 1 ? compact.first : self
  else
    size <= 1 ? first : self
  end
end
unempty?()
Alias for: filled?
values() click to toggle source
# File lib/ext/array.rb, line 43
def values()
  self
end