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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2ec9d8bb76073063a74ecad037545bf191d6432
4
- data.tar.gz: c81beeaea402eeb77acecc33b7484fe2fdc2eb5d
3
+ metadata.gz: 9279f7b994e89ec63bc8e681fb28effea01466dc
4
+ data.tar.gz: e100b0379b2dc1b9b4cbc29d0f651cd2d41e3df8
5
5
  SHA512:
6
- metadata.gz: afeb84a64f378477e98ab3deeff6d88124a4da170a50c050c0adff317cb161f0780640518c5d87b85248cbef3adc3e1582061c759bcd93f1bfc84fa0374c755b
7
- data.tar.gz: 45f9d9d7b3311e63ebca3b7911260232181a67799cd83f8807e15d8c3b3fa028fbb422da3a69cd0997e7c9ce9c0a5434699d2899b0a5e0e4a735980a3ee2bea3
6
+ metadata.gz: a9aaa1d0f041bbc8a15d8201738750f468cf7adfc13feca82a2d4c54019228fe09efacbf7b8de5b9e4789616c1193dbe49c356bfe3c33e86fe07f4e02d29f367
7
+ data.tar.gz: c6675405ddeef783c8b93b73504d3c434695107f320b8d726eef5202468c42fef8242b387657e2fe2e2cda10d7ac6284a71c8c1412054f8eb4cf6c2b0f8d98e0
@@ -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'
@@ -1,11 +1,5 @@
1
1
  module Either
2
- class Base
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 < Base
24
+ class Right < Trither::Box
31
25
  def left?
32
26
  false
33
27
  end
@@ -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.get_or_else
31
+ def self.or_else
28
32
  yield
29
33
  end
30
- end
31
34
 
32
- class Some
33
- def initialize(value)
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
@@ -5,17 +5,15 @@ module Try
5
5
  Failure.new(error)
6
6
  end
7
7
 
8
- class Base
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(yield @value)
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 < Base
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(yield @value)
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
@@ -1,3 +1,3 @@
1
1
  module Trither
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
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.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-30 00:00:00.000000000 Z
11
+ date: 2016-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler