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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -0
  3. data/lib/maybe.rb +7 -2
  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: e9acee35f37cd6cec08557b8ecf438ac66cda53c81737def1667d912ac916002
4
- data.tar.gz: 7aa82e0795492ba409b8644a3013298af1d4003af0bf8004a71b35423711bf77
3
+ metadata.gz: 50a07904dbbe8ee15651293ad4e71e863fe3b32de630cdf0743ef34575351ca1
4
+ data.tar.gz: 11e32540d53a86ce32300fd38d95c10244c35f7601b44e8cce2728a1d83c2185
5
5
  SHA512:
6
- metadata.gz: 869629640531acfc443af35b60a76e6696e6b10c2804de327d5054eae310244675f17e55e1964308909bd93c3960cc64cc5cd6ee9959d85c1b637eaed554424c
7
- data.tar.gz: 850944a1da552252a4434a47ccfd3615733b23789d677a52303b4352f5a26656eaceaafd57ee1a6b396333c8a5f3179280fb3a1cc05d66b6f487286b4b5ca0d9
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zx
4
- VERSION = '0.0.2'
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.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thadeu Esteves