result-monad 0.1.1 → 0.1.2
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/README.md +21 -2
- data/lib/result-monad/version.rb +1 -1
- data/lib/result-monad.rb +4 -4
- data/{result.gemspec → result-monad.gemspec} +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06e97a1d838923904e635d8db6d4a2d1aaa408fb
|
4
|
+
data.tar.gz: 664c8d07c7c60c78c4a420cd5d1a96a94794bda0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fb60c7bd5f36285a4d4ab4f10970698cb82b40bf4e60b09f94d13095a6be1f944ee8a70ad4bdc695cbbe20b01e643976028fa4a7d029e472f22394fa542cf07
|
7
|
+
data.tar.gz: 6cf9622293538460ce6760b9d5a1538263e51adcf135c95601a5822f94f19e4ec39a8330eecd68a9831f69a3dab2d944a2f552dc3b5f8c0244a9175c10e66a1a
|
data/README.md
CHANGED
@@ -109,6 +109,9 @@ write it to a local file, and then delete the file on the FTP server. Some thin
|
|
109
109
|
* Every call to any outside library, even standard library functions are either in a `map` block which
|
110
110
|
gets Captured or they are themselves Captured
|
111
111
|
* No independent action (as in someone calling `copy_file` directly) will execute without its requirements being met.
|
112
|
+
* A shortcut to creating an Error value based on some condition, as well as capturing errors generated from testing the
|
113
|
+
condition can be seen in `ensure_file`. Any exceptions raised by File.exist?, as well as our condition not being met
|
114
|
+
are captured as Error
|
112
115
|
|
113
116
|
```ruby
|
114
117
|
require 'net/ftp'
|
@@ -157,6 +160,23 @@ ftp.transfer_and_delete("5MB.zip")
|
|
157
160
|
`transfer_and_delete` can return numerous errors but there is no way for this code to raise an exception. Exceptions
|
158
161
|
raised in `map` or `map!` are caught and expressed as `Error`.
|
159
162
|
|
163
|
+
#### Conditionally executing code
|
164
|
+
|
165
|
+
Using the example above, say we wanted to find and delete the file if we may have accidentally created it.
|
166
|
+
This wouldn't be a sensible way of solving this problem, but this illustrates a use case for result base conditionals.
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
ftp = SensitiveFileFTP.new('speedtest.tele2.net')
|
170
|
+
ftp.transfer_and_delete("5MB.zip").or_else do
|
171
|
+
ftp.delete_local_file("5MB.zip")
|
172
|
+
end
|
173
|
+
|
174
|
+
# or lets say we wanted to log a success if it worked
|
175
|
+
|
176
|
+
ftp.transfer_and_delete("5MB.zip").and_then do
|
177
|
+
log "Did the thing!"
|
178
|
+
end
|
179
|
+
```
|
160
180
|
|
161
181
|
|
162
182
|
## What's next
|
@@ -186,5 +206,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
186
206
|
|
187
207
|
## License
|
188
208
|
|
189
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
190
|
-
|
209
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/result-monad/version.rb
CHANGED
data/lib/result-monad.rb
CHANGED
@@ -11,15 +11,15 @@ end
|
|
11
11
|
|
12
12
|
def Capture
|
13
13
|
begin
|
14
|
-
Ok(yield)
|
14
|
+
Ok(yield).join!
|
15
15
|
rescue StandardError => e
|
16
|
-
Error(e)
|
16
|
+
Error(e).join!
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
class Result
|
21
|
-
require 'result/error'
|
22
|
-
require 'result/ok'
|
21
|
+
require 'result-monad/error'
|
22
|
+
require 'result-monad/ok'
|
23
23
|
|
24
24
|
def initialize(m)
|
25
25
|
@m = m
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: result-monad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zachary Daniel
|
@@ -89,7 +89,7 @@ files:
|
|
89
89
|
- lib/result-monad/error.rb
|
90
90
|
- lib/result-monad/ok.rb
|
91
91
|
- lib/result-monad/version.rb
|
92
|
-
- result.gemspec
|
92
|
+
- result-monad.gemspec
|
93
93
|
homepage: http://gitlab.com/zachdaniel/result-monad
|
94
94
|
licenses:
|
95
95
|
- MIT
|