rfunk 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rfunk/attribute/attribute_definition.rb +1 -1
- data/lib/rfunk/attribute/attribute_function.rb +2 -2
- data/lib/rfunk/attribute/function.rb +5 -5
- data/lib/rfunk/either/either.rb +23 -21
- data/lib/rfunk/either/failure.rb +5 -3
- data/lib/rfunk/either/success.rb +4 -2
- data/lib/rfunk/lazy.rb +5 -3
- data/lib/rfunk/maybe/none.rb +6 -4
- data/lib/rfunk/maybe/option.rb +16 -14
- data/lib/rfunk/maybe/some.rb +8 -6
- data/lib/rfunk/tuple.rb +6 -4
- data/lib/rfunk/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0eb1a32853f93bfe2ebaa1548e4629afde49442
|
4
|
+
data.tar.gz: 3eb3bf01eadc2ad1821d09dc50583e7d9ada2b75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75ebb4f28b6332111a18fede512cdf3e584874ec668b025a5789b859caee509dc2f496e9d0d247ccabac42bb15a177497c2fdff84a374eb20b26c684924e1574
|
7
|
+
data.tar.gz: 99873499286bf55002c93c4b0a314050cfc0d62f3f135ba3ce5ff951ff5ad4de6f2279555fc65d483e9b0ca00c2934c8f992ded2ab8a6a2ca50beac0ac688623
|
@@ -15,9 +15,9 @@ module RFunk
|
|
15
15
|
case definition
|
16
16
|
when Hash
|
17
17
|
return_type = RFunk::TypeAnnotation.new(definition.values.first.to_s)
|
18
|
-
RFunk
|
18
|
+
RFunk.tuple(definition.keys.first, return_type)
|
19
19
|
else
|
20
|
-
RFunk
|
20
|
+
RFunk.tuple(definition)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -18,7 +18,7 @@ module RFunk
|
|
18
18
|
self.variables = variables.merge(options)
|
19
19
|
end
|
20
20
|
else
|
21
|
-
RFunk
|
21
|
+
RFunk.some(RFunk.some(variables)[options])
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -47,7 +47,7 @@ module RFunk
|
|
47
47
|
execute_body_block
|
48
48
|
else
|
49
49
|
validate_return_type(return_value)
|
50
|
-
RFunk
|
50
|
+
RFunk.option(return_value)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -67,7 +67,7 @@ module RFunk
|
|
67
67
|
def execute_body_block
|
68
68
|
execute_block pre_block, RFunk::PreConditionError
|
69
69
|
|
70
|
-
RFunk
|
70
|
+
RFunk.option(instance_eval(&body_block)).tap do |body|
|
71
71
|
execute_block post_block, RFunk::PostConditionError
|
72
72
|
validate_return_type(body)
|
73
73
|
end
|
@@ -79,7 +79,7 @@ module RFunk
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def error_checking
|
82
|
-
RFunk
|
82
|
+
RFunk.lazy(-> { RFunk::ErrorChecking.new }).value
|
83
83
|
end
|
84
84
|
|
85
85
|
def validate_return_type(return_value)
|
@@ -91,7 +91,7 @@ module RFunk
|
|
91
91
|
def validate_parameter_types(*args)
|
92
92
|
values = args.zip(type_annotation.parameters)
|
93
93
|
values.each_with_index do |v, i|
|
94
|
-
tuple = RFunk
|
94
|
+
tuple = RFunk.tuple(*v)
|
95
95
|
error_checking.raise_expected_parameter_type(i + 1, tuple.value(0), tuple.value(1))
|
96
96
|
end
|
97
97
|
end
|
data/lib/rfunk/either/either.rb
CHANGED
@@ -9,7 +9,7 @@ module RFunk
|
|
9
9
|
when RFunk::Some, RFunk::None
|
10
10
|
value
|
11
11
|
else
|
12
|
-
RFunk
|
12
|
+
RFunk.option(value)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -22,31 +22,33 @@ module RFunk
|
|
22
22
|
attr_reader :value
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
class << self
|
26
|
+
def either(value)
|
27
|
+
if lambda?(value)
|
28
|
+
either_with_lambda(value)
|
29
|
+
else
|
30
|
+
either_with_value(value)
|
31
|
+
end
|
30
32
|
end
|
31
|
-
end
|
32
33
|
|
33
|
-
|
34
|
+
private
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
def lambda?(value)
|
37
|
+
value.respond_to?(:lambda?) && value.lambda?
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def either_with_lambda(lambda)
|
41
|
+
RFunk.success(lambda.call)
|
42
|
+
rescue => e
|
43
|
+
RFunk.failure(e)
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
def either_with_value(value)
|
47
|
+
if value
|
48
|
+
RFunk.success(value)
|
49
|
+
else
|
50
|
+
RFunk.failure(value)
|
51
|
+
end
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
data/lib/rfunk/either/failure.rb
CHANGED
@@ -9,11 +9,13 @@ module RFunk
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def or(value)
|
12
|
-
RFunk
|
12
|
+
RFunk.failure(value)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
class << self
|
17
|
+
def failure(value)
|
18
|
+
RFunk::Failure.new(value)
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
data/lib/rfunk/either/success.rb
CHANGED
data/lib/rfunk/lazy.rb
CHANGED
@@ -8,7 +8,7 @@ module RFunk
|
|
8
8
|
|
9
9
|
def value
|
10
10
|
atomic.update { @value ||= lambda.call.tap { self.created = true } }
|
11
|
-
RFunk
|
11
|
+
RFunk.option(atomic.value)
|
12
12
|
end
|
13
13
|
|
14
14
|
def created?
|
@@ -21,7 +21,9 @@ module RFunk
|
|
21
21
|
attr_accessor :created
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
class << self
|
25
|
+
def lazy(lambda)
|
26
|
+
RFunk::Lazy.new(lambda)
|
27
|
+
end
|
26
28
|
end
|
27
29
|
end
|
data/lib/rfunk/maybe/none.rb
CHANGED
@@ -3,11 +3,11 @@ module RFunk
|
|
3
3
|
include Singleton
|
4
4
|
|
5
5
|
def value(default = None())
|
6
|
-
RFunk
|
6
|
+
RFunk.option(default)
|
7
7
|
end
|
8
8
|
|
9
9
|
def or(other)
|
10
|
-
RFunk
|
10
|
+
RFunk.option(other)
|
11
11
|
end
|
12
12
|
|
13
13
|
def pipe(&_block)
|
@@ -41,7 +41,9 @@ module RFunk
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
class << self
|
45
|
+
def none(value = nil)
|
46
|
+
RFunk.option(value)
|
47
|
+
end
|
46
48
|
end
|
47
49
|
end
|
data/lib/rfunk/maybe/option.rb
CHANGED
@@ -9,23 +9,25 @@ module RFunk
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
value
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
class << self
|
13
|
+
def option(value)
|
14
|
+
if [RFunk::Some, RFunk::None].map { |t| value.is_a?(t) }.any?
|
15
|
+
value
|
16
|
+
elsif nothing?(value)
|
17
|
+
RFunk::None.instance
|
18
|
+
else
|
19
|
+
RFunk::Some.new(value)
|
20
|
+
end
|
19
21
|
end
|
20
|
-
end
|
21
22
|
|
22
|
-
|
23
|
+
private
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def nothing?(value)
|
26
|
+
value.nil? || empty?(value) || value == RFunk::None.instance
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
def empty?(value)
|
30
|
+
value.respond_to?(:empty?) && value.empty?
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
data/lib/rfunk/maybe/some.rb
CHANGED
@@ -6,7 +6,7 @@ module RFunk
|
|
6
6
|
@value = value
|
7
7
|
end
|
8
8
|
|
9
|
-
def value(_ = RFunk
|
9
|
+
def value(_ = RFunk.none)
|
10
10
|
@value
|
11
11
|
end
|
12
12
|
|
@@ -16,16 +16,16 @@ module RFunk
|
|
16
16
|
|
17
17
|
def pipe(&block)
|
18
18
|
return self if block.nil?
|
19
|
-
RFunk
|
19
|
+
RFunk.option(yield value)
|
20
20
|
end
|
21
21
|
|
22
22
|
def method_missing(method, *arguments, &block)
|
23
|
-
RFunk
|
23
|
+
RFunk.option(value.send(method, *arguments, &block))
|
24
24
|
end
|
25
25
|
|
26
26
|
def ==(other)
|
27
27
|
return false unless self.class == other.class
|
28
|
-
value ==
|
28
|
+
value == RFunk.option(other).value
|
29
29
|
end
|
30
30
|
|
31
31
|
def <=>(other)
|
@@ -53,7 +53,9 @@ module RFunk
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
|
57
|
-
|
56
|
+
class << self
|
57
|
+
def some(value)
|
58
|
+
RFunk.option(value)
|
59
|
+
end
|
58
60
|
end
|
59
61
|
end
|
data/lib/rfunk/tuple.rb
CHANGED
@@ -9,9 +9,9 @@ module RFunk
|
|
9
9
|
index = args[0]
|
10
10
|
|
11
11
|
if args.length == 1
|
12
|
-
RFunk
|
12
|
+
RFunk.option(values[index])
|
13
13
|
else
|
14
|
-
self.class.new(values.dup.tap { |v| v[index] = RFunk
|
14
|
+
self.class.new(values.dup.tap { |v| v[index] = RFunk.option(args[1]) })
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -20,7 +20,9 @@ module RFunk
|
|
20
20
|
attr_reader :values
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
class << self
|
24
|
+
def tuple(*values)
|
25
|
+
RFunk::Tuple.new(values)
|
26
|
+
end
|
25
27
|
end
|
26
28
|
end
|
data/lib/rfunk/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rfunk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Falkowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ice_nine
|