ronad 0.3.0 → 0.4.0
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 +4 -4
- data/.ruby-version +1 -0
- data/README.md +18 -0
- data/lib/ronad/eventually.rb +35 -0
- data/lib/ronad/version.rb +1 -1
- data/lib/sugar.rb +2 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa2e90a31f98cc6989741b478cc1d3da81578c10
|
4
|
+
data.tar.gz: 261e18b674b19d0e8521dc9272111ea963648b9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bec8a6010fa768e26dad85aac978d262e83d519509be3934635459a73d644ab42bec7dff49094839855a2771bdc8f4fbb51b7cb267b8b696a8399165deb5f038
|
7
|
+
data.tar.gz: 35d94b5b3967ac127a7c21e020b16ef4ebd72193222feb68f6c1e8b34b1d759dc537e7e5a8c506cbb72cfd6d8a1d40c74b6f671e74f2db75c4be5bfa608d525b
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.2
|
data/README.md
CHANGED
@@ -161,6 +161,24 @@ d = ~Default('hello', Maybe(10)) #=> 10
|
|
161
161
|
Notice that default will recursively expand other Monads. As a general rule, you should never
|
162
162
|
receive a monad after invoking `#value`.
|
163
163
|
|
164
|
+
## Eventually
|
165
|
+
|
166
|
+
Useful for delaying execution or not executing at all. Useful to combine with
|
167
|
+
Default when it's not know if the default should execute.
|
168
|
+
|
169
|
+
```
|
170
|
+
person = Default(
|
171
|
+
Eventually { Person.create(name: "Frank", location: :unknown) },
|
172
|
+
Maybe(Person.find_by(name: "Frank"))
|
173
|
+
)
|
174
|
+
|
175
|
+
~ person.update(location: 'somewhere')
|
176
|
+
```
|
177
|
+
|
178
|
+
If `find_by` finds a person the `Person.create` will never be invoked.
|
179
|
+
Conversely if `find_by` does not it will create the person and update their
|
180
|
+
location.
|
181
|
+
|
164
182
|
## License
|
165
183
|
|
166
184
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Ronad
|
2
|
+
# Delayed execution. Similar to creating a closure but Eventually is
|
3
|
+
# compatible with the Ronad API.
|
4
|
+
#
|
5
|
+
# Eventually is not a promise. The block in the Eventually will not execute
|
6
|
+
# until invoked.
|
7
|
+
class Eventually < Monad
|
8
|
+
def initialize block
|
9
|
+
@value = block
|
10
|
+
end
|
11
|
+
|
12
|
+
# @override
|
13
|
+
def and_then &block
|
14
|
+
new_block = lambda do
|
15
|
+
block.call(expand @value.call)
|
16
|
+
end
|
17
|
+
|
18
|
+
Eventually.new new_block
|
19
|
+
end
|
20
|
+
|
21
|
+
# @override
|
22
|
+
def monad_value
|
23
|
+
expand @value.call
|
24
|
+
end
|
25
|
+
|
26
|
+
# @note can probably replace monad_value
|
27
|
+
def expand(val)
|
28
|
+
if Monad === val
|
29
|
+
expand val.monad_value
|
30
|
+
else
|
31
|
+
val
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/ronad/version.rb
CHANGED
data/lib/sugar.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'ronad/maybe'
|
2
2
|
require 'ronad/just'
|
3
3
|
require 'ronad/default'
|
4
|
+
require 'ronad/eventually'
|
4
5
|
|
5
6
|
def Maybe(value) ; Ronad::Maybe.new(value) end
|
6
7
|
def Just(value); Ronad::Just.new(value) end
|
7
8
|
def Default(fallback, value) ; Ronad::Default.new(fallback, value) end
|
9
|
+
def Eventually(&b); Ronad::Eventually.new(b) end
|
8
10
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ronad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uri Gorelik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
|
+
- ".ruby-version"
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE.txt
|
94
95
|
- README.md
|
@@ -97,6 +98,7 @@ files:
|
|
97
98
|
- bin/setup
|
98
99
|
- lib/ronad.rb
|
99
100
|
- lib/ronad/default.rb
|
101
|
+
- lib/ronad/eventually.rb
|
100
102
|
- lib/ronad/just.rb
|
101
103
|
- lib/ronad/maybe.rb
|
102
104
|
- lib/ronad/monad.rb
|
@@ -123,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
125
|
version: '0'
|
124
126
|
requirements: []
|
125
127
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.6.13
|
127
129
|
signing_key:
|
128
130
|
specification_version: 4
|
129
131
|
summary: Monads implemented the Ruby way
|