zx-monads 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50a07904dbbe8ee15651293ad4e71e863fe3b32de630cdf0743ef34575351ca1
4
- data.tar.gz: 11e32540d53a86ce32300fd38d95c10244c35f7601b44e8cce2728a1d83c2185
3
+ metadata.gz: 92ddc57d4126dfd37ebaeeb3695eeb9bd32dfedd4a1a973b1eefe6cc9f082f88
4
+ data.tar.gz: 1baafdd45d22c064368e9a8bd789fed4b23cc4cffb493d903441442e26e47502
5
5
  SHA512:
6
- metadata.gz: 81841c32f54a4bf2c22dd33ad1f72a1561c7d29c5b53977bb9641225fbe27116886d3391765643d35b43b3c77755cf58f74360213287e3ddbe443fe9706ecd65
7
- data.tar.gz: fe4d63145ecb587180a29e9880036d673d712019854098ff7842afe56a1a27c625f654f9f8dc356f6afce2983ea69e9ad87edc640dd3176e8ccef8304e861256
6
+ metadata.gz: 9969b07e28b5a4ca988e416bddcde3360e51c6f572b0712c247aedb7f78717e23e9821c2c83a4fafa4bea660e7c20ada2a43c75d07ec6159c09984f27941d471
7
+ data.tar.gz: 3fffca4170917b53e657cb010727cbdc3fd94f4f752893f01f61022714b5e9fda604b9dac1de3ec11dd642d451ccc6a41427e410894e8105dab63cc05e4c6cb9
@@ -10,7 +10,7 @@ jobs:
10
10
  runs-on: ubuntu-latest
11
11
  strategy:
12
12
  matrix:
13
- ruby-version: ['2.7', '3.0', '3.1', '3.2']
13
+ ruby-version: ['2.7', '3.0', '3.1', 'head']
14
14
 
15
15
  steps:
16
16
  - uses: actions/checkout@v3
data/.rubocop.yml CHANGED
@@ -7,7 +7,7 @@ Style/Documentation:
7
7
  Enabled: false
8
8
 
9
9
  Layout:
10
- Enabled: false
10
+ Enabled: true
11
11
 
12
12
  Style/FrozenStringLiteralComment:
13
13
  Enabled: true
data/Gemfile CHANGED
@@ -1,14 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'base64'
4
- gem 'json'
5
3
  gem 'zeitwerk'
6
4
 
7
5
  group :development, :test do
6
+ gem 'byebug'
8
7
  gem 'rubocop', github: 'rubocop/rubocop', require: false
9
8
  end
10
9
 
11
10
  group :test do
12
- gem 'byebug'
13
11
  gem 'rspec'
14
12
  end
data/lib/maybe.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Maybe
4
+ attr_reader :value
5
+
4
6
  IsBlank = ->(value) { value.nil? || value.to_s.strip&.empty? || !value }
5
7
 
6
8
  def self.of(...)
7
9
  new.of(...)
8
10
  end
9
11
 
10
- def self.[](...)
12
+ def self.[](...)
11
13
  of(...)
12
14
  end
13
15
 
@@ -18,7 +20,7 @@ class Maybe
18
20
  rescue StandardError
19
21
  None.new
20
22
  end
21
-
23
+
22
24
  def type
23
25
  to_s.downcase.to_sym
24
26
  end
@@ -32,7 +34,7 @@ class Maybe
32
34
  end
33
35
 
34
36
  def unwrap
35
- @value
37
+ @value
36
38
  end
37
39
 
38
40
  def or(value)
@@ -42,6 +44,7 @@ class Maybe
42
44
  def >>(other)
43
45
  self > other
44
46
  end
47
+ alias | >>
45
48
 
46
49
  def fmap(_)
47
50
  self
@@ -58,7 +61,7 @@ class Maybe
58
61
  case arg
59
62
  in None then self
60
63
  in Symbol | String then dig(arg)
61
- end
64
+ end
62
65
  rescue StandardError => e
63
66
  None.new(e.message)
64
67
  end
@@ -77,7 +80,7 @@ class Maybe
77
80
  def dig(...)
78
81
  Maybe[@value&.dig(...)]
79
82
  end
80
-
83
+
81
84
  def dig!(...)
82
85
  dig(...).unwrap
83
86
  end
@@ -121,7 +124,7 @@ class Maybe
121
124
  @value = value
122
125
  end
123
126
 
124
- def deconstruct
127
+ def deconstruct
125
128
  [@value]
126
129
  end
127
130
 
@@ -130,7 +133,7 @@ class Maybe
130
133
  end
131
134
 
132
135
  def to_s
133
- 'Some'
136
+ 'Some'
134
137
  end
135
138
 
136
139
  def >(other)
@@ -143,7 +146,7 @@ class Maybe
143
146
  end
144
147
 
145
148
  class None < Maybe
146
- def self.[](...)
149
+ def self.[](...)
147
150
  new(...)
148
151
  end
149
152
 
@@ -167,4 +170,4 @@ class Maybe
167
170
  self
168
171
  end
169
172
  end
170
- end
173
+ end
data/lib/zx/maybe.rb CHANGED
@@ -1,19 +1,20 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Zx
3
4
  module Maybe
4
5
  module Maybeable
5
6
  None = ->(*kwargs) { ::Maybe::None.new(*kwargs) }
6
7
  Some = ->(*kwargs) { ::Maybe::Some.new(*kwargs) }
7
8
  Maybe = ->(*kwargs) { ::Maybe.of(*kwargs) }
8
-
9
+
9
10
  def Maybe(*kwargs)
10
11
  ::Maybe.of(*kwargs)
11
12
  end
12
-
13
+
13
14
  def Some(*kwargs)
14
15
  ::Maybe::Some.new(*kwargs)
15
16
  end
16
-
17
+
17
18
  def None(*kwargs)
18
19
  ::Maybe::None.new(*kwargs)
19
20
  end
@@ -30,4 +31,4 @@ module Zx
30
31
  klass.extend(Maybeable)
31
32
  end
32
33
  end
33
- end
34
+ 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.4'
4
+ VERSION = '0.0.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zx-monads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thadeu Esteves
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-25 00:00:00.000000000 Z
11
+ date: 2023-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler