fear 2.0.1 → 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.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +105 -0
  3. data/.simplecov +2 -2
  4. data/.standard.yml +1 -0
  5. data/CHANGELOG.md +8 -0
  6. data/Gemfile +14 -2
  7. data/Gemfile.lock +84 -78
  8. data/LICENSE.txt +1 -1
  9. data/README.md +18 -70
  10. data/Rakefile +55 -142
  11. data/benchmarks/dry_do_vs_fear_for.txt +7 -6
  12. data/benchmarks/dry_some_fmap_vs_fear_some_map.txt +7 -6
  13. data/benchmarks/factorial.txt +7 -9
  14. data/benchmarks/fear_gaurd_and1_vs_new.txt +7 -6
  15. data/benchmarks/fear_gaurd_and2_vs_and.txt +8 -7
  16. data/benchmarks/fear_gaurd_and3_vs_and_and.txt +7 -6
  17. data/benchmarks/fear_pattern_matching_construction_vs_execution.txt +7 -6
  18. data/benchmarks/pattern_matching_dry_vs_qo_vs_fear_try.txt +8 -10
  19. data/examples/pattern_extracting.rb +2 -2
  20. data/examples/pattern_matching_number_in_words.rb +12 -12
  21. data/fear.gemspec +5 -21
  22. data/lib/fear/either/left_projection.rb +237 -0
  23. data/lib/fear/either/pattern_match.rb +49 -0
  24. data/lib/fear/either.rb +21 -12
  25. data/lib/fear/either_api.rb +2 -4
  26. data/lib/fear/empty_partial_function.rb +3 -3
  27. data/lib/fear/failure/pattern_match.rb +14 -0
  28. data/lib/fear/failure.rb +5 -5
  29. data/lib/fear/for.rb +1 -1
  30. data/lib/fear/for_api.rb +1 -3
  31. data/lib/fear/future.rb +6 -6
  32. data/lib/fear/future_api.rb +0 -5
  33. data/lib/fear/left/pattern_match.rb +15 -0
  34. data/lib/fear/left.rb +4 -4
  35. data/lib/fear/none.rb +0 -87
  36. data/lib/fear/none_class/pattern_match.rb +16 -0
  37. data/lib/fear/none_class.rb +85 -0
  38. data/lib/fear/option/pattern_match.rb +47 -0
  39. data/lib/fear/option.rb +2 -6
  40. data/lib/fear/option_api.rb +1 -3
  41. data/lib/fear/partial_function/and_then.rb +2 -2
  42. data/lib/fear/partial_function/combined.rb +3 -3
  43. data/lib/fear/partial_function/empty.rb +3 -5
  44. data/lib/fear/partial_function/guard.rb +0 -4
  45. data/lib/fear/partial_function/or_else.rb +2 -4
  46. data/lib/fear/partial_function.rb +0 -9
  47. data/lib/fear/partial_function_class.rb +2 -2
  48. data/lib/fear/pattern_match.rb +5 -4
  49. data/lib/fear/pattern_matching_api.rb +1 -4
  50. data/lib/fear/right/pattern_match.rb +15 -0
  51. data/lib/fear/right.rb +4 -4
  52. data/lib/fear/right_biased.rb +2 -0
  53. data/lib/fear/some/pattern_match.rb +15 -0
  54. data/lib/fear/some.rb +3 -3
  55. data/lib/fear/success/pattern_match.rb +16 -0
  56. data/lib/fear/success.rb +5 -5
  57. data/lib/fear/try/pattern_match.rb +29 -0
  58. data/lib/fear/try.rb +3 -7
  59. data/lib/fear/try_api.rb +1 -3
  60. data/lib/fear/utils.rb +1 -1
  61. data/lib/fear/version.rb +1 -1
  62. data/lib/fear.rb +3 -14
  63. data/spec/fear/awaitable_spec.rb +0 -2
  64. data/spec/fear/either/left_projection_spec.rb +289 -0
  65. data/spec/fear/{either_pattern_match_spec.rb → either/pattern_match_spec.rb} +7 -7
  66. data/spec/fear/either_spec.rb +1 -1
  67. data/spec/fear/left_spec.rb +1 -1
  68. data/spec/fear/{option_pattern_match_spec.rb → option/pattern_match_spec.rb} +6 -6
  69. data/spec/fear/option_spec.rb +2 -2
  70. data/spec/fear/partial_function/any_spec.rb +3 -3
  71. data/spec/fear/partial_function/empty_spec.rb +2 -2
  72. data/spec/fear/partial_function_and_then_spec.rb +5 -5
  73. data/spec/fear/partial_function_composition_spec.rb +6 -6
  74. data/spec/fear/partial_function_or_else_spec.rb +13 -13
  75. data/spec/fear/partial_function_spec.rb +7 -7
  76. data/spec/fear/pattern_match_spec.rb +5 -5
  77. data/spec/fear/right_spec.rb +1 -1
  78. data/spec/fear/{try_pattern_match_spec.rb → try/try_pattern_match_spec.rb} +7 -7
  79. data/spec/fear/try_api_spec.rb +2 -2
  80. data/spec/fear/utils_spec.rb +3 -3
  81. data/spec/support/.keep +0 -0
  82. metadata +27 -296
  83. data/.github/workflows/rubocop.yml +0 -39
  84. data/.github/workflows/spec.yml +0 -43
  85. data/.rubocop.yml +0 -7
  86. data/benchmarks/fear_pattern_extracting_with_vs_without_cache.txt +0 -11
  87. data/benchmarks/pattern_matching_qo_vs_fear_pattern_extraction.txt +0 -11
  88. data/benchmarks/pattern_matching_qo_vs_fear_try_execution.txt +0 -11
  89. data/lib/dry/types/fear/option.rb +0 -125
  90. data/lib/dry/types/fear.rb +0 -8
  91. data/lib/fear/either_pattern_match.rb +0 -52
  92. data/lib/fear/failure_pattern_match.rb +0 -12
  93. data/lib/fear/left_pattern_match.rb +0 -11
  94. data/lib/fear/none_pattern_match.rb +0 -14
  95. data/lib/fear/option_pattern_match.rb +0 -50
  96. data/lib/fear/right_pattern_match.rb +0 -13
  97. data/lib/fear/some_pattern_match.rb +0 -13
  98. data/lib/fear/struct.rb +0 -237
  99. data/lib/fear/success_pattern_match.rb +0 -14
  100. data/lib/fear/try_pattern_match.rb +0 -32
  101. data/spec/dry/types/fear/option/constrained_spec.rb +0 -22
  102. data/spec/dry/types/fear/option/core_spec.rb +0 -77
  103. data/spec/dry/types/fear/option/default_spec.rb +0 -21
  104. data/spec/dry/types/fear/option/hash_spec.rb +0 -58
  105. data/spec/dry/types/fear/option/option_spec.rb +0 -97
  106. data/spec/struct_pattern_matching_spec.rb +0 -36
  107. data/spec/struct_spec.rb +0 -194
  108. data/spec/support/dry_types.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 478065fc6d889020eb722d84eed56c46187431bb500a359985ee6e2fcb3277a2
4
- data.tar.gz: 9a92582747a64d9525967dec128f8d4cf7e36a32cfc184b6a06ffe1dbc71cf8f
3
+ metadata.gz: cdf54d778e33252c0142afd3c50e88cf47c5cebcb76f744f9e4e344914bd1d59
4
+ data.tar.gz: edb69fd084acfd7d33acb233b34ba285632ab0220b43b24b1d557d81c83ade06
5
5
  SHA512:
6
- metadata.gz: 9c2ac3a10810f8916efd3dffaa5b71fc57d2c08689ece14dc0fd7e29e9563703221b02f8f482c890cd4c87db784c0459a83395fb2e97acf4cc24a0ca299e5bf4
7
- data.tar.gz: 25f4758ea5c8cb2953e6942e2c64414d135c93f1ffa79f3850dcfe813a4d0b61efc68bb3b6292a3a16f1b76b07e81351393d608728297bdc877ef6b8368db371
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
@@ -9,8 +9,8 @@ end
9
9
  SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(
10
10
  [
11
11
  SimpleCov::Formatter::HTMLFormatter,
12
- SimpleCov::Formatter::LcovFormatter,
13
- ],
12
+ SimpleCov::Formatter::LcovFormatter
13
+ ]
14
14
  )
15
15
  SimpleCov.start do
16
16
  add_filter "spec/"
data/.standard.yml ADDED
@@ -0,0 +1 @@
1
+ ruby_version: 3.2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 3.0.0
2
+
3
+ See full changelog here: https://github.com/bolshakov/fear/releases/tag/v3.0.0
4
+
5
+ ## 2.0.1
6
+
7
+ * Fix Fear.option yard signature ([@bolshakov])
8
+
1
9
  ## 2.0.0
2
10
 
3
11
  * Added `Fear::Option#present?` and `Fear::Option#empty?` methods ([@Lokideos][])
data/Gemfile CHANGED
@@ -5,5 +5,17 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in functional.gemspec
6
6
  gemspec
7
7
 
8
- gem "irb"
9
- gem "qo", github: "baweaver/qo"
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,93 +1,89 @@
1
- GIT
2
- remote: https://github.com/baweaver/qo.git
3
- revision: 8951ce899559118eb60321014b43cf4211730bd0
4
- specs:
5
- qo (0.99.0)
6
- any (= 0.1.0)
7
-
8
1
  PATH
9
2
  remote: .
10
3
  specs:
11
- fear (2.0.1)
4
+ fear (3.1.0)
5
+ zeitwerk
12
6
 
13
7
  GEM
14
8
  remote: https://rubygems.org/
15
9
  specs:
16
- any (0.1.0)
17
- ast (2.4.2)
18
- benchmark-ips (2.12.0)
19
- concurrent-ruby (1.2.2)
20
- diff-lcs (1.5.0)
10
+ ast (2.4.3)
11
+ benchmark-ips (2.14.0)
12
+ bigdecimal (3.1.9)
13
+ concurrent-ruby (1.3.5)
14
+ diff-lcs (1.5.1)
21
15
  docile (1.4.0)
22
- dry-configurable (0.12.1)
23
- concurrent-ruby (~> 1.0)
24
- dry-core (~> 0.5, >= 0.5.0)
25
- dry-container (0.7.2)
26
- concurrent-ruby (~> 1.0)
27
- dry-configurable (~> 0.1, >= 0.1.3)
28
- dry-core (0.5.0)
16
+ dry-core (1.1.0)
29
17
  concurrent-ruby (~> 1.0)
30
- dry-equalizer (0.3.0)
31
- dry-inflector (0.2.0)
32
- dry-logic (1.1.0)
18
+ logger
19
+ zeitwerk (~> 2.6)
20
+ dry-inflector (1.2.0)
21
+ dry-logic (1.6.0)
22
+ bigdecimal
33
23
  concurrent-ruby (~> 1.0)
34
- dry-core (~> 0.5, >= 0.5)
35
- dry-matcher (0.8.0)
36
- dry-core (>= 0.4.7)
37
- dry-monads (1.3.5)
24
+ dry-core (~> 1.1)
25
+ zeitwerk (~> 2.6)
26
+ dry-matcher (1.0.0)
27
+ dry-core (~> 1.0, < 2)
28
+ dry-monads (1.6.0)
38
29
  concurrent-ruby (~> 1.0)
39
- dry-core (~> 0.4, >= 0.4.4)
40
- dry-equalizer
41
- dry-types (1.5.1)
30
+ dry-core (~> 1.0, < 2)
31
+ zeitwerk (~> 2.6)
32
+ dry-types (1.8.2)
33
+ bigdecimal (~> 3.0)
42
34
  concurrent-ruby (~> 1.0)
43
- dry-container (~> 0.3)
44
- dry-core (~> 0.5, >= 0.5)
45
- dry-inflector (~> 0.1, >= 0.1.2)
46
- dry-logic (~> 1.0, >= 1.0.2)
35
+ dry-core (~> 1.0)
36
+ dry-inflector (~> 1.0)
37
+ dry-logic (~> 1.4)
38
+ zeitwerk (~> 2.6)
47
39
  fear-rspec (0.3.0)
48
40
  fear (>= 1.0.0)
49
41
  rspec (~> 3.0)
50
- irb (1.1.0)
51
- reline (>= 0.0.1)
52
- json (2.6.2)
53
- parallel (1.22.1)
54
- parser (3.1.2.0)
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)
55
48
  ast (~> 2.4.1)
49
+ racc
50
+ prism (1.4.0)
51
+ racc (1.8.1)
56
52
  rainbow (3.1.1)
57
- rake (13.1.0)
58
- regexp_parser (2.5.0)
59
- reline (0.0.7)
60
- rexml (3.2.5)
61
- rspec (3.12.0)
62
- rspec-core (~> 3.12.0)
63
- rspec-expectations (~> 3.12.0)
64
- rspec-mocks (~> 3.12.0)
65
- rspec-core (3.12.0)
66
- rspec-support (~> 3.12.0)
67
- rspec-expectations (3.12.0)
53
+ rake (13.2.1)
54
+ regexp_parser (2.11.0)
55
+ rspec (3.13.0)
56
+ rspec-core (~> 3.13.0)
57
+ rspec-expectations (~> 3.13.0)
58
+ rspec-mocks (~> 3.13.0)
59
+ rspec-core (3.13.0)
60
+ rspec-support (~> 3.13.0)
61
+ rspec-expectations (3.13.0)
68
62
  diff-lcs (>= 1.2.0, < 2.0)
69
- rspec-support (~> 3.12.0)
70
- rspec-mocks (3.12.0)
63
+ rspec-support (~> 3.13.0)
64
+ rspec-mocks (3.13.0)
71
65
  diff-lcs (>= 1.2.0, < 2.0)
72
- rspec-support (~> 3.12.0)
73
- rspec-support (3.12.0)
74
- rubocop (1.32.0)
66
+ rspec-support (~> 3.13.0)
67
+ rspec-support (3.13.1)
68
+ rubocop (1.75.8)
75
69
  json (~> 2.3)
70
+ language_server-protocol (~> 3.17.0.2)
71
+ lint_roller (~> 1.1.0)
76
72
  parallel (~> 1.10)
77
- parser (>= 3.1.0.0)
73
+ parser (>= 3.3.0.2)
78
74
  rainbow (>= 2.2.2, < 4.0)
79
- regexp_parser (>= 1.8, < 3.0)
80
- rexml (>= 3.2.5, < 4.0)
81
- rubocop-ast (>= 1.19.1, < 2.0)
75
+ regexp_parser (>= 2.9.3, < 3.0)
76
+ rubocop-ast (>= 1.44.0, < 2.0)
82
77
  ruby-progressbar (~> 1.7)
83
- unicode-display_width (>= 1.4.0, < 3.0)
84
- rubocop-ast (1.19.1)
85
- parser (>= 3.1.1.0)
86
- rubocop-rspec (1.34.0)
87
- rubocop (>= 0.60.0)
88
- ruby-progressbar (1.11.0)
89
- ruby_coding_standard (0.4.0)
90
- rubocop (~> 1.32.0)
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)
86
+ ruby-progressbar (1.13.0)
91
87
  simplecov (0.22.0)
92
88
  docile (~> 1.1)
93
89
  simplecov-html (~> 0.11)
@@ -95,31 +91,41 @@ GEM
95
91
  simplecov-html (0.12.3)
96
92
  simplecov-lcov (0.8.0)
97
93
  simplecov_json_formatter (0.1.4)
98
- unicode-display_width (2.2.0)
99
- yard (0.9.34)
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)
100
111
 
101
112
  PLATFORMS
102
113
  ruby
103
114
 
104
115
  DEPENDENCIES
105
116
  benchmark-ips
106
- bundler
107
117
  concurrent-ruby
108
118
  dry-matcher
109
119
  dry-monads
110
120
  dry-types
111
121
  fear!
112
122
  fear-rspec
113
- irb
114
- qo!
115
- rake (~> 13.0)
116
- rspec (~> 3.1)
117
- rubocop (= 1.32.0)
118
- rubocop-rspec (= 1.34.0)
119
- ruby_coding_standard
123
+ rake
124
+ rspec
120
125
  simplecov
121
126
  simplecov-lcov
127
+ standard
122
128
  yard
123
129
 
124
130
  BUNDLED WITH
125
- 2.1.4
131
+ 2.5.7
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015-2019 Tema Bolshakov
1
+ Copyright (c) 2015-2024 Tëma Bolshakov
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -632,6 +632,20 @@ Fear.left('left').swap #=> Fear.right('left')
632
632
  Fear.right('right').swap #=> Fear.left('left')
633
633
  ```
634
634
 
635
+ #### Either#left
636
+
637
+ Projects this `Fear::Either` as a `Fear::Left`.
638
+ This allows performing right-biased operation of the left
639
+ side of the `Fear::Either`.
640
+
641
+ ```ruby
642
+ Fear.left(42).left.map(&:succ) #=> Fear.left(43)
643
+ Fear.right(42).left.map(&:succ) #=> Fear.left(42)
644
+
645
+ Fear.left(42).left.select(&:even?) #=> Fear.left(42)
646
+ Fear.right(42).left.select(&:odd?) #=> Fear.right(42)
647
+ ```
648
+
635
649
  #### Either#reduce
636
650
 
637
651
  Applies `reduce_left` if this is a `Left` or `reduce_right` if this is a `Right`.
@@ -1179,76 +1193,7 @@ end
1179
1193
 
1180
1194
  ### Dry-Types integration
1181
1195
 
1182
- #### Option
1183
-
1184
- NOTE: Requires the dry-tyes gem to be loaded.
1185
-
1186
- Load the `:fear_option` extension in your application.
1187
-
1188
- ```ruby
1189
- require 'dry-types'
1190
- require 'dry/types/fear'
1191
-
1192
- Dry::Types.load_extensions(:fear_option)
1193
-
1194
- module Types
1195
- include Dry.Types()
1196
- end
1197
- ```
1198
-
1199
- Append .option to a Type to return a `Fear::Option` object:
1200
-
1201
- ```ruby
1202
- Types::Option::Strict::Integer[nil]
1203
- #=> Fear.none
1204
- Types::Option::Coercible::String[nil]
1205
- #=> Fear.none
1206
- Types::Option::Strict::Integer[123]
1207
- #=> Fear.some(123)
1208
- Types::Option::Strict::String[123]
1209
- #=> Fear.some(123)
1210
- Types::Option::Coercible::Float['12.3']
1211
- #=> Fear.some(12.3)
1212
- ```
1213
-
1214
- 'Option' types can also accessed by calling '.option' on a regular type:
1215
-
1216
- ```ruby
1217
- Types::Strict::Integer.option # equivalent to Types::Option::Strict::Integer
1218
- ```
1219
-
1220
-
1221
- You can define your own optional types:
1222
-
1223
- ```ruby
1224
- option_string = Types::Strict::String.option
1225
- option_string[nil]
1226
- # => Fear.none
1227
- option_string[nil].map(&:upcase)
1228
- # => Fear.none
1229
- option_string['something']
1230
- # => Fear.some('something')
1231
- option_string['something'].map(&:upcase)
1232
- # => Fear.some('SOMETHING')
1233
- option_string['something'].map(&:upcase).get_or_else { 'NOTHING' }
1234
- # => "SOMETHING"
1235
- ```
1236
-
1237
- You can use it with dry-struct as well:
1238
-
1239
- ```ruby
1240
- class User < Dry::Struct
1241
- attribute :name, Types::Coercible::String
1242
- attribute :age, Types::Coercible::Integer.option
1243
- end
1244
-
1245
- user = User.new(name: 'Bob', age: nil)
1246
- user.name #=> "Bob"
1247
- user.age #=> Fear.none
1248
-
1249
- user = User.new(name: 'Bob', age: 42)
1250
- user.age #=> Fear.some(42)
1251
- ```
1196
+ To use `Fear::Option` as optional type for `Dry::Types` use the [dry-types-fear] gem.
1252
1197
 
1253
1198
  ## Testing
1254
1199
 
@@ -1272,3 +1217,6 @@ provides a bunch of rspec matchers.
1272
1217
  * [maybe](https://github.com/bhb/maybe)
1273
1218
  * [ruby-possibly](https://github.com/rap1ds/ruby-possibly)
1274
1219
  * [rumonade](https://github.com/ms-ati/rumonade)
1220
+
1221
+
1222
+ [dry-types-fear]: https://github.com/bolshakov/dry-types-fear