Class: J8::BiPredicate

Inherits:
Object show all
Includes:
Common
Defined in:
lib/j8/bi_predicate.rb

Instance Method Summary collapse

Methods included from Common

callable_from_proc, from_callable, from_callable_class, initialize, lambda?, make_lambda, raise_unless_lambda

Instance Method Details

#and(other = nil, &block) ⇒ Object



15
16
17
18
19
# File 'lib/j8/bi_predicate.rb', line 15

def and(other = nil, &block)
  callable = from_callable(other, block)

  J8::BiPredicate.new(->(o1, o2) { test(o1, o2) && callable.test(o1, o2) })
end

#negateObject



11
12
13
# File 'lib/j8/bi_predicate.rb', line 11

def negate
  J8::BiPredicate.new(->(o1, o2) { !test(o1, o2) })
end

#or(other = nil, &block) ⇒ Object



21
22
23
24
25
# File 'lib/j8/bi_predicate.rb', line 21

def or(other = nil, &block)
  callable = from_callable(other, block)

  J8::BiPredicate.new(->(o1, o2) { test(o1, o2) || callable.test(o1, o2) })
end

#test(o1, o2) ⇒ Object



7
8
9
# File 'lib/j8/bi_predicate.rb', line 7

def test(o1, o2)
  @callable.call(o1, o2)
end