monadist 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/continuation/acting_as_maybe.rb +22 -0
- data/examples/general.rb +4 -4
- data/lib/monadist/shims.rb +2 -2
- data/lib/monadist/version.rb +1 -1
- data/spec/monadist_spec.rb +1 -1
- metadata +3 -2
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'monadist'
|
2
|
+
|
3
|
+
words = %w[apple tree]
|
4
|
+
|
5
|
+
p Monadist::Continuation.unit(words).
|
6
|
+
fmap { |array| array.map &:length }.
|
7
|
+
run
|
8
|
+
|
9
|
+
|
10
|
+
words = nil
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
def maybe(value)
|
15
|
+
Monadist::Continuation.new { |next_block| next_block.call value unless value.nil? }
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
p maybe(words).
|
21
|
+
fmap { |array| array.map &:length }.
|
22
|
+
run
|
data/examples/general.rb
CHANGED
@@ -3,8 +3,8 @@ require 'monadist/shims'
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
nothing = possibly_nil nil
|
6
|
-
|
7
|
-
|
6
|
+
just_value = possibly_nil '{"first_name":"Sam", "last_name":"Vimes"}'
|
7
|
+
json_list = list ['{"first_name":"Granny", "last_name":"Weatherwax"}', '{"first_name":"Nanny", "last_name":"Ogg"}']
|
8
8
|
continuation = with '{"first_name":"Fred", "last_name":"Colon"}'
|
9
9
|
meanwhile = meanwhile_with '{"first_name":"Nobby", "last_name":"Nobbs"}'
|
10
10
|
|
@@ -19,8 +19,8 @@ end
|
|
19
19
|
|
20
20
|
|
21
21
|
p full_name(nothing).value
|
22
|
-
p full_name(
|
23
|
-
p full_name(
|
22
|
+
p full_name(just_value).value
|
23
|
+
p full_name(json_list).values
|
24
24
|
full_name(continuation).run { |full_name| p full_name }
|
25
25
|
|
26
26
|
full_name(meanwhile).run { |full_name| p full_name }
|
data/lib/monadist/shims.rb
CHANGED
data/lib/monadist/version.rb
CHANGED
data/spec/monadist_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monadist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-11-
|
12
|
+
date: 2014-11-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- LICENSE.txt
|
76
76
|
- README.md
|
77
77
|
- Rakefile
|
78
|
+
- examples/continuation/acting_as_maybe.rb
|
78
79
|
- examples/continuation/github_fetch_original.rb
|
79
80
|
- examples/continuation/github_fetch_refactored_continuation.rb
|
80
81
|
- examples/continuation/github_fetch_refactored_meanwhile.rb
|