either-monad 0.0.1 → 0.0.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 +77 -1
- data/Rakefile +1 -1
- data/lib/either.rb +1 -1
- data/lib/either/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b16513779903c1bf9334051f5d13e85e08105176
|
4
|
+
data.tar.gz: e62bc45ae20817c744fff565282bef0f513ad4b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5c3227da2e5a5cb38630a78b4d182a797339fbe062e3e1b5911e3c9fd944c64b75f3479818e45212dc762926917efe91408558a5e8152c36b0b08c3ab9de378
|
7
|
+
data.tar.gz: ec285cf53f870c470da4270016d2d2b5024ca86d12148cdafd5d01698ccfb5d9f57dd94516082d36e840df73b78a345e7d8499f33005fe5ef6a6c20209d2a900
|
data/README.md
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
Either
|
2
2
|
======
|
3
3
|
|
4
|
+
[](https://travis-ci.org/dredozubov/either)
|
5
|
+
[](https://codeclimate.com/github/dredozubov/either)
|
6
|
+
|
4
7
|
Dead simple error context framework aka Either monad. Goal of this gem is to
|
5
8
|
provide solid ground to control flow without exceptions and allow simple and
|
6
|
-
expressive chaining
|
9
|
+
expressive chaining and handling failures gracefully.
|
10
|
+
|
11
|
+
Don't fear the "monad" part of the name though, you don't have to know what monad is to understand
|
12
|
+
how his gem works and use it with ease!
|
7
13
|
|
8
14
|
Installation
|
9
15
|
------------
|
@@ -19,3 +25,73 @@ or in **Gemfile**
|
|
19
25
|
``` ruby
|
20
26
|
gem 'either-monad'
|
21
27
|
```
|
28
|
+
|
29
|
+
|
30
|
+
Examples
|
31
|
+
--------
|
32
|
+
|
33
|
+
All examples taken from production code.
|
34
|
+
|
35
|
+
### Chaining computations
|
36
|
+
|
37
|
+
You can chain computations without fear of losing a failure context. For
|
38
|
+
example you can validate a request, make some work and serialize the result
|
39
|
+
with:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
# results in either Success with serialized result or Failure with context.
|
43
|
+
validate(request)
|
44
|
+
.bind(->(validated) { search(validated) })
|
45
|
+
.bind(->(search_result) { serialize(search_result) })
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
If `Failure` has been returned from one of the binded methods, the whole
|
50
|
+
expression will be evaluated to this this `Failure` value.
|
51
|
+
Each of the binded method(to make sense type-wise) must take unwrapped value
|
52
|
+
from previous one, do some work and return new value wrapped in `Success`
|
53
|
+
or `Failure`.
|
54
|
+
|
55
|
+
### Wrapping values into Success or Failure context
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
Success[value]
|
59
|
+
```
|
60
|
+
|
61
|
+
or
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
Failure[failure_context]
|
65
|
+
```
|
66
|
+
|
67
|
+
### Unwrapping values
|
68
|
+
|
69
|
+
It's just an attribute reader!
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
result = Success[:foo]
|
73
|
+
result.value # => :foo
|
74
|
+
```
|
75
|
+
|
76
|
+
Ruby version support
|
77
|
+
--------------------
|
78
|
+
|
79
|
+
Gem is supposed to work correctly with the following rubies:
|
80
|
+
|
81
|
+
* 2.0.0
|
82
|
+
* 2.1.4
|
83
|
+
* jruby
|
84
|
+
* rbx
|
85
|
+
|
86
|
+
Contributing
|
87
|
+
-------------
|
88
|
+
|
89
|
+
* fork it
|
90
|
+
* make some changes and submit a pull request
|
91
|
+
* do not make changes to version
|
92
|
+
|
93
|
+
Contact info
|
94
|
+
------------
|
95
|
+
|
96
|
+
If you want to contact me or/and some questions - feel free to write me at
|
97
|
+
denis.redozubov at gmail or mention me on [twitter](http://twitter.com/rufuse).
|
data/Rakefile
CHANGED
data/lib/either.rb
CHANGED
data/lib/either/version.rb
CHANGED