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
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fear
4
+ class NoneClass
5
+ # @api private
6
+ class PatternMatch < Option::PatternMatch
7
+ # @param conditions [<#==>]
8
+ # @return [Fear::OptionPatternMatch]
9
+ def some(*conditions)
10
+ self
11
+ end
12
+ end
13
+
14
+ private_constant :PatternMatch
15
+ end
16
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fear
4
+ # @api private
5
+ class NoneClass
6
+ include Option
7
+ include RightBiased::Left
8
+ include PatternMatch.mixin
9
+
10
+ class << self
11
+ def inherited(*)
12
+ raise "you are not allowed to inherit from NoneClass, use Fear::None instead"
13
+ end
14
+ end
15
+
16
+ # @raise [NoSuchElementError]
17
+ def get
18
+ raise NoSuchElementError
19
+ end
20
+
21
+ # @return [nil]
22
+ def or_nil
23
+ nil
24
+ end
25
+
26
+ # @return [true]
27
+ def empty?
28
+ true
29
+ end
30
+
31
+ alias_method :blank?, :empty?
32
+
33
+ # @return [false]
34
+ def present?
35
+ false
36
+ end
37
+
38
+ # @return [None]
39
+ def select(*)
40
+ self
41
+ end
42
+
43
+ # @return [None]
44
+ def reject(*)
45
+ self
46
+ end
47
+
48
+ # @return [String]
49
+ def inspect
50
+ "#<Fear::NoneClass>"
51
+ end
52
+
53
+ # @return [String]
54
+ alias_method :to_s, :inspect
55
+
56
+ # @param other [Any]
57
+ # @return [Boolean]
58
+ def ==(other)
59
+ other.is_a?(NoneClass)
60
+ end
61
+
62
+ # @param other
63
+ # @return [Boolean]
64
+ def ===(other)
65
+ self == other
66
+ end
67
+
68
+ # @param other [Fear::Option]
69
+ # @return [Fear::Option]
70
+ def zip(other)
71
+ if other.is_a?(Option)
72
+ Fear.none
73
+ else
74
+ raise TypeError, "can't zip with #{other.class}"
75
+ end
76
+ end
77
+
78
+ # @return [RightBiased::Left]
79
+ def filter_map
80
+ self
81
+ end
82
+ end
83
+
84
+ private_constant(:NoneClass)
85
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fear
4
+ module Option
5
+ # Option pattern matcher
6
+ #
7
+ # @example
8
+ # pattern_match =
9
+ # Option::PatternMatch.new
10
+ # .some(Integer) { |x| x * 2 }
11
+ # .some(String) { |x| x.to_i * 2 }
12
+ # .none { 'NaN' }
13
+ # .else { 'error '}
14
+ #
15
+ # pattern_match.call(42) => 'NaN'
16
+ #
17
+ # @example the same matcher may be defined using block syntax
18
+ # Option::PatternMatch.new do |m|
19
+ # m.some(Integer) { |x| x * 2 }
20
+ # m.some(String) { |x| x.to_i * 2 }
21
+ # m.none { 'NaN' }
22
+ # m.else { 'error '}
23
+ # end
24
+ #
25
+ # @note it has two optimized subclasses +Fear::SomePatternMatch+ and +Fear::NonePatternMatch+
26
+ # @api private
27
+ class PatternMatch < Fear::PatternMatch
28
+ # Match against Some
29
+ #
30
+ # @param conditions [<#==>]
31
+ # @return [Fear::Option::PatternMatch]
32
+ def some(*conditions, &effect)
33
+ branch = Fear.case(Fear::Some, &:get).and_then(Fear.case(*conditions, &effect))
34
+ or_else(branch)
35
+ end
36
+
37
+ # Match against None
38
+ #
39
+ # @param effect [Proc]
40
+ # @return [Fear::Option::PatternMatch]
41
+ def none(&effect)
42
+ branch = Fear.case(Fear::None, &effect)
43
+ or_else(branch)
44
+ end
45
+ end
46
+ end
47
+ end
data/lib/fear/option.rb CHANGED
@@ -207,11 +207,11 @@ module Fear
207
207
  # @yieldparam [OptionPatternMatch]
208
208
  # @return [Fear::PartialFunction]
209
209
  def matcher(&matcher)
210
- OptionPatternMatch.new(&matcher)
210
+ Option::PatternMatch.new(&matcher)
211
211
  end
212
212
 
213
213
  def match(value, &block)
214
- matcher(&block).(value)
214
+ matcher(&block).call(value)
215
215
  end
216
216
  end
217
217
 
@@ -258,7 +258,3 @@ module Fear
258
258
  end
259
259
  end
260
260
  end
261
-
262
- require "fear/option_pattern_match"
263
- require "fear/some"
264
- require "fear/none"
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "fear/option"
4
-
5
3
  module Fear
6
4
  module OptionApi
7
5
  # An +Option+ factory which creates +Some+ if the argument is
@@ -29,7 +27,7 @@ module Fear
29
27
  Fear::None
30
28
  end
31
29
 
32
- # @param value [any]
30
+ # @param value [Object]
33
31
  # @return [Fear::Some]
34
32
  # @example
35
33
  # Fear.some(17) #=> #<Fear::Some get=17>
@@ -25,7 +25,7 @@ module Fear
25
25
  # @param arg [any]
26
26
  # @return [any ]
27
27
  def call(arg)
28
- function.(partial_function.(arg))
28
+ function.call(partial_function.call(arg))
29
29
  end
30
30
 
31
31
  # @param arg [any]
@@ -41,7 +41,7 @@ module Fear
41
41
  result = partial_function.call_or_else(arg) do
42
42
  return yield(arg)
43
43
  end
44
- function.(result)
44
+ function.call(result)
45
45
  end
46
46
  end
47
47
 
@@ -24,11 +24,11 @@ module Fear
24
24
  # @param arg [any]
25
25
  # @return [any ]
26
26
  def call(arg)
27
- f2.(f1.(arg))
27
+ f2.call(f1.call(arg))
28
28
  end
29
29
 
30
- alias === call
31
- alias [] call
30
+ alias_method :===, :call
31
+ alias_method :[], :call
32
32
 
33
33
  # @param arg [any]
34
34
  # @yieldparam arg [any]
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "fear/empty_partial_function"
4
-
5
3
  module Fear
6
4
  module PartialFunction
7
- EMPTY = EmptyPartialFunction.new
8
- EMPTY.freeze
5
+ Empty = EmptyPartialFunction.new
6
+ Empty.freeze
9
7
 
10
- public_constant :EMPTY
8
+ public_constant :Empty
11
9
  end
12
10
  end
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "fear/partial_function/guard/or"
4
- require "fear/partial_function/guard/and"
5
- require "fear/partial_function/guard/and3"
6
-
7
3
  module Fear
8
4
  module PartialFunction
9
5
  # Guard represents PartialFunction guardian
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "fear/utils"
4
-
5
3
  module Fear
6
4
  module PartialFunction
7
5
  # Composite function produced by +PartialFunction#or_else+ method
@@ -29,8 +27,8 @@ module Fear
29
27
  f1.call_or_else(arg, &f2)
30
28
  end
31
29
 
32
- alias === call
33
- alias [] call
30
+ alias_method :===, :call
31
+ alias_method :[], :call
34
32
 
35
33
  # @param other [Fear::PartialFunction]
36
34
  # @return [Fear::PartialFunction]
@@ -1,14 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "fear/partial_function/and_then"
4
- require "fear/partial_function/any"
5
- require "fear/partial_function/combined"
6
- require "fear/partial_function/empty"
7
- require "fear/partial_function/guard"
8
- require "fear/partial_function/lifted"
9
- require "fear/partial_function/or_else"
10
- require "fear/partial_function_class"
11
-
12
3
  module Fear
13
4
  # A partial function is a unary function defined on subset of all possible inputs.
14
5
  # The method +defined_at?+ allows to test dynamically if an arg is in
@@ -20,14 +20,14 @@ module Fear
20
20
  # is contained in the function domain.
21
21
  # @raise [MatchError] when this partial function is not defined.
22
22
  def call(arg)
23
- call_or_else(arg, &PartialFunction::EMPTY)
23
+ call_or_else(arg, &PartialFunction::Empty)
24
24
  end
25
25
 
26
26
  # @param arg [any]
27
27
  # @yield [arg] if function not defined
28
28
  def call_or_else(arg)
29
29
  if defined_at?(arg)
30
- function.(arg)
30
+ function.call(arg)
31
31
  else
32
32
  yield arg
33
33
  end
@@ -33,11 +33,11 @@ module Fear
33
33
  # @note Use this class only to build custom pattern match classes. See +Fear::OptionPatternMatch+ as an example.
34
34
  class PatternMatch
35
35
  class << self
36
- alias __new__ new
36
+ alias_method :__new__, :new
37
37
 
38
38
  # @return [Fear::PartialFunction]
39
39
  def new
40
- builder = __new__(PartialFunction::EMPTY)
40
+ builder = __new__(PartialFunction::Empty)
41
41
  yield builder
42
42
  builder.result
43
43
  end
@@ -61,7 +61,7 @@ module Fear
61
61
 
62
62
  Module.new do
63
63
  define_method(as) do |&matchers|
64
- matcher_class.new(&matchers).(self)
64
+ matcher_class.new(&matchers).call(self)
65
65
  end
66
66
  end
67
67
  end
@@ -89,12 +89,13 @@ module Fear
89
89
  #
90
90
  # @param guards [<#===>]
91
91
  # @param effect [Proc]
92
- # @return [Fear::PartialFunction]
92
+ # @return [Fear::PatternMatch]
93
93
  # @see #or_else for details
94
94
  def case(*guards, &effect)
95
95
  or_else(Fear.case(*guards, &effect))
96
96
  end
97
97
 
98
+ # @return [Fear::PatternMatch]
98
99
  # @see Fear::PartialFunction#or_else
99
100
  def or_else(other)
100
101
  self.result = result.or_else(other)
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "fear/partial_function"
4
- require "fear/pattern_match"
5
-
6
3
  module Fear
7
4
  # @api private
8
5
  module PatternMatchingApi
@@ -82,7 +79,7 @@ module Fear
82
79
  # @yieldparam matcher [Fear::PartialFunction]
83
80
  # @return [any]
84
81
  def match(value, &block)
85
- matcher(&block).(value)
82
+ matcher(&block).call(value)
86
83
  end
87
84
 
88
85
  # Creates partial function defined on domain described with guards
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fear
4
+ class Right
5
+ # @api private
6
+ class PatternMatch < Either::PatternMatch
7
+ def left(*)
8
+ self
9
+ end
10
+ alias_method :failure, :left
11
+ end
12
+
13
+ private_constant :PatternMatch
14
+ end
15
+ end
data/lib/fear/right.rb CHANGED
@@ -4,7 +4,7 @@ module Fear
4
4
  class Right
5
5
  include Either
6
6
  include RightBiased::Right
7
- include RightPatternMatch.mixin
7
+ include PatternMatch.mixin
8
8
 
9
9
  # @api private
10
10
  def right_value
@@ -15,13 +15,13 @@ module Fear
15
15
  def right?
16
16
  true
17
17
  end
18
- alias success? right?
18
+ alias_method :success?, :right?
19
19
 
20
20
  # @return [false]
21
21
  def left?
22
22
  false
23
23
  end
24
- alias failure? left?
24
+ alias_method :failure?, :left?
25
25
 
26
26
  # @param default [Proc, any]
27
27
  # @return [Either]
@@ -59,7 +59,7 @@ module Fear
59
59
  # @param reduce_right [Proc]
60
60
  # @return [any]
61
61
  def reduce(_reduce_left, reduce_right)
62
- reduce_right.(value)
62
+ reduce_right.call(value)
63
63
  end
64
64
 
65
65
  # @return [Either]
@@ -70,6 +70,7 @@ module Fear
70
70
  yield(value)
71
71
  self
72
72
  end
73
+ alias_method :apply, :each
73
74
 
74
75
  # Maps the value using given block.
75
76
  #
@@ -144,6 +145,7 @@ module Fear
144
145
  def each
145
146
  self
146
147
  end
148
+ alias_method :apply, :each
147
149
 
148
150
  # Ignores the given block and return self.
149
151
  #
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fear
4
+ class Some
5
+ # @api private
6
+ class PatternMatch < Option::PatternMatch
7
+ # @return [Fear::OptionPatternMatch]
8
+ def none
9
+ self
10
+ end
11
+ end
12
+
13
+ private_constant :PatternMatch
14
+ end
15
+ end
data/lib/fear/some.rb CHANGED
@@ -4,7 +4,7 @@ module Fear
4
4
  class Some
5
5
  include Option
6
6
  include RightBiased::Right
7
- include SomePatternMatch.mixin
7
+ include PatternMatch.mixin
8
8
 
9
9
  attr_reader :value
10
10
  protected :value
@@ -28,7 +28,7 @@ module Fear
28
28
  false
29
29
  end
30
30
 
31
- alias :blank? :empty?
31
+ alias_method :blank?, :empty?
32
32
 
33
33
  # @return [true]
34
34
  def present?
@@ -65,7 +65,7 @@ module Fear
65
65
  end
66
66
 
67
67
  # @return [String]
68
- alias to_s inspect
68
+ alias_method :to_s, :inspect
69
69
 
70
70
  # @param other [Fear::Option]
71
71
  # @return [Fear::Option]
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fear
4
+ class Success
5
+ # @api private
6
+ class PatternMatch < Try::PatternMatch
7
+ # @param conditions [<#==>]
8
+ # @return [Fear::TryPatternMatch]
9
+ def failure(*conditions)
10
+ self
11
+ end
12
+ end
13
+
14
+ private_constant :PatternMatch
15
+ end
16
+ end
data/lib/fear/success.rb CHANGED
@@ -4,7 +4,7 @@ module Fear
4
4
  class Success
5
5
  include Try
6
6
  include RightBiased::Right
7
- include SuccessPatternMatch.mixin
7
+ include PatternMatch.mixin
8
8
 
9
9
  attr_reader :value
10
10
  protected :value
@@ -52,7 +52,7 @@ module Fear
52
52
  else
53
53
  raise NoSuchElementError, "Predicate does not hold for `#{value}`"
54
54
  end
55
- rescue StandardError => error
55
+ rescue => error
56
56
  Failure.new(error)
57
57
  end
58
58
 
@@ -69,14 +69,14 @@ module Fear
69
69
  # @return [Try]
70
70
  def map
71
71
  super
72
- rescue StandardError => error
72
+ rescue => error
73
73
  Failure.new(error)
74
74
  end
75
75
 
76
76
  # @return [Try]
77
77
  def flat_map
78
78
  super
79
- rescue StandardError => error
79
+ rescue => error
80
80
  Failure.new(error)
81
81
  end
82
82
 
@@ -97,7 +97,7 @@ module Fear
97
97
  end
98
98
 
99
99
  # @return [String]
100
- alias to_s inspect
100
+ alias_method :to_s, :inspect
101
101
 
102
102
  # @return [<any>]
103
103
  def deconstruct
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fear
4
+ module Try
5
+ # Try pattern matcher
6
+ #
7
+ # @note it has two optimized subclasses +Fear::Success::PatternMatch+ and +Fear::FailurePatternMatch+
8
+ # @api private
9
+ class PatternMatch < Fear::PatternMatch
10
+ # Match against +Fear::Success+
11
+ #
12
+ # @param conditions [<#==>]
13
+ # @return [Fear::Try::PatternMatch]
14
+ def success(*conditions, &effect)
15
+ branch = Fear.case(Fear::Success, &:get).and_then(Fear.case(*conditions, &effect))
16
+ or_else(branch)
17
+ end
18
+
19
+ # Match against +Fear::Failure+
20
+ #
21
+ # @param conditions [<#==>]
22
+ # @return [Fear::Try::PatternMatch]
23
+ def failure(*conditions, &effect)
24
+ branch = Fear.case(Fear::Failure, &:exception).and_then(Fear.case(*conditions, &effect))
25
+ or_else(branch)
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/fear/try.rb CHANGED
@@ -231,7 +231,7 @@ module Fear
231
231
  #
232
232
  # @!method match(&matcher)
233
233
  # Pattern match against this +Try+
234
- # @yield matcher [Fear::TryPatternMatch]
234
+ # @yield matcher [Fear::Try::PatternMatch]
235
235
  # @example
236
236
  # Fear.try { ... }.match do |m|
237
237
  # m.success(Integer) do |x|
@@ -276,10 +276,10 @@ module Fear
276
276
  # end
277
277
  # matcher.call(try)
278
278
  #
279
- # @yieldparam [Fear::TryPatternMatch]
279
+ # @yieldparam [Fear::Try::PatternMatch]
280
280
  # @return [Fear::PartialFunction]
281
281
  def matcher(&matcher)
282
- TryPatternMatch.new(&matcher)
282
+ Try::PatternMatch.new(&matcher)
283
283
  end
284
284
  end
285
285
 
@@ -317,7 +317,3 @@ module Fear
317
317
  end
318
318
  end
319
319
  end
320
-
321
- require "fear/try_pattern_match"
322
- require "fear/success"
323
- require "fear/failure"
data/lib/fear/try_api.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "fear/try"
4
-
5
3
  module Fear
6
4
  module TryApi
7
5
  # Constructs a +Try+ using the block. This
@@ -14,7 +12,7 @@ module Fear
14
12
  #
15
13
  def try
16
14
  success(yield)
17
- rescue StandardError => error
15
+ rescue => error
18
16
  failure(error)
19
17
  end
20
18
 
data/lib/fear/utils.rb CHANGED
@@ -38,7 +38,7 @@ module Fear
38
38
 
39
39
  def return_or_call_proc(value)
40
40
  if value.respond_to?(:call)
41
- value.()
41
+ value.call
42
42
  else
43
43
  value
44
44
  end
data/lib/fear/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fear
4
- VERSION = "2.0.1"
4
+ VERSION = "3.1.0"
5
5
  public_constant :VERSION
6
6
  end
data/lib/fear.rb CHANGED
@@ -1,16 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "fear/utils"
4
- require "fear/right_biased"
5
- require "fear/struct"
6
- require "fear/unit"
7
- require "fear/either_api"
8
- require "fear/for_api"
9
- require "fear/future_api"
10
- require "fear/option_api"
11
- require "fear/pattern_matching_api"
12
- require "fear/try_api"
13
- require "fear/version"
3
+ require "zeitwerk"
4
+ loader = Zeitwerk::Loader.for_gem
5
+ loader.setup
14
6
 
15
7
  module Fear
16
8
  Error = Class.new(StandardError)
@@ -25,9 +17,6 @@ module Fear
25
17
  NoSuchElementError = Class.new(Error)
26
18
  public_constant :NoSuchElementError
27
19
 
28
- PatternSyntaxError = Class.new(Error)
29
- public_constant :PatternSyntaxError
30
-
31
20
  extend EitherApi
32
21
  extend ForApi
33
22
  extend FutureApi
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "fear/awaitable"
4
-
5
3
  RSpec.describe Fear::Awaitable do
6
4
  subject(:awaitable) { Object.new.extend(Fear::Awaitable) }
7
5