fear 2.0.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/spec.yml +1 -5
- data/CHANGELOG.md +8 -0
- data/Gemfile +14 -2
- data/Gemfile.lock +48 -61
- data/LICENSE.txt +1 -1
- data/README.md +18 -70
- data/Rakefile +32 -119
- data/benchmarks/dry_do_vs_fear_for.txt +7 -6
- data/benchmarks/dry_some_fmap_vs_fear_some_map.txt +7 -6
- data/benchmarks/factorial.txt +7 -9
- data/benchmarks/fear_gaurd_and1_vs_new.txt +7 -6
- data/benchmarks/fear_gaurd_and2_vs_and.txt +8 -7
- data/benchmarks/fear_gaurd_and3_vs_and_and.txt +7 -6
- data/benchmarks/fear_pattern_matching_construction_vs_execution.txt +7 -6
- data/benchmarks/pattern_matching_dry_vs_qo_vs_fear_try.txt +8 -10
- data/fear.gemspec +4 -19
- data/lib/fear/either/left_projection.rb +237 -0
- data/lib/fear/either/pattern_match.rb +49 -0
- data/lib/fear/either.rb +20 -11
- data/lib/fear/either_api.rb +2 -4
- data/lib/fear/empty_partial_function.rb +1 -1
- data/lib/fear/failure/pattern_match.rb +14 -0
- data/lib/fear/failure.rb +1 -1
- data/lib/fear/for_api.rb +0 -2
- data/lib/fear/future.rb +1 -1
- data/lib/fear/future_api.rb +0 -5
- data/lib/fear/left/pattern_match.rb +15 -0
- data/lib/fear/left.rb +1 -1
- data/lib/fear/none.rb +0 -87
- data/lib/fear/none_class/pattern_match.rb +16 -0
- data/lib/fear/none_class.rb +85 -0
- data/lib/fear/option/pattern_match.rb +47 -0
- data/lib/fear/option.rb +1 -5
- data/lib/fear/option_api.rb +1 -3
- data/lib/fear/partial_function/empty.rb +3 -5
- data/lib/fear/partial_function/guard.rb +0 -4
- data/lib/fear/partial_function/or_else.rb +0 -2
- data/lib/fear/partial_function.rb +0 -9
- data/lib/fear/partial_function_class.rb +1 -1
- data/lib/fear/pattern_match.rb +3 -2
- data/lib/fear/pattern_matching_api.rb +0 -3
- data/lib/fear/right/pattern_match.rb +15 -0
- data/lib/fear/right.rb +1 -1
- data/lib/fear/right_biased.rb +2 -0
- data/lib/fear/some/pattern_match.rb +15 -0
- data/lib/fear/some.rb +1 -1
- data/lib/fear/success/pattern_match.rb +16 -0
- data/lib/fear/success.rb +1 -1
- data/lib/fear/try/pattern_match.rb +29 -0
- data/lib/fear/try.rb +3 -7
- data/lib/fear/try_api.rb +0 -2
- data/lib/fear/version.rb +1 -1
- data/lib/fear.rb +3 -14
- data/spec/fear/awaitable_spec.rb +0 -2
- data/spec/fear/either/left_projection_spec.rb +289 -0
- data/spec/fear/{either_pattern_match_spec.rb → either/pattern_match_spec.rb} +1 -1
- data/spec/fear/{option_pattern_match_spec.rb → option/pattern_match_spec.rb} +1 -1
- data/spec/fear/partial_function/empty_spec.rb +1 -1
- data/spec/fear/{try_pattern_match_spec.rb → try/try_pattern_match_spec.rb} +1 -1
- data/spec/support/.keep +0 -0
- metadata +29 -255
- data/benchmarks/fear_pattern_extracting_with_vs_without_cache.txt +0 -11
- data/benchmarks/pattern_matching_qo_vs_fear_pattern_extraction.txt +0 -11
- data/benchmarks/pattern_matching_qo_vs_fear_try_execution.txt +0 -11
- data/lib/dry/types/fear/option.rb +0 -125
- data/lib/dry/types/fear.rb +0 -8
- data/lib/fear/either_pattern_match.rb +0 -52
- data/lib/fear/failure_pattern_match.rb +0 -12
- data/lib/fear/left_pattern_match.rb +0 -11
- data/lib/fear/none_pattern_match.rb +0 -14
- data/lib/fear/option_pattern_match.rb +0 -50
- data/lib/fear/right_pattern_match.rb +0 -13
- data/lib/fear/some_pattern_match.rb +0 -13
- data/lib/fear/struct.rb +0 -237
- data/lib/fear/success_pattern_match.rb +0 -14
- data/lib/fear/try_pattern_match.rb +0 -32
- data/spec/dry/types/fear/option/constrained_spec.rb +0 -22
- data/spec/dry/types/fear/option/core_spec.rb +0 -77
- data/spec/dry/types/fear/option/default_spec.rb +0 -21
- data/spec/dry/types/fear/option/hash_spec.rb +0 -58
- data/spec/dry/types/fear/option/option_spec.rb +0 -97
- data/spec/struct_pattern_matching_spec.rb +0 -36
- data/spec/struct_spec.rb +0 -194
- data/spec/support/dry_types.rb +0 -6
metadata
CHANGED
@@ -1,233 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fear
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Tëma Bolshakov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: zeitwerk
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
|
-
type: :
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: concurrent-ruby
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: dry-matcher
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: dry-monads
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: qo
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rake
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '13.0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '13.0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rspec
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '3.1'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '3.1'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rubocop-rspec
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - '='
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: 1.34.0
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - '='
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: 1.34.0
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: rubocop
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - '='
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: 1.32.0
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - '='
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: 1.32.0
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: ruby_coding_standard
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: yard
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - ">="
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '0'
|
174
|
-
type: :development
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - ">="
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: '0'
|
181
|
-
- !ruby/object:Gem::Dependency
|
182
|
-
name: dry-types
|
183
|
-
requirement: !ruby/object:Gem::Requirement
|
184
|
-
requirements:
|
185
|
-
- - ">="
|
186
|
-
- !ruby/object:Gem::Version
|
187
|
-
version: '0'
|
188
|
-
type: :development
|
189
|
-
prerelease: false
|
190
|
-
version_requirements: !ruby/object:Gem::Requirement
|
191
|
-
requirements:
|
192
|
-
- - ">="
|
193
|
-
- !ruby/object:Gem::Version
|
194
|
-
version: '0'
|
195
|
-
- !ruby/object:Gem::Dependency
|
196
|
-
name: fear-rspec
|
197
|
-
requirement: !ruby/object:Gem::Requirement
|
198
|
-
requirements:
|
199
|
-
- - ">="
|
200
|
-
- !ruby/object:Gem::Version
|
201
|
-
version: '0'
|
202
|
-
type: :development
|
203
|
-
prerelease: false
|
204
|
-
version_requirements: !ruby/object:Gem::Requirement
|
205
|
-
requirements:
|
206
|
-
- - ">="
|
207
|
-
- !ruby/object:Gem::Version
|
208
|
-
version: '0'
|
209
|
-
- !ruby/object:Gem::Dependency
|
210
|
-
name: simplecov
|
211
|
-
requirement: !ruby/object:Gem::Requirement
|
212
|
-
requirements:
|
213
|
-
- - ">="
|
214
|
-
- !ruby/object:Gem::Version
|
215
|
-
version: '0'
|
216
|
-
type: :development
|
217
|
-
prerelease: false
|
218
|
-
version_requirements: !ruby/object:Gem::Requirement
|
219
|
-
requirements:
|
220
|
-
- - ">="
|
221
|
-
- !ruby/object:Gem::Version
|
222
|
-
version: '0'
|
223
|
-
- !ruby/object:Gem::Dependency
|
224
|
-
name: simplecov-lcov
|
225
|
-
requirement: !ruby/object:Gem::Requirement
|
226
|
-
requirements:
|
227
|
-
- - ">="
|
228
|
-
- !ruby/object:Gem::Version
|
229
|
-
version: '0'
|
230
|
-
type: :development
|
20
|
+
type: :runtime
|
231
21
|
prerelease: false
|
232
22
|
version_requirements: !ruby/object:Gem::Requirement
|
233
23
|
requirements:
|
@@ -236,7 +26,7 @@ dependencies:
|
|
236
26
|
version: '0'
|
237
27
|
description: Ruby port of some Scala's monads.
|
238
28
|
email:
|
239
|
-
-
|
29
|
+
- tema@bolshakov.dev
|
240
30
|
executables: []
|
241
31
|
extensions: []
|
242
32
|
extra_rdoc_files: []
|
@@ -262,37 +52,34 @@ files:
|
|
262
52
|
- benchmarks/fear_gaurd_and1_vs_new.txt
|
263
53
|
- benchmarks/fear_gaurd_and2_vs_and.txt
|
264
54
|
- benchmarks/fear_gaurd_and3_vs_and_and.txt
|
265
|
-
- benchmarks/fear_pattern_extracting_with_vs_without_cache.txt
|
266
55
|
- benchmarks/fear_pattern_matching_construction_vs_execution.txt
|
267
56
|
- benchmarks/pattern_matching_dry_vs_qo_vs_fear_try.txt
|
268
|
-
- benchmarks/pattern_matching_qo_vs_fear_pattern_extraction.txt
|
269
|
-
- benchmarks/pattern_matching_qo_vs_fear_try_execution.txt
|
270
57
|
- examples/pattern_extracting.rb
|
271
58
|
- examples/pattern_matching_binary_tree_set.rb
|
272
59
|
- examples/pattern_matching_number_in_words.rb
|
273
60
|
- fear.gemspec
|
274
|
-
- lib/dry/types/fear.rb
|
275
|
-
- lib/dry/types/fear/option.rb
|
276
61
|
- lib/fear.rb
|
277
62
|
- lib/fear/await.rb
|
278
63
|
- lib/fear/awaitable.rb
|
279
64
|
- lib/fear/either.rb
|
65
|
+
- lib/fear/either/left_projection.rb
|
66
|
+
- lib/fear/either/pattern_match.rb
|
280
67
|
- lib/fear/either_api.rb
|
281
|
-
- lib/fear/either_pattern_match.rb
|
282
68
|
- lib/fear/empty_partial_function.rb
|
283
69
|
- lib/fear/failure.rb
|
284
|
-
- lib/fear/
|
70
|
+
- lib/fear/failure/pattern_match.rb
|
285
71
|
- lib/fear/for.rb
|
286
72
|
- lib/fear/for_api.rb
|
287
73
|
- lib/fear/future.rb
|
288
74
|
- lib/fear/future_api.rb
|
289
75
|
- lib/fear/left.rb
|
290
|
-
- lib/fear/
|
76
|
+
- lib/fear/left/pattern_match.rb
|
291
77
|
- lib/fear/none.rb
|
292
|
-
- lib/fear/
|
78
|
+
- lib/fear/none_class.rb
|
79
|
+
- lib/fear/none_class/pattern_match.rb
|
293
80
|
- lib/fear/option.rb
|
81
|
+
- lib/fear/option/pattern_match.rb
|
294
82
|
- lib/fear/option_api.rb
|
295
|
-
- lib/fear/option_pattern_match.rb
|
296
83
|
- lib/fear/partial_function.rb
|
297
84
|
- lib/fear/partial_function/and_then.rb
|
298
85
|
- lib/fear/partial_function/any.rb
|
@@ -309,28 +96,23 @@ files:
|
|
309
96
|
- lib/fear/pattern_matching_api.rb
|
310
97
|
- lib/fear/promise.rb
|
311
98
|
- lib/fear/right.rb
|
99
|
+
- lib/fear/right/pattern_match.rb
|
312
100
|
- lib/fear/right_biased.rb
|
313
|
-
- lib/fear/right_pattern_match.rb
|
314
101
|
- lib/fear/some.rb
|
315
|
-
- lib/fear/
|
316
|
-
- lib/fear/struct.rb
|
102
|
+
- lib/fear/some/pattern_match.rb
|
317
103
|
- lib/fear/success.rb
|
318
|
-
- lib/fear/
|
104
|
+
- lib/fear/success/pattern_match.rb
|
319
105
|
- lib/fear/try.rb
|
106
|
+
- lib/fear/try/pattern_match.rb
|
320
107
|
- lib/fear/try_api.rb
|
321
|
-
- lib/fear/try_pattern_match.rb
|
322
108
|
- lib/fear/unit.rb
|
323
109
|
- lib/fear/utils.rb
|
324
110
|
- lib/fear/version.rb
|
325
|
-
- spec/dry/types/fear/option/constrained_spec.rb
|
326
|
-
- spec/dry/types/fear/option/core_spec.rb
|
327
|
-
- spec/dry/types/fear/option/default_spec.rb
|
328
|
-
- spec/dry/types/fear/option/hash_spec.rb
|
329
|
-
- spec/dry/types/fear/option/option_spec.rb
|
330
111
|
- spec/fear/awaitable_spec.rb
|
331
112
|
- spec/fear/done_spec.rb
|
113
|
+
- spec/fear/either/left_projection_spec.rb
|
332
114
|
- spec/fear/either/mixin_spec.rb
|
333
|
-
- spec/fear/
|
115
|
+
- spec/fear/either/pattern_match_spec.rb
|
334
116
|
- spec/fear/either_pattern_matching_spec.rb
|
335
117
|
- spec/fear/either_spec.rb
|
336
118
|
- spec/fear/failure_spec.rb
|
@@ -341,7 +123,7 @@ files:
|
|
341
123
|
- spec/fear/left_spec.rb
|
342
124
|
- spec/fear/none_spec.rb
|
343
125
|
- spec/fear/option/mixin_spec.rb
|
344
|
-
- spec/fear/
|
126
|
+
- spec/fear/option/pattern_match_spec.rb
|
345
127
|
- spec/fear/option_pattern_matching_spec.rb
|
346
128
|
- spec/fear/option_spec.rb
|
347
129
|
- spec/fear/partial_function/any_spec.rb
|
@@ -359,14 +141,12 @@ files:
|
|
359
141
|
- spec/fear/some_spec.rb
|
360
142
|
- spec/fear/success_spec.rb
|
361
143
|
- spec/fear/try/mixin_spec.rb
|
144
|
+
- spec/fear/try/try_pattern_match_spec.rb
|
362
145
|
- spec/fear/try_api_spec.rb
|
363
|
-
- spec/fear/try_pattern_match_spec.rb
|
364
146
|
- spec/fear/try_pattern_matching_spec.rb
|
365
147
|
- spec/fear/utils_spec.rb
|
366
148
|
- spec/spec_helper.rb
|
367
|
-
- spec/
|
368
|
-
- spec/struct_spec.rb
|
369
|
-
- spec/support/dry_types.rb
|
149
|
+
- spec/support/.keep
|
370
150
|
homepage: https://github.com/bolshakov/fear
|
371
151
|
licenses:
|
372
152
|
- MIT
|
@@ -379,27 +159,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
379
159
|
requirements:
|
380
160
|
- - ">="
|
381
161
|
- !ruby/object:Gem::Version
|
382
|
-
version:
|
162
|
+
version: '3.1'
|
383
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
384
164
|
requirements:
|
385
165
|
- - ">="
|
386
166
|
- !ruby/object:Gem::Version
|
387
167
|
version: '0'
|
388
168
|
requirements: []
|
389
|
-
rubygems_version: 3.
|
169
|
+
rubygems_version: 3.5.7
|
390
170
|
signing_key:
|
391
171
|
specification_version: 4
|
392
172
|
summary: "%q{Ruby port of some Scala's monads.}"
|
393
173
|
test_files:
|
394
|
-
- spec/dry/types/fear/option/constrained_spec.rb
|
395
|
-
- spec/dry/types/fear/option/core_spec.rb
|
396
|
-
- spec/dry/types/fear/option/default_spec.rb
|
397
|
-
- spec/dry/types/fear/option/hash_spec.rb
|
398
|
-
- spec/dry/types/fear/option/option_spec.rb
|
399
174
|
- spec/fear/awaitable_spec.rb
|
400
175
|
- spec/fear/done_spec.rb
|
176
|
+
- spec/fear/either/left_projection_spec.rb
|
401
177
|
- spec/fear/either/mixin_spec.rb
|
402
|
-
- spec/fear/
|
178
|
+
- spec/fear/either/pattern_match_spec.rb
|
403
179
|
- spec/fear/either_pattern_matching_spec.rb
|
404
180
|
- spec/fear/either_spec.rb
|
405
181
|
- spec/fear/failure_spec.rb
|
@@ -410,7 +186,7 @@ test_files:
|
|
410
186
|
- spec/fear/left_spec.rb
|
411
187
|
- spec/fear/none_spec.rb
|
412
188
|
- spec/fear/option/mixin_spec.rb
|
413
|
-
- spec/fear/
|
189
|
+
- spec/fear/option/pattern_match_spec.rb
|
414
190
|
- spec/fear/option_pattern_matching_spec.rb
|
415
191
|
- spec/fear/option_spec.rb
|
416
192
|
- spec/fear/partial_function/any_spec.rb
|
@@ -428,11 +204,9 @@ test_files:
|
|
428
204
|
- spec/fear/some_spec.rb
|
429
205
|
- spec/fear/success_spec.rb
|
430
206
|
- spec/fear/try/mixin_spec.rb
|
207
|
+
- spec/fear/try/try_pattern_match_spec.rb
|
431
208
|
- spec/fear/try_api_spec.rb
|
432
|
-
- spec/fear/try_pattern_match_spec.rb
|
433
209
|
- spec/fear/try_pattern_matching_spec.rb
|
434
210
|
- spec/fear/utils_spec.rb
|
435
211
|
- spec/spec_helper.rb
|
436
|
-
- spec/
|
437
|
-
- spec/struct_spec.rb
|
438
|
-
- spec/support/dry_types.rb
|
212
|
+
- spec/support/.keep
|
@@ -1,11 +0,0 @@
|
|
1
|
-
> bundle exec rake perf:fear:pattern_extracting_with_vs_without_cache
|
2
|
-
Warming up --------------------------------------
|
3
|
-
With cache 1.555k i/100ms
|
4
|
-
Without cache 164.000 i/100ms
|
5
|
-
Calculating -------------------------------------
|
6
|
-
With cache 26.159M (±14.7%) i/s - 124.607M in 4.958175s
|
7
|
-
Without cache 278.285k (±10.5%) i/s - 1.368M in 4.993567s
|
8
|
-
|
9
|
-
Comparison:
|
10
|
-
With cache: 26159162.8 i/s
|
11
|
-
Without cache: 278285.4 i/s - 94.00x slower
|
@@ -1,11 +0,0 @@
|
|
1
|
-
> bundle exec rake perf:pattern_matching:qo_vs_fear_pattern_extraction
|
2
|
-
Warming up --------------------------------------
|
3
|
-
Qo 12.352k i/100ms
|
4
|
-
Fear 6.841k i/100ms
|
5
|
-
Calculating -------------------------------------
|
6
|
-
Qo 142.416k (± 4.3%) i/s - 716.416k in 5.040430s
|
7
|
-
Fear 88.179k (± 4.8%) i/s - 444.665k in 5.055908s
|
8
|
-
|
9
|
-
Comparison:
|
10
|
-
Qo: 142415.6 i/s
|
11
|
-
Fear: 88179.5 i/s - 1.62x slower
|
@@ -1,11 +0,0 @@
|
|
1
|
-
> bundle exec rake perf:pattern_matching:qo_vs_fear_try_execution
|
2
|
-
Warming up --------------------------------------
|
3
|
-
Qo 10.079k i/100ms
|
4
|
-
Fear 25.868k i/100ms
|
5
|
-
Calculating -------------------------------------
|
6
|
-
Qo 142.209k (± 3.8%) i/s - 715.609k in 5.039975s
|
7
|
-
Fear 395.999k (± 2.5%) i/s - 1.992M in 5.033046s
|
8
|
-
|
9
|
-
Comparison:
|
10
|
-
Fear: 395999.2 i/s
|
11
|
-
Qo: 142209.4 i/s - 2.78x slower
|
@@ -1,125 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Dry
|
4
|
-
module Types
|
5
|
-
class Option
|
6
|
-
include Type
|
7
|
-
include ::Dry::Equalizer(:type, :options, inspect: false, immutable: true)
|
8
|
-
include Decorator
|
9
|
-
include Builder
|
10
|
-
include Printable
|
11
|
-
|
12
|
-
# @param [Fear::Option, Object] input
|
13
|
-
#
|
14
|
-
# @return [Fear::Option]
|
15
|
-
#
|
16
|
-
# @api private
|
17
|
-
def call_unsafe(input = Undefined)
|
18
|
-
case input
|
19
|
-
when ::Fear::Option
|
20
|
-
input
|
21
|
-
when Undefined
|
22
|
-
Fear.none
|
23
|
-
else
|
24
|
-
Fear.option(type.call_unsafe(input))
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# @param [Fear::Option, Object] input
|
29
|
-
#
|
30
|
-
# @return [Fear::Option]
|
31
|
-
#
|
32
|
-
# @api private
|
33
|
-
def call_safe(input = Undefined)
|
34
|
-
case input
|
35
|
-
when ::Fear::Option
|
36
|
-
input
|
37
|
-
when Undefined
|
38
|
-
Fear.none
|
39
|
-
else
|
40
|
-
Fear.option(type.call_safe(input) { |output = input| return yield(output) })
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# @param [Object] input
|
45
|
-
#
|
46
|
-
# @return [Result::Success]
|
47
|
-
#
|
48
|
-
# @api public
|
49
|
-
def try(input = Undefined)
|
50
|
-
result = type.try(input)
|
51
|
-
|
52
|
-
if result.success?
|
53
|
-
Result::Success.new(Fear.option(result.input))
|
54
|
-
else
|
55
|
-
result
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# @return [true]
|
60
|
-
#
|
61
|
-
# @api public
|
62
|
-
def default?
|
63
|
-
true
|
64
|
-
end
|
65
|
-
|
66
|
-
# @param [Object] value
|
67
|
-
#
|
68
|
-
# @see Dry::Types::Builder#default
|
69
|
-
#
|
70
|
-
# @raise [ArgumentError] if nil provided as default value
|
71
|
-
#
|
72
|
-
# @api public
|
73
|
-
def default(value)
|
74
|
-
if value.nil?
|
75
|
-
raise ArgumentError, "nil cannot be used as a default of a maybe type"
|
76
|
-
else
|
77
|
-
super
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
module Builder
|
83
|
-
# Turn a type into a maybe type
|
84
|
-
#
|
85
|
-
# @return [Option]
|
86
|
-
#
|
87
|
-
# @api public
|
88
|
-
def option
|
89
|
-
Option.new(Types["nil"] | self)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# @api private
|
94
|
-
class Schema
|
95
|
-
class Key
|
96
|
-
# @api private
|
97
|
-
def option
|
98
|
-
__new__(type.option)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# @api private
|
104
|
-
class Printer
|
105
|
-
MAPPING[Option] = :visit_option
|
106
|
-
|
107
|
-
# @api private
|
108
|
-
def visit_option(maybe)
|
109
|
-
visit(maybe.type) do |type|
|
110
|
-
yield "Fear::Option<#{type}>"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Register non-coercible maybe types
|
116
|
-
NON_NIL.each_key do |name|
|
117
|
-
register("option.strict.#{name}", self[name.to_s].option)
|
118
|
-
end
|
119
|
-
|
120
|
-
# Register coercible maybe types
|
121
|
-
COERCIBLE.each_key do |name|
|
122
|
-
register("option.coercible.#{name}", self["coercible.#{name}"].option)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
data/lib/dry/types/fear.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "fear/pattern_match"
|
4
|
-
|
5
|
-
module Fear
|
6
|
-
# Either pattern matcher
|
7
|
-
#
|
8
|
-
# @example
|
9
|
-
# pattern_match =
|
10
|
-
# EitherPatternMatch.new
|
11
|
-
# .right(Integer, ->(x) { x > 2 }) { |x| x * 2 }
|
12
|
-
# .right(String) { |x| x.to_i * 2 }
|
13
|
-
# .left(String) { :err }
|
14
|
-
# .else { 'error '}
|
15
|
-
#
|
16
|
-
# pattern_match.call(42) => 'NaN'
|
17
|
-
#
|
18
|
-
# @example the same matcher may be defined using block syntax
|
19
|
-
# EitherPatternMatch.new do |m|
|
20
|
-
# m.right(Integer, ->(x) { x > 2 }) { |x| x * 2 }
|
21
|
-
# m.right(String) { |x| x.to_i * 2 }
|
22
|
-
# m.left(String) { :err }
|
23
|
-
# m.else { 'error '}
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
# @note it has two optimized subclasses +Fear::LeftPatternMatch+ and +Fear::RightPatternMatch+
|
27
|
-
# @api private
|
28
|
-
class EitherPatternMatch < Fear::PatternMatch
|
29
|
-
# Match against +Fear::Right+
|
30
|
-
#
|
31
|
-
# @param conditions [<#==>]
|
32
|
-
# @return [Fear::EitherPatternMatch]
|
33
|
-
def right(*conditions, &effect)
|
34
|
-
branch = Fear.case(Fear::Right, &:right_value).and_then(Fear.case(*conditions, &effect))
|
35
|
-
or_else(branch)
|
36
|
-
end
|
37
|
-
alias success right
|
38
|
-
|
39
|
-
# Match against +Fear::Left+
|
40
|
-
#
|
41
|
-
# @param conditions [<#==>]
|
42
|
-
# @return [Fear::EitherPatternMatch]
|
43
|
-
def left(*conditions, &effect)
|
44
|
-
branch = Fear.case(Fear::Left, &:left_value).and_then(Fear.case(*conditions, &effect))
|
45
|
-
or_else(branch)
|
46
|
-
end
|
47
|
-
alias failure left
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
require "fear/left_pattern_match"
|
52
|
-
require "fear/right_pattern_match"
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Fear
|
4
|
-
# @api private
|
5
|
-
class NonePatternMatch < OptionPatternMatch
|
6
|
-
# @param conditions [<#==>]
|
7
|
-
# @return [Fear::OptionPatternMatch]
|
8
|
-
def some(*_conditions)
|
9
|
-
self
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
private_constant :NonePatternMatch
|
14
|
-
end
|