zx-monads 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -0
  3. data/lib/maybe.rb +7 -0
  4. data/lib/zx/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5813fb9b40773da4e1b045030b8cd3086ac78b19792860d78d7a62b139892d06
4
- data.tar.gz: 0a8923287676072ccec22427a2ea564a318c1ad895bdce66d1c2a1557f8804cb
3
+ metadata.gz: 50a07904dbbe8ee15651293ad4e71e863fe3b32de630cdf0743ef34575351ca1
4
+ data.tar.gz: 11e32540d53a86ce32300fd38d95c10244c35f7601b44e8cce2728a1d83c2185
5
5
  SHA512:
6
- metadata.gz: 21598b32f355806f176afd8e6fdab613d3d999410943ef570cbfdda8500bd443f28e00e7b35073bdb75dc46fd44d888efe6b3fe8bac82bbb9bec97d873d13e77
7
- data.tar.gz: 64d5dac9dfaabb44fc9227f01fdcec0c7ddfb18a2f8e01c307266eb235438a1ce34af4e078c8f2675fb441b7544ce148a898a89dc281f5206761e0b6c8f6609e
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
@@ -105,6 +105,13 @@ class Maybe
105
105
  self
106
106
  end
107
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
+
108
115
  class Some < Maybe
109
116
  def self.[](...)
110
117
  new(...)
data/lib/zx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zx
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zx-monads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thadeu Esteves