zx-monads 0.0.6 → 0.0.7

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 +29 -29
  3. data/lib/zx/maybe.rb +8 -5
  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: '0391e47fa921d99cc0295cd52c3dd364a6f2bbe69af850b8cce890f7d74510ab'
4
- data.tar.gz: b662943acb8c80009cc12d2322495169aca0bcda8bd52d7d1aa8ae5808f93998
3
+ metadata.gz: 6fad11ef006f65fc1217e5bbf480844d4367b3d7d8f72f486af7c8b3601de4cb
4
+ data.tar.gz: fca3ee13b064db8da1a706ad749e8af4a3f9ceddfd19876be49eaec28dcadc93
5
5
  SHA512:
6
- metadata.gz: 4eac7c508d2eeb24fb0cdcda5ef86fe55536773533acb22ff3e4865e0190379ddc723a00f6ed6ee2bae3183040e258cce8740e1f90931fd2064cf9a30ddb36d4
7
- data.tar.gz: 47b496f06b771727f6b5d542dda7c303bb178b64253ef6dbbe9d978937671c28a78e433ca312ac488c67cbdf2385781bb5db5fb8016b48ce990d1a81bb9c64b7
6
+ metadata.gz: 2ccf1a54176be479cb0e09ad8c2bab177668e8d9219bbc4dbe113ee855231d11cb79c3dbc5ece68b9a2d7ab2208b17cb005eb3eb4beff1ef8ee9b21faae9ff6f
7
+ data.tar.gz: 27430e4a6472dabc923357276cd3c39ca55814ddec4c7f0b6c012f60fedd3bc61080ce9d82428ed095992c96b8087d987a403d30a2fe3abc8cad7c25484c7a29
data/README.md CHANGED
@@ -68,11 +68,11 @@ class Order
68
68
  end
69
69
 
70
70
  class Order
71
- include Zx::Maybe
71
+ include Zx::Maybeable
72
72
  end
73
73
 
74
74
  class ProcessOrder < Zx::Steps
75
- # Maybe included now!
75
+ # include Zx::Maybeable included now!
76
76
  end
77
77
  ```
78
78
 
@@ -102,35 +102,35 @@ end
102
102
  ### ZX::Maybe
103
103
 
104
104
  ```ruby
105
- result = Maybe[1] # or Maybe.of(1)
105
+ result = Zx::Maybe[1] # or Maybe.of(1)
106
106
  ```
107
107
 
108
108
  ```ruby
109
- result = Maybe[nil] # or Maybe.of(nil)
109
+ result = Zx::Maybe[nil] # or Maybe.of(nil)
110
110
  ```
111
111
 
112
112
  ```ruby
113
- result = Maybe[1].map{ _1 + 2}
113
+ result = Zx::Maybe[1].map{ _1 + 2}
114
114
  # -> Some(3)
115
115
  ```
116
116
 
117
117
  ```ruby
118
- result = Maybe[nil].map{ _1 + 2}
118
+ result = Zx::Maybe[nil].map{ _1 + 2}
119
119
  # -> None
120
120
  ```
121
121
 
122
122
  ```ruby
123
- result = Maybe.of(1).or(2)
123
+ result = Zx::Maybe.of(1).or(2)
124
124
  result.or(2) # 1
125
125
  ```
126
126
 
127
127
  ```ruby
128
- result = Maybe.of(' ').or(2)
128
+ result = Zx::Maybe.of(' ').or(2)
129
129
  result.or(2) # 2
130
130
  ```
131
131
 
132
132
  ```ruby
133
- result = Maybe.of(' ').or(2)
133
+ result = Zx::Maybe.of(' ').or(2)
134
134
  result.or(2) # 2
135
135
  ```
136
136
 
@@ -143,7 +143,7 @@ order = {
143
143
  }
144
144
  }
145
145
 
146
- price = Maybe[order]
146
+ price = Zx::Maybe[order]
147
147
  .map { _1[:shopping] }
148
148
  .map { _1[:banana] }
149
149
  .map { _1[:price] }
@@ -152,13 +152,13 @@ price = Maybe[order]
152
152
 
153
153
  # or using #dig
154
154
 
155
- price = Maybe[order].dig(:shopping, :banana, :price)
155
+ price = Zx::Maybe[order].dig(:shopping, :banana, :price)
156
156
  # -> Some(10.0)
157
157
 
158
- price_none = Maybe[order].dig(:shopping, :banana, :price_non_exists)
158
+ price_none = Zx::Maybe[order].dig(:shopping, :banana, :price_non_exists)
159
159
  # -> None
160
160
 
161
- price_or = Maybe[order].dig(:shopping, :banana, :price_non_exists).or(10.0)
161
+ price_or = Zx::Maybe[order].dig(:shopping, :banana, :price_non_exists).or(10.0)
162
162
  # -> Some(10.0)
163
163
  ```
164
164
 
@@ -167,11 +167,11 @@ class Response
167
167
  attr_reader :body
168
168
 
169
169
  def initialize(new_body)
170
- @body = Maybe[new_body]
170
+ @body = Zx::Maybe[new_body]
171
171
  end
172
172
 
173
173
  def change(new_body)
174
- @body = Maybe[new_body]
174
+ @body = Zx::Maybe[new_body]
175
175
  end
176
176
  end
177
177
 
@@ -182,7 +182,7 @@ response.change({ status: 200 })
182
182
  expect(response.body).to be_some
183
183
 
184
184
  response_status = response.body.match(
185
- some: ->(body) { Maybe[body].map { _1.fetch(:status) }.unwrap },
185
+ some: ->(body) { Zx::Maybe[body].map { _1.fetch(:status) }.unwrap },
186
186
  none: -> {}
187
187
  )
188
188
  ```
@@ -196,7 +196,7 @@ response = Response.new(dump) # It's receive an JSON stringified
196
196
 
197
197
  module StatusCodeUnwrapModule
198
198
  def self.call(body)
199
- Maybe[body]
199
+ Zx::Maybe[body]
200
200
  .map{ JSON(_1, symbolize_names: true) }
201
201
  .dig(:status, :code)
202
202
  .apply(&:to_i)
@@ -215,11 +215,11 @@ expect(response_status).to eq(300)
215
215
  You can use `>>` to compose many callables, like this.
216
216
 
217
217
  ```rb
218
- sum = ->(x) { Maybe::Some[x + 1] }
218
+ sum = ->(x) { Zx::Maybe::Some[x + 1] }
219
219
 
220
- subtract = ->(x) { Maybe::Some[x - 1] }
220
+ subtract = ->(x) { Zx::Maybe::Some[x - 1] }
221
221
 
222
- result = Maybe[1] >> \
222
+ result = Zx::Maybe[1] >> \
223
223
  sum >> \
224
224
  subtract
225
225
 
@@ -229,11 +229,11 @@ expect(result.unwrap).to eq(1)
229
229
  If handle None, no worries.
230
230
 
231
231
  ```rb
232
- sum = ->(x) { Maybe::Some[x + 1] }
232
+ sum = ->(x) { Zx::Maybe::Some[x + 1] }
233
233
 
234
- subtract = ->(_) { Maybe::None.new }
234
+ subtract = ->(_) { Zx::Maybe::None.new }
235
235
 
236
- result = Maybe[1] \
236
+ result = Zx::Maybe[1] \
237
237
  >> sum \
238
238
  >> subtract
239
239
 
@@ -243,7 +243,7 @@ expect(result.unwrap).to be_nil
243
243
  ```rb
244
244
  class Order
245
245
  def self.sum(x)
246
- Maybe[{ number: x + 1 }]
246
+ Zx::Maybe[{ number: x + 1 }]
247
247
  end
248
248
  end
249
249
 
@@ -258,7 +258,7 @@ expect(result.unwrap).to be(2)
258
258
 
259
259
  ```rb
260
260
  class Order
261
- include Zx::Maybe
261
+ include Zx::Maybeable
262
262
 
263
263
  def self.sum(x)
264
264
  new.sum(x)
@@ -280,7 +280,7 @@ expect(result.unwrap).to be(2)
280
280
 
281
281
  ```rb
282
282
  class Order
283
- include Zx::Maybe
283
+ include Zx::Maybeable
284
284
 
285
285
  def self.sum(x)
286
286
  new.sum(x)
@@ -305,7 +305,7 @@ expect(number.unwrap).to be(0) # nil.to_i == 0
305
305
 
306
306
  ```rb
307
307
  class Order
308
- include Zx::Maybe
308
+ include Zx::Maybeable
309
309
 
310
310
  def self.sum(x)
311
311
  new.sum(x)
@@ -327,7 +327,7 @@ With default value, in None case.
327
327
 
328
328
  ```rb
329
329
  class Order
330
- include Zx::Maybe
330
+ include Zx::Maybeable
331
331
 
332
332
  def self.sum(x)
333
333
  new.sum(x)
@@ -347,7 +347,7 @@ expect(result.unwrap).to be(2)
347
347
 
348
348
  ```rb
349
349
  class Order
350
- include Zx::Maybe
350
+ include Zx::Maybeable
351
351
 
352
352
  def self.sum(x)
353
353
  new.sum(x)
data/lib/zx/maybe.rb CHANGED
@@ -173,20 +173,20 @@ module Zx
173
173
  end
174
174
 
175
175
  module ClassMethods
176
- None = ->(*kwargs) { Zx::Maybe::None.new(*kwargs) }
176
+ None = ->(value = nil) { Zx::Maybe::None.new(value) }
177
177
  Some = ->(*kwargs) { Zx::Maybe::Some.new(*kwargs) }
178
178
  Maybe = ->(*kwargs) { Zx::Maybe.of(*kwargs) }
179
179
 
180
180
  def Maybe(*kwargs)
181
- Zx::Maybe.of(*kwargs)
181
+ Maybe[*kwargs]
182
182
  end
183
183
 
184
184
  def Some(*kwargs)
185
- Zx::Maybe::Some.new(*kwargs)
185
+ Some[*kwargs]
186
186
  end
187
187
 
188
- def None(*kwargs)
189
- Zx::Maybe::None.new(*kwargs)
188
+ def None(value = nil)
189
+ Zx::Maybe.of(value)
190
190
  end
191
191
 
192
192
  def Try(default = nil, options = {})
@@ -196,4 +196,7 @@ module Zx
196
196
  end
197
197
  end
198
198
  end
199
+
200
+ include Maybe::ClassMethods
201
+ extend Maybe::ClassMethods
199
202
  end
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.6'
4
+ VERSION = '0.0.7'
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thadeu Esteves