module Functions

Private Instance Methods

as_promise() click to toggle source
# File lib/totally_lazy/functions.rb, line 86
def as_promise
  -> (fn) { Concurrent::Promise.new { fn.() } }
end
call_concurrently(sequence_of_fn) click to toggle source
# File lib/totally_lazy/functions.rb, line 69
def call_concurrently(sequence_of_fn)
  pool = Concurrent::CachedThreadPool.new
  begin
    call_concurrently_with_pool(sequence_of_fn, pool)
  ensure
    pool.shutdown
  end
end
call_concurrently_with_pool(sequence_of_fn, pool) click to toggle source
# File lib/totally_lazy/functions.rb, line 78
def call_concurrently_with_pool(sequence_of_fn, pool)
  sequence_of_fn.
      map(as_promise).
      map(execute_with(pool)).
      realise.
      map(realise_promise)
end
call_fn() click to toggle source
# File lib/totally_lazy/functions.rb, line 53
def call_fn
  ->(fn) { fn.() }
end
call_raises(e) click to toggle source
# File lib/totally_lazy/functions.rb, line 47
def call_raises(e)
  -> { raise e }
end
Also aliased as: call_throws
call_throws(e)
Alias for: call_raises
constant(value) click to toggle source
# File lib/totally_lazy/functions.rb, line 39
def constant(value)
  ->(_) { value }
end
defer_apply(fn, value) click to toggle source
# File lib/totally_lazy/functions.rb, line 65
def defer_apply(fn, value)
  ->() { fn.(value) }
end
defer_return(fn) click to toggle source
# File lib/totally_lazy/functions.rb, line 61
def defer_return(fn)
  ->(value) { defer_apply(fn, value) }
end
execute_with(pool) click to toggle source
# File lib/totally_lazy/functions.rb, line 90
def execute_with(pool)
  -> (promise) {
    pool.post { promise.execute }
    promise
  }
end
flip(fn) click to toggle source
# File lib/totally_lazy/functions.rb, line 57
def flip(fn)
  ->(a, b) { fn.(b, a) }
end
get_left() click to toggle source
# File lib/totally_lazy/functions.rb, line 101
def get_left
  ->(either) { either.left_value }
end
get_right() click to toggle source
# File lib/totally_lazy/functions.rb, line 105
def get_right
  ->(either) { either.right_value }
end
identity() click to toggle source
# File lib/totally_lazy/functions.rb, line 43
def identity
  -> (a) { a }
end
ignore_and_return(value) click to toggle source
# File lib/totally_lazy/functions.rb, line 31
def ignore_and_return(value)
  returns1(value)
end
monoid(fn, id) click to toggle source
# File lib/totally_lazy/functions.rb, line 20
def monoid(fn, id)
  fn.define_singleton_method(:identity) do
    id
  end
  fn
end
realise_promise() click to toggle source
# File lib/totally_lazy/functions.rb, line 97
def realise_promise
  ->(promise) { promise.value! }
end
returns(value) click to toggle source
# File lib/totally_lazy/functions.rb, line 27
def returns(value)
  -> { value }
end
returns1(value) click to toggle source
# File lib/totally_lazy/functions.rb, line 35
def returns1(value)
  constant(value)
end