fear 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +105 -0
- data/.simplecov +2 -2
- data/.standard.yml +1 -0
- data/Gemfile +14 -14
- data/Gemfile.lock +56 -37
- data/Rakefile +24 -24
- data/examples/pattern_extracting.rb +2 -2
- data/examples/pattern_matching_number_in_words.rb +12 -12
- data/fear.gemspec +2 -3
- data/lib/fear/either/left_projection.rb +5 -5
- data/lib/fear/either/pattern_match.rb +2 -2
- data/lib/fear/either.rb +1 -1
- data/lib/fear/empty_partial_function.rb +2 -2
- data/lib/fear/failure.rb +4 -4
- data/lib/fear/for.rb +1 -1
- data/lib/fear/for_api.rb +1 -1
- data/lib/fear/future.rb +5 -5
- data/lib/fear/left/pattern_match.rb +1 -1
- data/lib/fear/left.rb +3 -3
- data/lib/fear/none_class.rb +2 -2
- data/lib/fear/option.rb +1 -1
- data/lib/fear/partial_function/and_then.rb +2 -2
- data/lib/fear/partial_function/combined.rb +3 -3
- data/lib/fear/partial_function/or_else.rb +2 -2
- data/lib/fear/partial_function_class.rb +1 -1
- data/lib/fear/pattern_match.rb +2 -2
- data/lib/fear/pattern_matching_api.rb +1 -1
- data/lib/fear/right/pattern_match.rb +1 -1
- data/lib/fear/right.rb +3 -3
- data/lib/fear/right_biased.rb +2 -2
- data/lib/fear/some.rb +2 -2
- data/lib/fear/success.rb +4 -4
- data/lib/fear/try_api.rb +1 -1
- data/lib/fear/utils.rb +1 -1
- data/lib/fear/version.rb +1 -1
- data/spec/fear/either/pattern_match_spec.rb +6 -6
- data/spec/fear/either_spec.rb +1 -1
- data/spec/fear/left_spec.rb +1 -1
- data/spec/fear/option/pattern_match_spec.rb +5 -5
- data/spec/fear/option_spec.rb +2 -2
- data/spec/fear/partial_function/any_spec.rb +3 -3
- data/spec/fear/partial_function/empty_spec.rb +1 -1
- data/spec/fear/partial_function_and_then_spec.rb +5 -5
- data/spec/fear/partial_function_composition_spec.rb +6 -6
- data/spec/fear/partial_function_or_else_spec.rb +13 -13
- data/spec/fear/partial_function_spec.rb +7 -7
- data/spec/fear/pattern_match_spec.rb +5 -5
- data/spec/fear/right_spec.rb +1 -1
- data/spec/fear/try/try_pattern_match_spec.rb +6 -6
- data/spec/fear/try_api_spec.rb +2 -2
- data/spec/fear/utils_spec.rb +3 -3
- metadata +7 -50
- data/.github/workflows/rubocop.yml +0 -39
- data/.github/workflows/spec.yml +0 -39
- data/.rubocop.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdf54d778e33252c0142afd3c50e88cf47c5cebcb76f744f9e4e344914bd1d59
|
4
|
+
data.tar.gz: edb69fd084acfd7d33acb233b34ba285632ab0220b43b24b1d557d81c83ade06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b07156c7031a8da348d502aac6cca48bf3a0d5d02cf4396cfe5aa3219a5f2fcc647293c1bdbc25332db4256bd10691425dde21a75afc5707cd27ee0bfb6b3e84
|
7
|
+
data.tar.gz: d32bd3164eaad7b7ca594776487e58370037a3e16da450bce94177035590555e2d5bd588f9d7fe5e00863e72f4f861f12203da7d187943e5d5401ee3cc979459
|
@@ -0,0 +1,105 @@
|
|
1
|
+
name: Fear
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
push:
|
6
|
+
branches: [ master ]
|
7
|
+
|
8
|
+
permissions: # added using https://github.com/step-security/secure-repo
|
9
|
+
contents: read
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
standard:
|
13
|
+
name: Standard 👮
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
permissions:
|
16
|
+
checks: write
|
17
|
+
contents: read
|
18
|
+
steps:
|
19
|
+
- name: Harden the runner (Audit all outbound calls)
|
20
|
+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
|
21
|
+
with:
|
22
|
+
egress-policy: audit
|
23
|
+
|
24
|
+
- name: Checkout code
|
25
|
+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
26
|
+
- name: Standard Ruby
|
27
|
+
uses: standardrb/standard-ruby-action@eecb3f730879f5b8830705348c2961e5aa26de78 # v1.5.0
|
28
|
+
with:
|
29
|
+
autofix: false
|
30
|
+
|
31
|
+
specs:
|
32
|
+
permissions:
|
33
|
+
checks: write # for coverallsapp/github-action to create new checks
|
34
|
+
contents: read # for actions/checkout to fetch code
|
35
|
+
runs-on: ubuntu-latest
|
36
|
+
strategy:
|
37
|
+
matrix:
|
38
|
+
ruby: [ '3.2', "3.3", "3.4", "truffleruby+graalvm-head" ]
|
39
|
+
name: Specs on Ruby ${{ matrix.ruby }} 💚
|
40
|
+
steps:
|
41
|
+
- name: Harden the runner (Audit all outbound calls)
|
42
|
+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
|
43
|
+
with:
|
44
|
+
egress-policy: audit
|
45
|
+
|
46
|
+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
47
|
+
- name: Set up ruby
|
48
|
+
uses: ruby/setup-ruby@2a7b30092b0caf9c046252510f9273b4875f3db9 # v1.254.0
|
49
|
+
with:
|
50
|
+
ruby-version: ${{ matrix.ruby }}
|
51
|
+
bundler-cache: true
|
52
|
+
- name: Specs
|
53
|
+
run: bundle exec rspec
|
54
|
+
- name: Coveralls
|
55
|
+
uses: coverallsapp/github-action@8cbef1dea373ebce56de0a14c68d6267baa10b44 # v1.1.2
|
56
|
+
with:
|
57
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
58
|
+
flag-name: ruby-${{ matrix.ruby }}
|
59
|
+
parallel: true
|
60
|
+
|
61
|
+
release:
|
62
|
+
name: Release Ruby Gem 📦
|
63
|
+
runs-on: ubuntu-latest
|
64
|
+
environment: release
|
65
|
+
needs: [specs, standard]
|
66
|
+
if: github.ref == 'refs/heads/master'
|
67
|
+
permissions:
|
68
|
+
id-token: write # this permission is mandatory for trusted publishing
|
69
|
+
contents: write # this permission is required for `rake release` to push the release tag
|
70
|
+
steps:
|
71
|
+
- name: Harden the runner (Audit all outbound calls)
|
72
|
+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
|
73
|
+
with:
|
74
|
+
egress-policy: audit
|
75
|
+
|
76
|
+
- name: Checkout code
|
77
|
+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
78
|
+
with:
|
79
|
+
persist-credentials: false
|
80
|
+
|
81
|
+
- name: Set up Ruby
|
82
|
+
uses: ruby/setup-ruby@bb6434c747fa7022e12fa1cae2a0951fcffcff26 # v1.253.0
|
83
|
+
with:
|
84
|
+
bundler-cache: true
|
85
|
+
ruby-version: ruby
|
86
|
+
|
87
|
+
- name: Release Gem
|
88
|
+
uses: rubygems/release-gem@ebe1ec66bd8d2c709ac29aa2b43438d450e7a0a6 # v1
|
89
|
+
|
90
|
+
finish:
|
91
|
+
permissions:
|
92
|
+
checks: write # for coverallsapp/github-action to create new checks
|
93
|
+
needs: specs
|
94
|
+
runs-on: ubuntu-latest
|
95
|
+
steps:
|
96
|
+
- name: Harden the runner (Audit all outbound calls)
|
97
|
+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
|
98
|
+
with:
|
99
|
+
egress-policy: audit
|
100
|
+
|
101
|
+
- name: Coveralls Finished
|
102
|
+
uses: coverallsapp/github-action@09b709cf6a16e30b0808ba050c7a6e8a5ef13f8d # master
|
103
|
+
with:
|
104
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
105
|
+
parallel-finished: true
|
data/.simplecov
CHANGED
data/.standard.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby_version: 3.2
|
data/Gemfile
CHANGED
@@ -5,17 +5,17 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in functional.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
|
9
|
-
gem "
|
10
|
-
gem "
|
11
|
-
gem "dry-
|
12
|
-
gem "dry-
|
13
|
-
gem "
|
14
|
-
gem "
|
15
|
-
gem "
|
16
|
-
gem "
|
17
|
-
gem "
|
18
|
-
gem "
|
19
|
-
gem "
|
20
|
-
gem "
|
21
|
-
|
8
|
+
group :development do
|
9
|
+
gem "benchmark-ips"
|
10
|
+
gem "concurrent-ruby"
|
11
|
+
gem "dry-matcher"
|
12
|
+
gem "dry-monads"
|
13
|
+
gem "dry-types"
|
14
|
+
gem "fear-rspec"
|
15
|
+
gem "rake"
|
16
|
+
gem "rspec"
|
17
|
+
gem "simplecov"
|
18
|
+
gem "simplecov-lcov"
|
19
|
+
gem "standard"
|
20
|
+
gem "yard"
|
21
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fear (3.
|
4
|
+
fear (3.1.0)
|
5
5
|
zeitwerk
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
ast (2.4.
|
11
|
-
benchmark-ips (2.
|
12
|
-
bigdecimal (3.1.
|
13
|
-
concurrent-ruby (1.
|
10
|
+
ast (2.4.3)
|
11
|
+
benchmark-ips (2.14.0)
|
12
|
+
bigdecimal (3.1.9)
|
13
|
+
concurrent-ruby (1.3.5)
|
14
14
|
diff-lcs (1.5.1)
|
15
15
|
docile (1.4.0)
|
16
|
-
dry-core (1.0
|
16
|
+
dry-core (1.1.0)
|
17
17
|
concurrent-ruby (~> 1.0)
|
18
|
+
logger
|
18
19
|
zeitwerk (~> 2.6)
|
19
|
-
dry-inflector (1.
|
20
|
-
dry-logic (1.
|
20
|
+
dry-inflector (1.2.0)
|
21
|
+
dry-logic (1.6.0)
|
22
|
+
bigdecimal
|
21
23
|
concurrent-ruby (~> 1.0)
|
22
|
-
dry-core (~> 1.
|
24
|
+
dry-core (~> 1.1)
|
23
25
|
zeitwerk (~> 2.6)
|
24
26
|
dry-matcher (1.0.0)
|
25
27
|
dry-core (~> 1.0, < 2)
|
@@ -27,7 +29,7 @@ GEM
|
|
27
29
|
concurrent-ruby (~> 1.0)
|
28
30
|
dry-core (~> 1.0, < 2)
|
29
31
|
zeitwerk (~> 2.6)
|
30
|
-
dry-types (1.
|
32
|
+
dry-types (1.8.2)
|
31
33
|
bigdecimal (~> 3.0)
|
32
34
|
concurrent-ruby (~> 1.0)
|
33
35
|
dry-core (~> 1.0)
|
@@ -37,16 +39,19 @@ GEM
|
|
37
39
|
fear-rspec (0.3.0)
|
38
40
|
fear (>= 1.0.0)
|
39
41
|
rspec (~> 3.0)
|
40
|
-
json (2.
|
41
|
-
|
42
|
-
|
42
|
+
json (2.13.2)
|
43
|
+
language_server-protocol (3.17.0.5)
|
44
|
+
lint_roller (1.1.0)
|
45
|
+
logger (1.6.5)
|
46
|
+
parallel (1.27.0)
|
47
|
+
parser (3.3.9.0)
|
43
48
|
ast (~> 2.4.1)
|
44
49
|
racc
|
45
|
-
|
50
|
+
prism (1.4.0)
|
51
|
+
racc (1.8.1)
|
46
52
|
rainbow (3.1.1)
|
47
|
-
rake (13.1
|
48
|
-
regexp_parser (2.
|
49
|
-
rexml (3.2.6)
|
53
|
+
rake (13.2.1)
|
54
|
+
regexp_parser (2.11.0)
|
50
55
|
rspec (3.13.0)
|
51
56
|
rspec-core (~> 3.13.0)
|
52
57
|
rspec-expectations (~> 3.13.0)
|
@@ -60,23 +65,25 @@ GEM
|
|
60
65
|
diff-lcs (>= 1.2.0, < 2.0)
|
61
66
|
rspec-support (~> 3.13.0)
|
62
67
|
rspec-support (3.13.1)
|
63
|
-
rubocop (1.
|
68
|
+
rubocop (1.75.8)
|
64
69
|
json (~> 2.3)
|
70
|
+
language_server-protocol (~> 3.17.0.2)
|
71
|
+
lint_roller (~> 1.1.0)
|
65
72
|
parallel (~> 1.10)
|
66
|
-
parser (>= 3.
|
73
|
+
parser (>= 3.3.0.2)
|
67
74
|
rainbow (>= 2.2.2, < 4.0)
|
68
|
-
regexp_parser (>=
|
69
|
-
|
70
|
-
rubocop-ast (>= 1.19.1, < 2.0)
|
75
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
76
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
71
77
|
ruby-progressbar (~> 1.7)
|
72
|
-
unicode-display_width (>=
|
73
|
-
rubocop-ast (1.
|
74
|
-
parser (>= 3.3.
|
75
|
-
|
76
|
-
|
78
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
79
|
+
rubocop-ast (1.46.0)
|
80
|
+
parser (>= 3.3.7.2)
|
81
|
+
prism (~> 1.4)
|
82
|
+
rubocop-performance (1.25.0)
|
83
|
+
lint_roller (~> 1.1)
|
84
|
+
rubocop (>= 1.75.0, < 2.0)
|
85
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
77
86
|
ruby-progressbar (1.13.0)
|
78
|
-
ruby_coding_standard (0.4.0)
|
79
|
-
rubocop (~> 1.32.0)
|
80
87
|
simplecov (0.22.0)
|
81
88
|
docile (~> 1.1)
|
82
89
|
simplecov-html (~> 0.11)
|
@@ -84,9 +91,23 @@ GEM
|
|
84
91
|
simplecov-html (0.12.3)
|
85
92
|
simplecov-lcov (0.8.0)
|
86
93
|
simplecov_json_formatter (0.1.4)
|
87
|
-
|
88
|
-
|
89
|
-
|
94
|
+
standard (1.50.0)
|
95
|
+
language_server-protocol (~> 3.17.0.2)
|
96
|
+
lint_roller (~> 1.0)
|
97
|
+
rubocop (~> 1.75.5)
|
98
|
+
standard-custom (~> 1.0.0)
|
99
|
+
standard-performance (~> 1.8)
|
100
|
+
standard-custom (1.0.2)
|
101
|
+
lint_roller (~> 1.0)
|
102
|
+
rubocop (~> 1.50)
|
103
|
+
standard-performance (1.8.0)
|
104
|
+
lint_roller (~> 1.1)
|
105
|
+
rubocop-performance (~> 1.25.0)
|
106
|
+
unicode-display_width (3.1.4)
|
107
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
108
|
+
unicode-emoji (4.0.4)
|
109
|
+
yard (0.9.37)
|
110
|
+
zeitwerk (2.6.18)
|
90
111
|
|
91
112
|
PLATFORMS
|
92
113
|
ruby
|
@@ -99,13 +120,11 @@ DEPENDENCIES
|
|
99
120
|
dry-types
|
100
121
|
fear!
|
101
122
|
fear-rspec
|
102
|
-
rake
|
103
|
-
rspec
|
104
|
-
rubocop (= 1.32.0)
|
105
|
-
rubocop-rspec (= 1.34.0)
|
106
|
-
ruby_coding_standard
|
123
|
+
rake
|
124
|
+
rspec
|
107
125
|
simplecov
|
108
126
|
simplecov-lcov
|
127
|
+
standard
|
109
128
|
yard
|
110
129
|
|
111
130
|
BUNDLED WITH
|
data/Rakefile
CHANGED
@@ -7,6 +7,20 @@ require_relative "lib/fear"
|
|
7
7
|
|
8
8
|
include Dry::Monads[:maybe]
|
9
9
|
|
10
|
+
class Operation
|
11
|
+
include Dry::Monads::Do.for(:call)
|
12
|
+
|
13
|
+
def call
|
14
|
+
m1 = Some(1)
|
15
|
+
m2 = Some(2)
|
16
|
+
|
17
|
+
one = yield m1
|
18
|
+
two = yield m2
|
19
|
+
|
20
|
+
Some(one + two)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
10
24
|
namespace :perf do
|
11
25
|
# Contains benchmarking against Dry-rb
|
12
26
|
namespace :dry do
|
@@ -26,24 +40,10 @@ namespace :perf do
|
|
26
40
|
task :do_vs_fear_for do
|
27
41
|
require "dry/monads/do"
|
28
42
|
|
29
|
-
class Operation
|
30
|
-
include Dry::Monads::Do.for(:call)
|
31
|
-
|
32
|
-
def call
|
33
|
-
m1 = Some(1)
|
34
|
-
m2 = Some(2)
|
35
|
-
|
36
|
-
one = yield m1
|
37
|
-
two = yield m2
|
38
|
-
|
39
|
-
Some(one + two)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
43
|
op = Operation.new
|
44
44
|
|
45
45
|
Benchmark.ips do |x|
|
46
|
-
x.report("Dry") { op.
|
46
|
+
x.report("Dry") { op.call }
|
47
47
|
|
48
48
|
x.report("Fear") do |_n|
|
49
49
|
Fear.for(Fear.some(1), Fear.some(2)) do |one, two|
|
@@ -141,7 +141,7 @@ namespace :perf do
|
|
141
141
|
end
|
142
142
|
|
143
143
|
x.report("execution") do
|
144
|
-
matcher.(42)
|
144
|
+
matcher.call(42)
|
145
145
|
end
|
146
146
|
|
147
147
|
x.compare!
|
@@ -178,7 +178,7 @@ namespace :perf do
|
|
178
178
|
end
|
179
179
|
|
180
180
|
x.report("Option#matcher") do
|
181
|
-
matcher.(some)
|
181
|
+
matcher.call(some)
|
182
182
|
end
|
183
183
|
|
184
184
|
x.compare!
|
@@ -194,14 +194,14 @@ namespace :perf do
|
|
194
194
|
match: ->(try, *pattern) {
|
195
195
|
try.is_a?(Fear::Success) && pattern.all? { |p| p === try.get }
|
196
196
|
},
|
197
|
-
resolve: ->(try) { try.get }
|
197
|
+
resolve: ->(try) { try.get }
|
198
198
|
)
|
199
199
|
|
200
200
|
failure_case = Dry::Matcher::Case.new(
|
201
201
|
match: ->(try, *pattern) {
|
202
202
|
try.is_a?(Fear::Failure) && pattern.all? { |p| p === try.exception }
|
203
203
|
},
|
204
|
-
resolve: ->(value) { value.exception }
|
204
|
+
resolve: ->(value) { value.exception }
|
205
205
|
)
|
206
206
|
|
207
207
|
# Build the matcher
|
@@ -219,7 +219,7 @@ namespace :perf do
|
|
219
219
|
end
|
220
220
|
|
221
221
|
x.report("Dr::Matcher") do
|
222
|
-
matcher.(success) do |m|
|
222
|
+
matcher.call(success) do |m|
|
223
223
|
m.failure(&:itself)
|
224
224
|
m.success(Integer, ->(y) { y % 5 == 0 }, &:itself)
|
225
225
|
m.success { "else" }
|
@@ -235,23 +235,23 @@ namespace :perf do
|
|
235
235
|
if n <= 1
|
236
236
|
1
|
237
237
|
else
|
238
|
-
n * factorial_proc.(n - 1)
|
238
|
+
n * factorial_proc.call(n - 1)
|
239
239
|
end
|
240
240
|
end
|
241
241
|
|
242
242
|
factorial_pm = Fear.matcher do |m|
|
243
243
|
m.case(1, &:itself)
|
244
244
|
m.case(0, &:itself)
|
245
|
-
m.else { |n| n * factorial_pm.(n - 1) }
|
245
|
+
m.else { |n| n * factorial_pm.call(n - 1) }
|
246
246
|
end
|
247
247
|
|
248
248
|
Benchmark.ips do |x|
|
249
249
|
x.report("Proc") do
|
250
|
-
factorial_proc.(100)
|
250
|
+
factorial_proc.call(100)
|
251
251
|
end
|
252
252
|
|
253
253
|
x.report("Fear") do
|
254
|
-
factorial_pm.(100)
|
254
|
+
factorial_pm.call(100)
|
255
255
|
end
|
256
256
|
|
257
257
|
x.compare!
|
@@ -31,7 +31,7 @@ class ToWords
|
|
31
31
|
60 => "sixty",
|
32
32
|
70 => "seventy",
|
33
33
|
80 => "eighty",
|
34
|
-
90 => "ninety"
|
34
|
+
90 => "ninety"
|
35
35
|
}.freeze
|
36
36
|
private_constant :NUMBERS
|
37
37
|
|
@@ -39,22 +39,22 @@ class ToWords
|
|
39
39
|
NUMBERS.each_pair do |number, in_words|
|
40
40
|
m.case(number) { in_words }
|
41
41
|
end
|
42
|
-
m.case(->(n) { n < 0 }) { |n| "minus #{CONVERTER.(-n)}" }
|
43
|
-
m.case(->(n) { n < 100 }) { |n| "#{CONVERTER.((n / 10) * 10)}-#{CONVERTER.(n % 10)}" }
|
44
|
-
m.case(->(n) { n < 200 }) { |n| "one hundred #{CONVERTER.(n % 100)}" }
|
45
|
-
m.case(->(n) { n < 1_000 }) { |n| "#{CONVERTER.(n / 100)} hundreds #{CONVERTER.(n % 100)}" }
|
46
|
-
m.case(->(n) { n < 2_000 }) { |n| "one thousand #{CONVERTER.(n % 1000)}" }
|
47
|
-
m.case(->(n) { n < 1_000_000 }) { |n| "#{CONVERTER.(n / 1_000)} thousands #{CONVERTER.(n % 1_000)}" }
|
42
|
+
m.case(->(n) { n < 0 }) { |n| "minus #{CONVERTER.call(-n)}" }
|
43
|
+
m.case(->(n) { n < 100 }) { |n| "#{CONVERTER.call((n / 10) * 10)}-#{CONVERTER.call(n % 10)}" }
|
44
|
+
m.case(->(n) { n < 200 }) { |n| "one hundred #{CONVERTER.call(n % 100)}" }
|
45
|
+
m.case(->(n) { n < 1_000 }) { |n| "#{CONVERTER.call(n / 100)} hundreds #{CONVERTER.call(n % 100)}" }
|
46
|
+
m.case(->(n) { n < 2_000 }) { |n| "one thousand #{CONVERTER.call(n % 1000)}" }
|
47
|
+
m.case(->(n) { n < 1_000_000 }) { |n| "#{CONVERTER.call(n / 1_000)} thousands #{CONVERTER.call(n % 1_000)}" }
|
48
48
|
m.else { |n| raise "#{n} too big " }
|
49
49
|
end
|
50
50
|
private_constant :CONVERTER
|
51
51
|
|
52
52
|
def self.call(number)
|
53
|
-
Fear.case(Integer, &:itself).and_then(CONVERTER).(number)
|
53
|
+
Fear.case(Integer, &:itself).and_then(CONVERTER).call(number)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
ToWords.(99) #=> 'ninety-nine'
|
58
|
-
ToWords.(133) #=> 'one hundred thirty-three
|
59
|
-
ToWords.(777) #=> 'seven hundreds seventy-seven'
|
60
|
-
ToWords.(254_555) #=> 'two hundreds fifty-four thousands five hundreds fifty-five'
|
57
|
+
ToWords.call(99) #=> 'ninety-nine'
|
58
|
+
ToWords.call(133) #=> 'one hundred thirty-three
|
59
|
+
ToWords.call(777) #=> 'seven hundreds seventy-seven'
|
60
|
+
ToWords.call(254_555) #=> 'two hundreds fifty-four thousands five hundreds fifty-five'
|
data/fear.gemspec
CHANGED
@@ -16,10 +16,9 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.license = "MIT"
|
17
17
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0")
|
19
|
-
spec.executables = spec.files.grep(%r{^bin
|
20
|
-
spec.test_files = spec.files.grep(%r{^spec\/})
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
20
|
spec.require_paths = ["lib"]
|
22
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 3.
|
21
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.2")
|
23
22
|
|
24
23
|
spec.add_runtime_dependency "zeitwerk"
|
25
24
|
end
|
@@ -82,7 +82,7 @@ module Fear
|
|
82
82
|
either
|
83
83
|
end
|
84
84
|
end
|
85
|
-
|
85
|
+
alias_method :apply, :each
|
86
86
|
|
87
87
|
# Maps the block argument through +Fear::Left+.
|
88
88
|
#
|
@@ -169,7 +169,7 @@ module Fear
|
|
169
169
|
def any?(&predicate)
|
170
170
|
case either
|
171
171
|
in Fear::Left(value)
|
172
|
-
predicate.(value)
|
172
|
+
predicate.call(value)
|
173
173
|
in Fear::Right
|
174
174
|
false
|
175
175
|
end
|
@@ -191,7 +191,7 @@ module Fear
|
|
191
191
|
case either
|
192
192
|
in Fear::Right
|
193
193
|
either
|
194
|
-
in Fear::Left(value) if predicate.(value)
|
194
|
+
in Fear::Left(value) if predicate.call(value)
|
195
195
|
either
|
196
196
|
in Fear::Left
|
197
197
|
either.swap
|
@@ -211,13 +211,13 @@ module Fear
|
|
211
211
|
#
|
212
212
|
def find(&predicate)
|
213
213
|
case either
|
214
|
-
in Fear::Left(value) if predicate.(value)
|
214
|
+
in Fear::Left(value) if predicate.call(value)
|
215
215
|
Fear.some(either)
|
216
216
|
in Fear::Either
|
217
217
|
Fear.none
|
218
218
|
end
|
219
219
|
end
|
220
|
-
|
220
|
+
alias_method :detect, :find
|
221
221
|
|
222
222
|
# @param other [Object]
|
223
223
|
# @return [Boolean]
|
@@ -33,7 +33,7 @@ module Fear
|
|
33
33
|
branch = Fear.case(Fear::Right, &:right_value).and_then(Fear.case(*conditions, &effect))
|
34
34
|
or_else(branch)
|
35
35
|
end
|
36
|
-
|
36
|
+
alias_method :success, :right
|
37
37
|
|
38
38
|
# Match against +Fear::Left+
|
39
39
|
#
|
@@ -43,7 +43,7 @@ module Fear
|
|
43
43
|
branch = Fear.case(Fear::Left, &:left_value).and_then(Fear.case(*conditions, &effect))
|
44
44
|
or_else(branch)
|
45
45
|
end
|
46
|
-
|
46
|
+
alias_method :failure, :left
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
data/lib/fear/either.rb
CHANGED
data/lib/fear/failure.rb
CHANGED
@@ -31,7 +31,7 @@ module Fear
|
|
31
31
|
# @return [Try] of calling block
|
32
32
|
def or_else(*args)
|
33
33
|
super
|
34
|
-
rescue
|
34
|
+
rescue => error
|
35
35
|
Failure.new(error)
|
36
36
|
end
|
37
37
|
|
@@ -52,7 +52,7 @@ module Fear
|
|
52
52
|
Fear.matcher { |m| yield(m) }
|
53
53
|
.and_then { |result| result.tap { Utils.assert_type!(result, Success, Failure) } }
|
54
54
|
.call_or_else(exception) { self }
|
55
|
-
rescue
|
55
|
+
rescue => error
|
56
56
|
Failure.new(error)
|
57
57
|
end
|
58
58
|
|
@@ -63,7 +63,7 @@ module Fear
|
|
63
63
|
Fear.matcher { |m| yield(m) }
|
64
64
|
.and_then { |v| Success.new(v) }
|
65
65
|
.call_or_else(exception) { self }
|
66
|
-
rescue
|
66
|
+
rescue => error
|
67
67
|
Failure.new(error)
|
68
68
|
end
|
69
69
|
|
@@ -95,7 +95,7 @@ module Fear
|
|
95
95
|
end
|
96
96
|
|
97
97
|
# @return [String]
|
98
|
-
|
98
|
+
alias_method :to_s, :inspect
|
99
99
|
|
100
100
|
# @return [<StandardError>]
|
101
101
|
def deconstruct
|
data/lib/fear/for.rb
CHANGED
data/lib/fear/for_api.rb
CHANGED
data/lib/fear/future.rb
CHANGED
@@ -221,7 +221,7 @@ module Fear
|
|
221
221
|
# @yieldparam [any] yields with successful feature value
|
222
222
|
# @see {#on_complete}
|
223
223
|
#
|
224
|
-
|
224
|
+
alias_method :each, :on_success
|
225
225
|
|
226
226
|
# Creates a new future by applying the +success+ function to the successful
|
227
227
|
# result of this future, or the +failure+ function to the failed result.
|
@@ -245,8 +245,8 @@ module Fear
|
|
245
245
|
def transform(success, failure)
|
246
246
|
promise = Promise.new(**@options)
|
247
247
|
on_complete_match do |m|
|
248
|
-
m.success { |value| promise.success(success.(value)) }
|
249
|
-
m.failure { |error| promise.failure(failure.(error)) }
|
248
|
+
m.success { |value| promise.success(success.call(value)) }
|
249
|
+
m.failure { |error| promise.failure(failure.call(error)) }
|
250
250
|
end
|
251
251
|
promise.to_future
|
252
252
|
end
|
@@ -293,7 +293,7 @@ module Fear
|
|
293
293
|
m.case(Fear::Failure) { |failure| promise.complete!(failure) }
|
294
294
|
m.success do |value|
|
295
295
|
yield(value).on_complete { |callback_result| promise.complete!(callback_result) }
|
296
|
-
rescue
|
296
|
+
rescue => error
|
297
297
|
promise.failure!(error)
|
298
298
|
end
|
299
299
|
end
|
@@ -379,7 +379,7 @@ module Fear
|
|
379
379
|
else
|
380
380
|
[value, other_value]
|
381
381
|
end
|
382
|
-
end
|
382
|
+
end
|
383
383
|
)
|
384
384
|
end
|
385
385
|
end
|