monadify 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -3
- data/lib/monadify/option/none.rb +4 -0
- data/lib/monadify/option/option.rb +2 -0
- data/lib/monadify/option/some.rb +14 -3
- data/lib/monadify/version.rb +1 -1
- data/monadify.gemspec +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: 73280a168e2d8c9f1946503d3f1dbc21499e1c75
|
4
|
+
data.tar.gz: d1c1f2d86c5f91d65a4a7488de0c8d16c7d30c0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be81d9643579b3cbd8fb6113fb182c0215d2688e4dc2c0c65ae91b98c22cc6e6ff0169a828c21787af5556d7a6231739e39a39a27372db4ca434074822bf2ecf
|
7
|
+
data.tar.gz: 8d3dd60411e830b4c6bd542bb11815f49d9d7ec24424c75c292b2fde3b4d3fcf1755a1545a6dcd4c8bf3c57252197051397b4fad12eea4acaebc3a83a2a237c7
|
data/README.md
CHANGED
data/lib/monadify/option/none.rb
CHANGED
@@ -6,6 +6,8 @@ class Monadify::None < Monadify::Option
|
|
6
6
|
def map
|
7
7
|
begin
|
8
8
|
yield nil
|
9
|
+
rescue ArgumentError, NameError
|
10
|
+
raise
|
9
11
|
rescue
|
10
12
|
end
|
11
13
|
self
|
@@ -14,6 +16,8 @@ class Monadify::None < Monadify::Option
|
|
14
16
|
def flatmap
|
15
17
|
begin
|
16
18
|
yield nil
|
19
|
+
rescue ArgumentError, NameError
|
20
|
+
raise
|
17
21
|
rescue
|
18
22
|
end
|
19
23
|
self
|
data/lib/monadify/option/some.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
class NotAnOptionError < TypeError; end
|
2
|
+
|
1
3
|
class Monadify::Some < Monadify::Option
|
2
4
|
attr_reader :value
|
3
5
|
|
@@ -17,6 +19,8 @@ class Monadify::Some < Monadify::Option
|
|
17
19
|
else
|
18
20
|
Monadify::Some.new(return_val)
|
19
21
|
end
|
22
|
+
rescue ArgumentError, NameError, TypeError
|
23
|
+
raise
|
20
24
|
rescue
|
21
25
|
Monadify::None.new
|
22
26
|
end
|
@@ -25,11 +29,18 @@ class Monadify::Some < Monadify::Option
|
|
25
29
|
def flatmap
|
26
30
|
begin
|
27
31
|
return_option = yield value
|
28
|
-
|
29
|
-
|
30
|
-
|
32
|
+
case return_option
|
33
|
+
when Monadify::None
|
34
|
+
return_option
|
35
|
+
when Monadify::Some
|
31
36
|
Monadify::Some.new(return_option.value)
|
37
|
+
else
|
38
|
+
raise NotAnOptionError
|
32
39
|
end
|
40
|
+
rescue NotAnOptionError
|
41
|
+
raise ArgumentError, 'The block should return an Option'
|
42
|
+
rescue ArgumentError, NameError, TypeError
|
43
|
+
raise
|
33
44
|
rescue
|
34
45
|
Monadify::None.new
|
35
46
|
end
|
data/lib/monadify/version.rb
CHANGED
data/monadify.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['mail@saklee.net', 'mail@linhbui.me']
|
11
11
|
|
12
12
|
spec.summary = %q{Bringing Functional Monads to Ruby}
|
13
|
-
spec.description = %q{
|
13
|
+
spec.description = %q{In alpha development. Currently only Option is implemented.}
|
14
14
|
spec.homepage = 'https://github.com/ulysses-sl/monadify'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monadify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sak Lee
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
-
description:
|
56
|
+
description: In alpha development. Currently only Option is implemented.
|
57
57
|
email:
|
58
58
|
- mail@saklee.net
|
59
59
|
- mail@linhbui.me
|