ribimaybe 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +4 -3
- data/lib/ribimaybe.rb +3 -32
- data/lib/version.rb +1 -1
- data/spec/applicative_functor_spec.rb +8 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Y2ZiYjVmMzM2NTJkMmRiNWFiNmNmNDIxMzRmN2Y3YWYxNTFmZTJkMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDM2NTVjY2Y1NTI5NzZiZTU0MjdmYTAyYmZkZDgyY2JkNTI0NTM4MQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2ZlNGY0MDU0Y2QzOGUzMDE2NDk3NDJhZDI2M2Q5Nzk0YTk5Zjc3YzI1ZDA1
|
10
|
+
YzMzZWZmNmJhOTllOGIzZWZkYzE3ZjhjNGFhNDhiY2Q3ODU1NTU4NTJkNDFj
|
11
|
+
OGI2NzBlM2MwZjZmZjRmNTgxOWYxODA0MTEyMmFkZTJkM2M4NDk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODExNTFhMDIyNDQyOWE3ZTY0YzJkM2QzMGUxZjQ5ZGFjZjllMjBkZTA3Mzc3
|
14
|
+
NDk0MWFhNTc3NGVjMmU4OTI4YWY3YmU2ODcwZmZlMTU1MDg2NWU2OTkyMWY3
|
15
|
+
NzRlNjhmYjkzNWI5MzcyMDMyMTgyYzZjMzE5NTQxYzNhMTczYTY=
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Ribimaybe
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/ribimaybe.svg)](http://badge.fury.io/rb/ribimaybe)
|
3
4
|
[![Travis](https://travis-ci.org/unsymbol/ribimaybe.svg?branch=master)](http://travis-ci.org/unsymbol/ribimaybe)
|
4
5
|
[![Code Climate](https://codeclimate.com/github/unsymbol/ribimaybe.png)](https://codeclimate.com/github/unsymbol/ribimaybe)
|
5
6
|
|
@@ -59,9 +60,9 @@ Nothing.map { |x| x * x } # => Nothing
|
|
59
60
|
include Ribimaybe::Maybe
|
60
61
|
|
61
62
|
# Wrap functions inside functors and apply them to other functors!
|
62
|
-
Just do |x|
|
63
|
-
x *
|
64
|
-
end.apply(pure(42)) # => Just(1764)
|
63
|
+
Just do |x, y|
|
64
|
+
x * y
|
65
|
+
end.apply(pure(42)).apply(pure(42)) # => Just(1764)
|
65
66
|
|
66
67
|
Just do |x|
|
67
68
|
x * x
|
data/lib/ribimaybe.rb
CHANGED
@@ -176,39 +176,10 @@ module Ribimaybe
|
|
176
176
|
Contract Any, Or[nil, Proc] => Or[Nothing, Just]
|
177
177
|
def Just(value = nil, &fn)
|
178
178
|
return Nothing unless (value || fn)
|
179
|
-
Just.new(value || fn)
|
179
|
+
Just.new(value || fn.curry)
|
180
180
|
end
|
181
181
|
|
182
|
-
|
183
|
-
|
184
|
-
# ==== Attributes
|
185
|
-
#
|
186
|
-
# * +value+ - Value to be wrapped.
|
187
|
-
#
|
188
|
-
# ==== Examples
|
189
|
-
#
|
190
|
-
# pure(nil) # => Nothing
|
191
|
-
# pure(1) # => Just(1)
|
192
|
-
#
|
193
|
-
Contract Any => Or[Nothing, Just]
|
194
|
-
def pure(value)
|
195
|
-
Maybe(value)
|
196
|
-
end
|
197
|
-
|
198
|
-
# Wraps a value in a Just or returns a Nothing.
|
199
|
-
#
|
200
|
-
# ==== Attributes
|
201
|
-
#
|
202
|
-
# * +value+ - Value to be wrapped.
|
203
|
-
#
|
204
|
-
# ==== Examples
|
205
|
-
#
|
206
|
-
# rturn(nil) # => Nothing
|
207
|
-
# rturn(1) # => Just(1)
|
208
|
-
#
|
209
|
-
Contract Any => Or[Nothing, Just]
|
210
|
-
def rturn(value)
|
211
|
-
pure(value)
|
212
|
-
end
|
182
|
+
alias_method :pure, :Just
|
183
|
+
alias_method :rturn, :Just
|
213
184
|
end
|
214
185
|
end
|
data/lib/version.rb
CHANGED
@@ -28,11 +28,18 @@ describe "Applicative Instance" do
|
|
28
28
|
|
29
29
|
context "when i something containing a fn" do
|
30
30
|
it "should be apply to apply that fn to something" do
|
31
|
-
result =
|
31
|
+
result = pure do |x|
|
32
32
|
x + x
|
33
33
|
end.apply Just(21)
|
34
34
|
expect(result).to eq Just(42)
|
35
35
|
end
|
36
|
+
|
37
|
+
it "should be curried by default" do
|
38
|
+
result = pure do |x, y|
|
39
|
+
x + y
|
40
|
+
end.apply(Just(21)).apply(Just(21))
|
41
|
+
expect(result).to eq Just(42)
|
42
|
+
end
|
36
43
|
end
|
37
44
|
end
|
38
45
|
end
|