module Speculation::Utils

@private

Public Class Methods

conj(a, b) click to toggle source
# File lib/speculation/utils.rb, line 32
def self.conj(a, b)
  case a
  when Array, Set
    a + [b]
  when Hash
    case b
    when Array then a.merge(b[0] => b[1])
    else            a.merge(b)
    end
  else raise ArgumentError, "#{a}: must be an Array, Set or Hash"
  end
end
constantly(x) click to toggle source
# File lib/speculation/utils.rb, line 12
def self.constantly(x)
  ->(*) { x }
end
empty(coll) click to toggle source
# File lib/speculation/utils.rb, line 24
def self.empty(coll)
  coll.class.new
end
ident?(x) click to toggle source
# File lib/speculation/utils.rb, line 16
def self.ident?(x)
  x.is_a?(Symbol) || x.is_a?(MethodIdentifier)
end
into(to, from) click to toggle source
# File lib/speculation/utils.rb, line 28
def self.into(to, from)
  from.reduce(to) { |memo, obj| conj(memo, obj) }
end
itself(x) click to toggle source
# File lib/speculation/utils.rb, line 8
def self.itself(x)
  x
end
method?(x) click to toggle source
# File lib/speculation/utils.rb, line 20
def self.method?(x)
  x.is_a?(Method) || x.is_a?(UnboundMethod)
end
sort_descending(coll) { |b| ... } click to toggle source
# File lib/speculation/utils.rb, line 45
def self.sort_descending(coll)
  coll.sort { |a, b| yield(b) <=> yield(a) }
end