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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06eccdcb9c408c664fb41b5bc07da7ca999babed
4
- data.tar.gz: 2c5326bec81d9aaf949c1c40b7b0f36e7bd8fcfa
3
+ metadata.gz: 73280a168e2d8c9f1946503d3f1dbc21499e1c75
4
+ data.tar.gz: d1c1f2d86c5f91d65a4a7488de0c8d16c7d30c0b
5
5
  SHA512:
6
- metadata.gz: b7ec3925f3e9060774b29e79d599a47d16fa564c6a21b1776048372e1e23df65b3e7eec7035c74150a77e8b43e68b6064d65f1f791d45aa80c8f618b216197d3
7
- data.tar.gz: fd0b3889c22e2f2aa43b37d16d8be9378746056d744317e0e6457f23a24bfa4f89249e36415a19160d3ceef07f71bc29b0a6e532321a178f10a6c59149d4190d
6
+ metadata.gz: be81d9643579b3cbd8fb6113fb182c0215d2688e4dc2c0c65ae91b98c22cc6e6ff0169a828c21787af5556d7a6231739e39a39a27372db4ca434074822bf2ecf
7
+ data.tar.gz: 8d3dd60411e830b4c6bd542bb11815f49d9d7ec24424c75c292b2fde3b4d3fcf1755a1545a6dcd4c8bf3c57252197051397b4fad12eea4acaebc3a83a2a237c7
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Monadify
2
2
 
3
- NOTE: In alpha development
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ NOTE: In alpha development. Currently only Option is implemented.
6
4
 
7
5
  ## Installation
8
6
 
@@ -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
@@ -8,6 +8,8 @@ class Monadify::Option
8
8
  else
9
9
  Monadify::Some.new(val)
10
10
  end
11
+ rescue ArgumentError, NameError, TypeError
12
+ raise
11
13
  rescue
12
14
  Monadify::None.new
13
15
  end
@@ -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
- if return_option.empty?
29
- Monadify::None.new
30
- else
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
@@ -1,3 +1,3 @@
1
1
  module Monadify
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
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{in alpha}
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.0
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: in alpha
56
+ description: In alpha development. Currently only Option is implemented.
57
57
  email:
58
58
  - mail@saklee.net
59
59
  - mail@linhbui.me