trither 0.4.0 → 0.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/trither.rb +14 -0
- data/lib/trither/either.rb +2 -8
- data/lib/trither/option.rb +17 -5
- data/lib/trither/try.rb +20 -10
- data/lib/trither/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: 9279f7b994e89ec63bc8e681fb28effea01466dc
|
4
|
+
data.tar.gz: e100b0379b2dc1b9b4cbc29d0f651cd2d41e3df8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9aaa1d0f041bbc8a15d8201738750f468cf7adfc13feca82a2d4c54019228fe09efacbf7b8de5b9e4789616c1193dbe49c356bfe3c33e86fe07f4e02d29f367
|
7
|
+
data.tar.gz: c6675405ddeef783c8b93b73504d3c434695107f320b8d726eef5202468c42fef8242b387657e2fe2e2cda10d7ac6284a71c8c1412054f8eb4cf6c2b0f8d98e0
|
data/lib/trither.rb
CHANGED
@@ -1,4 +1,18 @@
|
|
1
1
|
require 'trither/version'
|
2
|
+
|
3
|
+
module Trither
|
4
|
+
class Box
|
5
|
+
def initialize(value)
|
6
|
+
@value = value
|
7
|
+
end
|
8
|
+
|
9
|
+
def ==(other)
|
10
|
+
(self.class == other.class) &&
|
11
|
+
(@value == other.instance_variable_get('@value'))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
2
16
|
require 'trither/try'
|
3
17
|
require 'trither/either'
|
4
18
|
require 'trither/option'
|
data/lib/trither/either.rb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
1
|
module Either
|
2
|
-
class
|
3
|
-
def initialize(value)
|
4
|
-
@value = value
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
class Left < Base
|
2
|
+
class Left < Trither::Box
|
9
3
|
def left?
|
10
4
|
true
|
11
5
|
end
|
@@ -27,7 +21,7 @@ module Either
|
|
27
21
|
end
|
28
22
|
end
|
29
23
|
|
30
|
-
class Right <
|
24
|
+
class Right < Trither::Box
|
31
25
|
def left?
|
32
26
|
false
|
33
27
|
end
|
data/lib/trither/option.rb
CHANGED
@@ -12,6 +12,10 @@ module Option
|
|
12
12
|
true
|
13
13
|
end
|
14
14
|
|
15
|
+
def self.filter
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
15
19
|
def self.fetch(default)
|
16
20
|
default
|
17
21
|
end
|
@@ -24,20 +28,24 @@ module Option
|
|
24
28
|
self
|
25
29
|
end
|
26
30
|
|
27
|
-
def self.
|
31
|
+
def self.or_else
|
28
32
|
yield
|
29
33
|
end
|
30
|
-
end
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
@value = value
|
35
|
+
def self.get_or_else
|
36
|
+
yield
|
35
37
|
end
|
38
|
+
end
|
36
39
|
|
40
|
+
class Some < Trither::Box
|
37
41
|
def empty?
|
38
42
|
false
|
39
43
|
end
|
40
44
|
|
45
|
+
def filter
|
46
|
+
yield(@value) ? self : None
|
47
|
+
end
|
48
|
+
|
41
49
|
def fetch(_default)
|
42
50
|
@value
|
43
51
|
end
|
@@ -55,6 +63,10 @@ module Option
|
|
55
63
|
end
|
56
64
|
end
|
57
65
|
|
66
|
+
def or_else
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
58
70
|
def get_or_else
|
59
71
|
@value
|
60
72
|
end
|
data/lib/trither/try.rb
CHANGED
@@ -5,17 +5,15 @@ module Try
|
|
5
5
|
Failure.new(error)
|
6
6
|
end
|
7
7
|
|
8
|
-
class
|
9
|
-
def initialize(value)
|
10
|
-
@value = value
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class Failure < Base
|
8
|
+
class Failure < Trither::Box
|
15
9
|
def failure?
|
16
10
|
true
|
17
11
|
end
|
18
12
|
|
13
|
+
def filter
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
19
17
|
def flat_map
|
20
18
|
self
|
21
19
|
end
|
@@ -25,7 +23,11 @@ module Try
|
|
25
23
|
end
|
26
24
|
|
27
25
|
def fail_map
|
28
|
-
Failure.new(
|
26
|
+
Failure.new yield(@value)
|
27
|
+
end
|
28
|
+
|
29
|
+
def or_else
|
30
|
+
yield @value
|
29
31
|
end
|
30
32
|
|
31
33
|
def get_or_else
|
@@ -33,23 +35,31 @@ module Try
|
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
class Success <
|
38
|
+
class Success < Trither::Box
|
37
39
|
def failure?
|
38
40
|
false
|
39
41
|
end
|
40
42
|
|
43
|
+
def filter
|
44
|
+
yield(@value) ? self : Failure.new(Option::None)
|
45
|
+
end
|
46
|
+
|
41
47
|
def flat_map
|
42
48
|
yield @value
|
43
49
|
end
|
44
50
|
|
45
51
|
def map
|
46
|
-
Success.new(
|
52
|
+
Success.new yield(@value)
|
47
53
|
end
|
48
54
|
|
49
55
|
def fail_map
|
50
56
|
self
|
51
57
|
end
|
52
58
|
|
59
|
+
def or_else
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
53
63
|
def get_or_else
|
54
64
|
@value
|
55
65
|
end
|
data/lib/trither/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trither
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lyall Jonathan Di Trapani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04
|
11
|
+
date: 2016-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|