consequence 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -4
- data/lib/consequence/delegates_to_value.rb +0 -2
- data/lib/consequence/eventually.rb +17 -0
- data/lib/consequence/something.rb +5 -0
- data/lib/consequence/utils.rb +1 -1
- data/lib/consequence.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35e897cf0811f0e794d208bfcff9c243f86fd167
|
4
|
+
data.tar.gz: 4d71d729915727771f5ae6e9263bbf1a72fc0093
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 434bcae89a6fad08652e5d697a6f9a3ea3e2eadcf6393a68827b087680c1cfa7d49e14546373b45a3380dd1268d5383e647bfa196ddbd38bc1917c1130ef50bf
|
7
|
+
data.tar.gz: efd3cb4d3e8bd01b2d2fb99aae2a1ce69257baa7d7da55edb37428e58560b69d1860f2438bfe8cb7229321c62bbc2161da3714d1f2675f003872c743ef1c6980
|
data/README.md
CHANGED
@@ -184,6 +184,12 @@ A `Nothing` responds positively to the `#nil?` method:
|
|
184
184
|
Nothing[nil].nil? # true
|
185
185
|
```
|
186
186
|
|
187
|
+
### Eventually
|
188
|
+
|
189
|
+
The `Eventually` monad hooks up the callbacks of a chain of methods that may be executed some time in the future. This is useful for dealing with asynochronous calls.
|
190
|
+
|
191
|
+
For an example, check out the [Eventually example](https://github.com/mushishi78/consequence/wiki/Eventually-Example) on the wiki.
|
192
|
+
|
187
193
|
## DelegatesToValue
|
188
194
|
|
189
195
|
`DelegatesToValue` is a module that can be included into Monad that adds a `#method_missing` method to delegate calls to its value:
|
@@ -196,9 +202,6 @@ Foo[[1, 4, 6]].map {|n| n + 1} # Foo[[2, 5, 7]]
|
|
196
202
|
It delegates via the `>>` operation, so subclasses of the NullMonad will respond to delegated method calls, but still take no action:
|
197
203
|
|
198
204
|
``` ruby
|
199
|
-
Something.include DelegatesToValue
|
200
|
-
Nothing.include DelegatesToValue
|
201
|
-
|
202
205
|
dangrous_hash = {user: {orders: {1 => {price: 3.99} } } }
|
203
206
|
|
204
207
|
Something[dangrous_hash][:user][:orders][1][:price] # Consequence::Something[3.99]
|
@@ -207,12 +210,13 @@ Something[dangrous_hash][:user][:orders][2][:price] # Consequence::Nothing[nil]
|
|
207
210
|
|
208
211
|
## Wiki
|
209
212
|
|
210
|
-
To find some examples and information about utils, [check out the wiki](https://github.com/mushishi78/consequence/wiki
|
213
|
+
To find some examples and information about utils, [check out the wiki](https://github.com/mushishi78/consequence/wiki) and feel free to contribute to it.
|
211
214
|
|
212
215
|
## Inspirations
|
213
216
|
|
214
217
|
* [Deterministic](https://github.com/pzol/deterministic)
|
215
218
|
* [Kleisli](https://github.com/txus/kleisli)
|
219
|
+
* [Refactoring Ruby with Monads](https://www.youtube.com/watch?v=J1jYlPtkrqQ&feature=youtu.be&a)
|
216
220
|
|
217
221
|
## Installation
|
218
222
|
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'consequence/monad'
|
2
|
+
require 'consequence/delegates_to_value'
|
2
3
|
|
3
4
|
module Consequence
|
4
5
|
class Something < Monad
|
6
|
+
include DelegatesToValue
|
7
|
+
|
5
8
|
def >>(proc)
|
6
9
|
result = super
|
7
10
|
result.value.nil? ? Nothing[nil] : result
|
@@ -9,6 +12,8 @@ module Consequence
|
|
9
12
|
end
|
10
13
|
|
11
14
|
class Nothing < NullMonad
|
15
|
+
include DelegatesToValue
|
16
|
+
|
12
17
|
def nil?; true end
|
13
18
|
end
|
14
19
|
end
|
data/lib/consequence/utils.rb
CHANGED
data/lib/consequence.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consequence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max White
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- lib/consequence.rb
|
42
42
|
- lib/consequence/core_ext/utils.rb
|
43
43
|
- lib/consequence/delegates_to_value.rb
|
44
|
+
- lib/consequence/eventually.rb
|
44
45
|
- lib/consequence/monad.rb
|
45
46
|
- lib/consequence/something.rb
|
46
47
|
- lib/consequence/success.rb
|