module Sequence::Functional

methods (and constants) related to functional programming

Constants

HAS_SIDE_EFFECT
NO_SIDE_EFFECT
PMETHS_REF

Public Class Methods

functions_of(obj) click to toggle source

hashes of Module (or Class, including meta-Class) to a list of method names which do or don't have side effects

# File lib/sequence/functional.rb, line 49
def functions_of(obj)
  published=Set[public_methods_of(obj).delete_if{|name| /[!=]$/===name}]
  result=[]
  list=class<<obj; ancestors.unshift self end
  list.each{|mod| 
    result.push( *published&NO_SIDE_EFFECT[mod] )
    published&=Set[*NO_SIDE_EFFECT[mod]+HAS_SIDE_EFFECT[mod]]
  }
  return result
end
is_function?(obj,name) click to toggle source
# File lib/sequence/functional.rb, line 77
def is_function?(obj,name)
  list=class<<obj; ancestors.unshift self end
  list.each{|mod| 
    return true if NO_SIDE_EFFECT[mod].include? name
    return false if HAS_SIDE_EFFECT[mod].include? name
  }
  return false
end
is_maybe_function?(obj,name) click to toggle source
# File lib/sequence/functional.rb, line 90
def is_maybe_function?(obj,name)
  list=class<<obj; ancestors.unshift self end
  list.each{|mod| 
    return true if NO_SIDE_EFFECT[mod].include? name
    return false if HAS_SIDE_EFFECT[mod].include? name
  } 
  return true
end
is_maybe_not_function?(obj,name) click to toggle source
# File lib/sequence/functional.rb, line 86
def is_maybe_not_function?(obj,name)
  !is_function(obj,name)
end
is_not_function?(obj,name) click to toggle source
# File lib/sequence/functional.rb, line 99
def is_not_function?(obj,name)
  !is_maybe_function(obj,name)
end
maybe_functions_of(obj) click to toggle source
# File lib/sequence/functional.rb, line 60
def maybe_functions_of(obj)
  published=public_methods_of(obj).delete_if{|name| /[!=]$/===name}
  result=[]
  list=class<<obj; ancestors.unshift self end
  list.each{|mod| 
    published.delete_if{|name| 
      NO_SIDE_EFFECT[mod].include? name || 
      HAS_SIDE_EFFECT[mod].include? name
    }
  }
  return result
end
nonfunctions_of(obj) click to toggle source
# File lib/sequence/functional.rb, line 73
def nonfunctions_of(obj)
  public_methods_of(obj)-functions_of(obj)-maybe_functions_of(obj)
end
public_methods_of(obj) click to toggle source
# File lib/sequence/functional.rb, line 104
def public_methods_of(obj)
  PMETHS_REF.bind(obj).call
end