zx-monads 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/maybe.rb +7 -2
- data/lib/zx/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50a07904dbbe8ee15651293ad4e71e863fe3b32de630cdf0743ef34575351ca1
|
4
|
+
data.tar.gz: 11e32540d53a86ce32300fd38d95c10244c35f7601b44e8cce2728a1d83c2185
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81841c32f54a4bf2c22dd33ad1f72a1561c7d29c5b53977bb9641225fbe27116886d3391765643d35b43b3c77755cf58f74360213287e3ddbe443fe9706ecd65
|
7
|
+
data.tar.gz: fe4d63145ecb587180a29e9880036d673d712019854098ff7842afe56a1a27c625f654f9f8dc356f6afce2983ea69e9ad87edc640dd3176e8ccef8304e861256
|
data/README.md
CHANGED
@@ -96,6 +96,7 @@ end
|
|
96
96
|
#math(some:, none:) -> Receive callables and associate them
|
97
97
|
#on_success{} -> Only when Some
|
98
98
|
#on_failure{} -> Only then None
|
99
|
+
#on(:success|:failure){}
|
99
100
|
```
|
100
101
|
|
101
102
|
### ZX::Maybe
|
@@ -404,6 +405,15 @@ order.call
|
|
404
405
|
.on_failure { |none| expect(none.or(0)).to eq(0) }
|
405
406
|
```
|
406
407
|
|
408
|
+
```rb
|
409
|
+
order = OrderStep.new(20)
|
410
|
+
|
411
|
+
order.call
|
412
|
+
.map { |n| n + 1 }
|
413
|
+
.on(:success) { |some| expect(some.unwrap).to eq(10) }
|
414
|
+
.on(:failure) { |none| expect(none.or(0)).to eq(0) }
|
415
|
+
```
|
416
|
+
|
407
417
|
```rb
|
408
418
|
order = OrderStep.new(-1)
|
409
419
|
|
data/lib/maybe.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Maybe
|
4
|
-
attr_reader :value
|
5
|
-
|
6
4
|
IsBlank = ->(value) { value.nil? || value.to_s.strip&.empty? || !value }
|
7
5
|
|
8
6
|
def self.of(...)
|
@@ -107,6 +105,13 @@ class Maybe
|
|
107
105
|
self
|
108
106
|
end
|
109
107
|
|
108
|
+
def on(ontype, &block)
|
109
|
+
case ontype.to_sym
|
110
|
+
when :success then on_success(&block)
|
111
|
+
when :failure then on_failure(&block)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
110
115
|
class Some < Maybe
|
111
116
|
def self.[](...)
|
112
117
|
new(...)
|
data/lib/zx/version.rb
CHANGED