logical_lambda 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/logical_lambda.rb +63 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 584d34f93659b362b6af1b151ee016fc508bc708
|
4
|
+
data.tar.gz: 1d0f0666c425de14587125201bd89b5388a47f19
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d4ba10668a152674bc5ec820df7d581b509c788eaa8cbc14fde0f3fc198d904282e8b92aabb8b76637d6293cf9914c80bc1e02daad50a1d4f6109e3945fc492
|
7
|
+
data.tar.gz: 32acde56e3b8c6d78644e85ee5e3a75a7c44e37e123a08cce2390b866dbffb9b7b75e1e7954376d195d5cf0ee0cd9da4d8a600eecc69e62ca8a97c137689b84f
|
@@ -0,0 +1,63 @@
|
|
1
|
+
|
2
|
+
class LogicalLambda < Proc
|
3
|
+
|
4
|
+
# AND
|
5
|
+
def &(other)
|
6
|
+
LogicalLambda.new {|*args| call(*args) && other.call(*args) }
|
7
|
+
end
|
8
|
+
|
9
|
+
# Override the negative and bang as in -is_true !is_true
|
10
|
+
def !@; LogicalLambda.new {|*args| !call(*args)}; end
|
11
|
+
#def -@; LogicalLambda.new {|*args| !call(*args)}; end
|
12
|
+
#def ~@; LogicalLambda.new {|*args| !call(*args)}; end
|
13
|
+
|
14
|
+
# OR
|
15
|
+
def |(other)
|
16
|
+
LogicalLambda.new {|*args| call(*args) || other.call(*args) }
|
17
|
+
end
|
18
|
+
|
19
|
+
############# Comparables #############
|
20
|
+
|
21
|
+
def self.define_comparable(compare_method)
|
22
|
+
define_method compare_method do |other|
|
23
|
+
if other.respond_to?(:call)
|
24
|
+
LogicalLambda.new {|*args| call(*args).send(compare_method, other.call(*args)) }
|
25
|
+
else
|
26
|
+
# Must not be a block
|
27
|
+
LogicalLambda.new {|*args| call(*args).send(compare_method, other) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
define_comparable :==
|
33
|
+
define_comparable :!=
|
34
|
+
define_comparable :<
|
35
|
+
define_comparable :>
|
36
|
+
define_comparable :<=
|
37
|
+
define_comparable :>=
|
38
|
+
|
39
|
+
# def ==(other)
|
40
|
+
# LogicalLambda.new {|*args| call(*args) == other.call(*args) }
|
41
|
+
# end
|
42
|
+
|
43
|
+
# def !=(other)
|
44
|
+
# LogicalLambda.new {|*args| call(*args) != other.call(*args) }
|
45
|
+
# end
|
46
|
+
|
47
|
+
# def >(other)
|
48
|
+
# LogicalLambda.new {|*args| call(*args) > other.call(*args) }
|
49
|
+
# end
|
50
|
+
|
51
|
+
# def <(other)
|
52
|
+
# LogicalLambda.new {|*args| call(*args) < other.call(*args) }
|
53
|
+
# end
|
54
|
+
|
55
|
+
# def >=(other)
|
56
|
+
# LogicalLambda.new {|*args| call(*args) >= other.call(*args) }
|
57
|
+
# end
|
58
|
+
|
59
|
+
# def <=(other)
|
60
|
+
# LogicalLambda.new {|*args| call(*args) <= other.call(*args) }
|
61
|
+
# end
|
62
|
+
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logical_lambda
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tyler Roberts
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: See github page for more info.
|
14
|
+
email: code@polar-concepts.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/logical_lambda.rb
|
20
|
+
homepage: https://github.com/bdevel/logical_lambda
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Ruby library to combine Procs into logic chains.
|
44
|
+
test_files: []
|
45
|
+
has_rdoc:
|