module ComposeEverything::FunctionalGoodies

Public Instance Methods

compose(with) click to toggle source
# File lib/composeeverything/functionalgoodies.rb, line 2
def compose(with)
  ->(x) { with[self[x]] }
end
f_add(idx, output) click to toggle source
# File lib/composeeverything/functionalgoodies.rb, line 29
def f_add(idx, output)
  union ->(x) {
    output if x == idx
  }
end
f_delete(a) click to toggle source
# File lib/composeeverything/functionalgoodies.rb, line 48
def f_delete(a)
  remove ->(x) {
    a
  }
end
f_filter(func) click to toggle source
# File lib/composeeverything/functionalgoodies.rb, line 16
def f_filter(func)
  filter_indexed ->(idx, x) {
    func[x]
  }
end
f_flat_map(func) click to toggle source
# File lib/composeeverything/functionalgoodies.rb, line 10
def f_flat_map(func)
  ->(x) {
    self[x].f_map(func)
  }
end
f_map(func) click to toggle source
# File lib/composeeverything/functionalgoodies.rb, line 6
def f_map(func)
  compose(func)
end
filter_indexed(func) click to toggle source
# File lib/composeeverything/functionalgoodies.rb, line 22
def filter_indexed(func)
  ->(x) {
    a = self[x]
    func[x, a] ? a : nil
  }
end
intersection(with) click to toggle source
# File lib/composeeverything/functionalgoodies.rb, line 35
def intersection(with)
  filter_indexed ->(idx, x) {
    x == with[idx]
  }
end
remove(removed) click to toggle source
# File lib/composeeverything/functionalgoodies.rb, line 54
def remove(removed)
  filter_indexed ->(idx, x) {
    removed[idx] != x
  }
end
union(with) click to toggle source
# File lib/composeeverything/functionalgoodies.rb, line 41
def union(with)
  ->(x) {
    a = self[x]
    y.nil? ? a : with[x]
  }
end