trither 0.2.0 → 0.3.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 +1 -0
- data/lib/trither/either.rb +16 -0
- data/lib/trither/option.rb +54 -0
- data/lib/trither/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34ea63d76d95c6a027ec109a9ac9eadfb304f92e
|
4
|
+
data.tar.gz: 13a7149040a45cead9febb232303f2bafc0e31de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 993cb30ff85146ef4d7f3f48b609b5f1f959ff4beb739a5ee0330d8d75ebf0d3d9b4a39f40b7fad5b5a4d0b0458ceb4bc6ce4c696f3112d0717381b899016320
|
7
|
+
data.tar.gz: a24b0b2a1370e4269578e526de11a04c79c599f2c7749deb7900fbe6b94cd32764ba13a4a974c90926f386e48328b6c5152cf29a522bad1c9f85428d516bd772
|
data/lib/trither.rb
CHANGED
data/lib/trither/either.rb
CHANGED
@@ -17,6 +17,14 @@ module Either
|
|
17
17
|
def left
|
18
18
|
@value
|
19
19
|
end
|
20
|
+
|
21
|
+
def left_map
|
22
|
+
Left.new(yield @value)
|
23
|
+
end
|
24
|
+
|
25
|
+
def right_map
|
26
|
+
self
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
22
30
|
class Right < Base
|
@@ -31,5 +39,13 @@ module Either
|
|
31
39
|
def right
|
32
40
|
@value
|
33
41
|
end
|
42
|
+
|
43
|
+
def left_map
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def right_map
|
48
|
+
Right.new(yield @value)
|
49
|
+
end
|
34
50
|
end
|
35
51
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Option
|
2
|
+
def self.make(value)
|
3
|
+
if value.nil?
|
4
|
+
None
|
5
|
+
else
|
6
|
+
Some.new(value)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module None
|
11
|
+
def self.empty?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.fetch(default)
|
16
|
+
default
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.map
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.flat_map
|
24
|
+
self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Some
|
29
|
+
def initialize(value)
|
30
|
+
@value = value
|
31
|
+
end
|
32
|
+
|
33
|
+
def empty?
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
def fetch(_default)
|
38
|
+
@value
|
39
|
+
end
|
40
|
+
|
41
|
+
def map
|
42
|
+
Option.make(yield @value)
|
43
|
+
end
|
44
|
+
|
45
|
+
def flat_map
|
46
|
+
result = yield @value
|
47
|
+
if result.nil?
|
48
|
+
None
|
49
|
+
else
|
50
|
+
result
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/trither/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trither
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lyall Jonathan Di Trapani
|
@@ -56,17 +56,17 @@ dependencies:
|
|
56
56
|
name: rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Very simple implementations of Try and
|
69
|
+
description: Very simple implementations of Try, Either, and Option inspired by Scala
|
70
70
|
email:
|
71
71
|
- lj.ditrapani@gmail.com
|
72
72
|
executables: []
|
@@ -75,6 +75,7 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- lib/trither.rb
|
77
77
|
- lib/trither/either.rb
|
78
|
+
- lib/trither/option.rb
|
78
79
|
- lib/trither/try.rb
|
79
80
|
- lib/trither/version.rb
|
80
81
|
homepage: https://github.com/lj-ditrapani/trither
|
@@ -100,5 +101,5 @@ rubyforge_project:
|
|
100
101
|
rubygems_version: 2.2.2
|
101
102
|
signing_key:
|
102
103
|
specification_version: 4
|
103
|
-
summary: Simple implementations of Try and
|
104
|
+
summary: Simple implementations of Try, Either, and Option
|
104
105
|
test_files: []
|