monad-maybe 0.9.5 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afe8c9e77ea5086d445cc8de4ddf4f2e90ae1cd4
4
- data.tar.gz: ca392be8c5f236b86d92ec95140128aad505980e
3
+ metadata.gz: 98844158ce3a0e0e1dfc165e8d984a46cf0d7434
4
+ data.tar.gz: db1a6787a2e5823e8fae1154467477d38f031fd1
5
5
  SHA512:
6
- metadata.gz: 2318578beb8bbd41a9582bd3cbde2a63fb0bab2969e84340e50cc8420dfe9a1cd85b53cadd25ce2697d1c20683400d56e556426b4d8c32cd36c7cbba1cf760e1
7
- data.tar.gz: f6a5c1169b008858acef80beba3fc5d42bed319151d59256b7051863efd26ea7f0bc35cc808a0d878a0edcab7dd8693e6ab80c3f4be8e3351f38c4acd96569d1
6
+ metadata.gz: 3039effd1abcd59df0a1e695bfbc3287cc13185a41c361df105e4011a421735536c241795ba09b8f060ce82e78efe08a9a9284b08ed00d974d22ea3e3bd310a9
7
+ data.tar.gz: b7f35337ccad21f7d47d8022514fbb795e849550065f939ae7a318868070b32c291c2a4d57b8c351693098718d21a65d3f5e471b27e472d0caed58b52dc5ca6a
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
- `monad-maybe`
2
- =============
3
-
4
- An Implementation of Haskell's Maybe Mondad
5
- -------------------------------------------
6
-
7
- This is an attempt to implement Haskell's Maybe monad in a Ruby-ish way with as little monkey patching as possible.
8
-
9
- SEE ALSO
10
- ========
11
- [andand](http://)
12
- [Haskell's Maybe Monad](http://)
1
+ `monad-maybe`
2
+ =============
3
+
4
+ An Implementation of Haskell's Maybe Mondad
5
+ -------------------------------------------
6
+
7
+ This is an attempt to implement Haskell's Maybe monad in a Ruby-ish way with as little monkey patching as possible.
8
+
9
+ SEE ALSO
10
+ ========
11
+ [andand](http://)
12
+ [Haskell's Maybe Monad](http://)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.5
1
+ 0.9.7
@@ -7,8 +7,8 @@ require_relative 'maybe/list'
7
7
  # Some monkey patching and constructor methods.
8
8
  #
9
9
  module Enumerable
10
- def to_maybe
11
- first.to_maybe
10
+ def to_maybe(&blk)
11
+ first.to_maybe(&blk)
12
12
  end
13
13
 
14
14
  def maybe_map
@@ -17,8 +17,9 @@ module Enumerable
17
17
  end
18
18
 
19
19
  class Object
20
- def to_maybe
21
- Monad::Maybe::Just.new(self)
20
+ def to_maybe(&blk)
21
+ j = Monad::Maybe::Just.new(self)
22
+ blk ? j.maybe(&blk) : j
22
23
  end
23
24
 
24
25
  def maybe?
@@ -35,7 +36,7 @@ class Object
35
36
  end
36
37
 
37
38
  class NilClass
38
- def to_maybe
39
+ def to_maybe(&blk)
39
40
  Monad::Maybe::Nothing.instance
40
41
  end
41
42
  end
@@ -48,8 +49,9 @@ module Monad
48
49
  end
49
50
  end
50
51
 
51
- def maybe(obj)
52
- Monad::Maybe.return(obj)
52
+ def maybe(obj, &blk)
53
+ m = Monad::Maybe.return(obj)
54
+ blk ? m.maybe(&blk) : m
53
55
  end
54
56
 
55
57
  def just(o)
@@ -1,26 +1,26 @@
1
- require 'json'
2
-
3
- #
4
- # Adds JSON conversions to Just, Nothing, and List
5
- #
6
- module Monad
7
- module Maybe
8
- class Just
9
- def to_json(*args)
10
- value.to_json(*args)
11
- end
12
- end
13
-
14
- class Nothing
15
- def to_json(*args)
16
- 'null'
17
- end
18
- end
19
-
20
- class List
21
- def to_json(*args)
22
- to_a.to_json(*args)
23
- end
24
- end
25
- end
26
- end
1
+ require 'json'
2
+
3
+ #
4
+ # Adds JSON conversions to Just, Nothing, and List
5
+ #
6
+ module Monad
7
+ module Maybe
8
+ class Just
9
+ def to_json(*args)
10
+ value.to_json(*args)
11
+ end
12
+ end
13
+
14
+ class Nothing
15
+ def to_json(*args)
16
+ 'null'
17
+ end
18
+ end
19
+
20
+ class List
21
+ def to_json(*args)
22
+ to_a.to_json(*args)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -25,10 +25,6 @@ module Monad
25
25
  true
26
26
  end
27
27
 
28
- def maybe(&blk)
29
- bind(blk)
30
- end
31
-
32
28
  def bind(fn)
33
29
  fn[@value].to_maybe
34
30
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "monad-maybe"
8
- s.version = "0.9.5"
8
+ s.version = "0.9.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Delon Newman"]
12
- s.date = "2013-06-20"
12
+ s.date = "2013-07-16"
13
13
  s.description = "This is an attempt to implement Haskell's Maybe monad in a Ruby-ish way."
14
14
  s.email = "delon.newman@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -79,6 +79,15 @@ class MaybeTest < Test::Unit::TestCase
79
79
  end
80
80
  end
81
81
 
82
+ def test_to_maybe_blocks
83
+ 1.to_maybe { |v| assert_equal 1, v }
84
+
85
+ assert_nothing_raised do
86
+ nil.to_maybe { raise Exception, "This should not run" }
87
+ end
88
+ end
89
+
90
+
82
91
  def test_maybe_block_return_value_and_type
83
92
  m = maybe(1).maybe { |n| n + 1 }
84
93
  assert_equal 2, m.value
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monad-maybe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delon Newman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-20 00:00:00.000000000 Z
11
+ date: 2013-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jeweler