fear 0.10.0 → 0.11.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/.rubocop.yml +30 -4
- data/.travis.yml +2 -3
- data/Appraisals +5 -9
- data/CHANGELOG.md +9 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +255 -85
- data/Rakefile +393 -0
- data/fear.gemspec +13 -6
- data/gemfiles/dry_equalizer_0.1.0.gemfile +1 -0
- data/gemfiles/dry_equalizer_0.1.0.gemfile.lock +31 -27
- data/gemfiles/dry_equalizer_0.2.1.gemfile +1 -0
- data/gemfiles/dry_equalizer_0.2.1.gemfile.lock +31 -27
- data/lib/fear/either.rb +49 -14
- data/lib/fear/either_pattern_match.rb +48 -0
- data/lib/fear/empty_partial_function.rb +36 -0
- data/lib/fear/failure.rb +5 -4
- data/lib/fear/failure_pattern_match.rb +8 -0
- data/lib/fear/for.rb +46 -51
- data/lib/fear/left.rb +7 -1
- data/lib/fear/left_pattern_match.rb +9 -0
- data/lib/fear/none.rb +37 -2
- data/lib/fear/none_pattern_match.rb +12 -0
- data/lib/fear/option.rb +65 -31
- data/lib/fear/option_pattern_match.rb +45 -0
- data/lib/fear/partial_function/and_then.rb +48 -0
- data/lib/fear/partial_function/any.rb +26 -0
- data/lib/fear/partial_function/combined.rb +51 -0
- data/lib/fear/partial_function/empty.rb +6 -0
- data/lib/fear/partial_function/guard/and.rb +36 -0
- data/lib/fear/partial_function/guard/and3.rb +39 -0
- data/lib/fear/partial_function/guard/or.rb +36 -0
- data/lib/fear/partial_function/guard.rb +90 -0
- data/lib/fear/partial_function/lifted.rb +20 -0
- data/lib/fear/partial_function/or_else.rb +62 -0
- data/lib/fear/partial_function.rb +171 -0
- data/lib/fear/partial_function_class.rb +26 -0
- data/lib/fear/pattern_match.rb +102 -0
- data/lib/fear/pattern_matching_api.rb +110 -0
- data/lib/fear/right.rb +7 -1
- data/lib/fear/right_biased.rb +2 -12
- data/lib/fear/right_pattern_match.rb +9 -0
- data/lib/fear/some.rb +5 -2
- data/lib/fear/some_pattern_match.rb +11 -0
- data/lib/fear/success.rb +5 -4
- data/lib/fear/success_pattern_match.rb +10 -0
- data/lib/fear/try.rb +56 -16
- data/lib/fear/try_pattern_match.rb +28 -0
- data/lib/fear/utils.rb +24 -14
- data/lib/fear/version.rb +1 -1
- data/lib/fear.rb +21 -4
- data/spec/fear/either_pattern_match_spec.rb +37 -0
- data/spec/fear/failure_spec.rb +41 -3
- data/spec/fear/for_spec.rb +17 -29
- data/spec/fear/guard_spec.rb +101 -0
- data/spec/fear/left_spec.rb +38 -0
- data/spec/fear/none_spec.rb +80 -0
- data/spec/fear/option_pattern_match_spec.rb +35 -0
- data/spec/fear/partial_function/empty_spec.rb +36 -0
- data/spec/fear/partial_function_and_then_spec.rb +145 -0
- data/spec/fear/partial_function_composition_spec.rb +80 -0
- data/spec/fear/partial_function_or_else_spec.rb +274 -0
- data/spec/fear/partial_function_spec.rb +165 -0
- data/spec/fear/pattern_match_spec.rb +59 -0
- data/spec/fear/right_biased/left.rb +1 -6
- data/spec/fear/right_biased/right.rb +0 -5
- data/spec/fear/right_spec.rb +38 -0
- data/spec/fear/some_spec.rb +37 -0
- data/spec/fear/success_spec.rb +41 -4
- data/spec/fear/try_pattern_match_spec.rb +37 -0
- metadata +97 -23
- data/lib/fear/for/evaluation_context.rb +0 -91
    
        data/Rakefile
    CHANGED
    
    | @@ -1 +1,394 @@ | |
| 1 1 | 
             
            require 'bundler/gem_tasks'
         | 
| 2 | 
            +
            require 'benchmark/ips'
         | 
| 3 | 
            +
            require_relative 'lib/fear'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            namespace :perf do
         | 
| 6 | 
            +
              namespace :guard do
         | 
| 7 | 
            +
                task :and1 do
         | 
| 8 | 
            +
                  condition = Integer
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  Benchmark.ips do |x|
         | 
| 11 | 
            +
                    x.report('Guard.new') do |n|
         | 
| 12 | 
            +
                      Fear::PartialFunction::Guard.new(condition) === n
         | 
| 13 | 
            +
                    end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                    x.report('Guard.single') do |n|
         | 
| 16 | 
            +
                      Fear::PartialFunction::Guard.and1(condition) === n
         | 
| 17 | 
            +
                    end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    x.compare!
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                task :and1 do
         | 
| 24 | 
            +
                  first = Integer
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  and1 = Fear::PartialFunction::Guard.and1(first)
         | 
| 27 | 
            +
                  guard = Fear::PartialFunction::Guard.new(first)
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  Benchmark.ips do |x|
         | 
| 30 | 
            +
                    x.report('guard') do |n|
         | 
| 31 | 
            +
                      and1 === n
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                    x.report('single') do |n|
         | 
| 35 | 
            +
                      guard === n
         | 
| 36 | 
            +
                    end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                    x.compare!
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                task :and2 do
         | 
| 43 | 
            +
                  first = Integer
         | 
| 44 | 
            +
                  second = ->(x) { x > 2 }
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  and2 = Fear::PartialFunction::Guard.and2(first, second)
         | 
| 47 | 
            +
                  and_and = Fear::PartialFunction::Guard.new(first).and(Fear::PartialFunction::Guard.new(second))
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  Benchmark.ips do |x|
         | 
| 50 | 
            +
                    x.report('and2') do |n|
         | 
| 51 | 
            +
                      and2 === n
         | 
| 52 | 
            +
                    end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                    x.report('Guard#and') do |n|
         | 
| 55 | 
            +
                      and_and === n
         | 
| 56 | 
            +
                    end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                    x.compare!
         | 
| 59 | 
            +
                  end
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                task :and3 do
         | 
| 63 | 
            +
                  first = Integer
         | 
| 64 | 
            +
                  second = ->(x) { x > 2 }
         | 
| 65 | 
            +
                  third = ->(x) {  x < 10 }
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                  and3 = Fear::PartialFunction::Guard.and3(first, second, third)
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                  and_and_and = Fear::PartialFunction::Guard.new(first)
         | 
| 70 | 
            +
                                                            .and(Fear::PartialFunction::Guard.new(second))
         | 
| 71 | 
            +
                                                            .and(Fear::PartialFunction::Guard.new(third))
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                  Benchmark.ips do |x|
         | 
| 74 | 
            +
                    x.report('Guard.and3') do |n|
         | 
| 75 | 
            +
                      and3 === n
         | 
| 76 | 
            +
                    end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                    x.report('Guard#and') do |n|
         | 
| 79 | 
            +
                      and_and_and === n
         | 
| 80 | 
            +
                    end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                    x.compare!
         | 
| 83 | 
            +
                  end
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
              end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
              require 'qo'
         | 
| 88 | 
            +
              require 'dry/matcher'
         | 
| 89 | 
            +
             | 
| 90 | 
            +
              namespace :pattern_matching do
         | 
| 91 | 
            +
                task :try do
         | 
| 92 | 
            +
                  module ExhaustivePatternMatch
         | 
| 93 | 
            +
                    def initialize(*)
         | 
| 94 | 
            +
                      super
         | 
| 95 | 
            +
                      @default ||= self.else { raise Fear::MatchError }
         | 
| 96 | 
            +
                    end
         | 
| 97 | 
            +
                  end
         | 
| 98 | 
            +
             | 
| 99 | 
            +
                  SuccessBranch = Qo.create_branch(name: 'success', precondition: Fear::Success, extractor: :get)
         | 
| 100 | 
            +
                  FailureBranch = Qo.create_branch(name: 'failure', precondition: Fear::Failure, extractor: :exception)
         | 
| 101 | 
            +
             | 
| 102 | 
            +
                  PatternMatch = Qo.create_pattern_match(
         | 
| 103 | 
            +
                    branches: [
         | 
| 104 | 
            +
                      SuccessBranch,
         | 
| 105 | 
            +
                      FailureBranch,
         | 
| 106 | 
            +
                    ],
         | 
| 107 | 
            +
                  ).prepend(ExhaustivePatternMatch)
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                  Fear::Success.include(PatternMatch.mixin(as: :qo_match))
         | 
| 110 | 
            +
             | 
| 111 | 
            +
                  success_case = Dry::Matcher::Case.new(
         | 
| 112 | 
            +
                    match: lambda { |try, *pattern|
         | 
| 113 | 
            +
                      try.is_a?(Fear::Success) && pattern.all? { |p| p === try.get }
         | 
| 114 | 
            +
                    },
         | 
| 115 | 
            +
                    resolve: ->(try) { try.get },
         | 
| 116 | 
            +
                  )
         | 
| 117 | 
            +
             | 
| 118 | 
            +
                  failure_case = Dry::Matcher::Case.new(
         | 
| 119 | 
            +
                    match: lambda { |try, *pattern|
         | 
| 120 | 
            +
                      try.is_a?(Fear::Failure) && pattern.all? { |p| p === try.exception }
         | 
| 121 | 
            +
                    },
         | 
| 122 | 
            +
                    resolve: ->(value) { value.exception },
         | 
| 123 | 
            +
                  )
         | 
| 124 | 
            +
             | 
| 125 | 
            +
                  # Build the matcher
         | 
| 126 | 
            +
                  matcher = Dry::Matcher.new(success: success_case, failure: failure_case)
         | 
| 127 | 
            +
             | 
| 128 | 
            +
                  success = Fear::Success.new(4)
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                  Benchmark.ips do |x|
         | 
| 131 | 
            +
                    x.report('Qo') do
         | 
| 132 | 
            +
                      success.qo_match do |m|
         | 
| 133 | 
            +
                        m.failure { |y| y }
         | 
| 134 | 
            +
                        m.success(->(y) { y % 4 == 0 }) { |y| y }
         | 
| 135 | 
            +
                        m.success { 'else' }
         | 
| 136 | 
            +
                      end
         | 
| 137 | 
            +
                    end
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                    x.report('Fear') do
         | 
| 140 | 
            +
                      success.match do |m|
         | 
| 141 | 
            +
                        m.failure { |y| y }
         | 
| 142 | 
            +
                        m.success(->(y) { y % 4 == 0 }) { |y| y }
         | 
| 143 | 
            +
                        m.success { 'else' }
         | 
| 144 | 
            +
                      end
         | 
| 145 | 
            +
                    end
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                    x.report('Dr::Matcher') do
         | 
| 148 | 
            +
                      matcher.call(success) do |m|
         | 
| 149 | 
            +
                        m.failure { |_y| 'failure' }
         | 
| 150 | 
            +
                        m.success(->(y) { y % 4 == 0 }) { |y| "2: #{y}" }
         | 
| 151 | 
            +
                        m.success { 'else' }
         | 
| 152 | 
            +
                      end
         | 
| 153 | 
            +
                    end
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                    x.compare!
         | 
| 156 | 
            +
                  end
         | 
| 157 | 
            +
                end
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                task :either do
         | 
| 160 | 
            +
                  module ExhaustivePatternMatch
         | 
| 161 | 
            +
                    def initialize(*)
         | 
| 162 | 
            +
                      super
         | 
| 163 | 
            +
                      @default ||= self.else { raise Fear::MatchError }
         | 
| 164 | 
            +
                    end
         | 
| 165 | 
            +
                  end
         | 
| 166 | 
            +
             | 
| 167 | 
            +
                  RightBranch = Qo.create_branch(name: 'right', precondition: Fear::Right, extractor: :right_value)
         | 
| 168 | 
            +
                  LeftBranch = Qo.create_branch(name: 'left', precondition: Fear::Left, extractor: :left_value)
         | 
| 169 | 
            +
             | 
| 170 | 
            +
                  PatternMatch = Qo.create_pattern_match(
         | 
| 171 | 
            +
                    branches: [
         | 
| 172 | 
            +
                      RightBranch,
         | 
| 173 | 
            +
                      LeftBranch,
         | 
| 174 | 
            +
                    ],
         | 
| 175 | 
            +
                  ).prepend(ExhaustivePatternMatch)
         | 
| 176 | 
            +
             | 
| 177 | 
            +
                  Fear::Right.include(PatternMatch.mixin(as: :qo_match))
         | 
| 178 | 
            +
             | 
| 179 | 
            +
                  right = Fear::Right.new(4)
         | 
| 180 | 
            +
             | 
| 181 | 
            +
                  Benchmark.ips do |x|
         | 
| 182 | 
            +
                    x.report('Qo') do
         | 
| 183 | 
            +
                      right.qo_match do |m|
         | 
| 184 | 
            +
                        m.left(->(y) { y % 3 == 0 }) { |y| y }
         | 
| 185 | 
            +
                        m.right(->(y) { y % 4 == 0 }) { |y| y }
         | 
| 186 | 
            +
                        m.else { 'else' }
         | 
| 187 | 
            +
                      end
         | 
| 188 | 
            +
                    end
         | 
| 189 | 
            +
             | 
| 190 | 
            +
                    x.report('Fear') do
         | 
| 191 | 
            +
                      right.match do |m|
         | 
| 192 | 
            +
                        m.left(->(y) { y % 3 == 0 }) { |y| y }
         | 
| 193 | 
            +
                        m.right(->(y) { y % 4 == 0 }) { |y| y }
         | 
| 194 | 
            +
                        m.else { 'else' }
         | 
| 195 | 
            +
                      end
         | 
| 196 | 
            +
                    end
         | 
| 197 | 
            +
             | 
| 198 | 
            +
                    x.compare!
         | 
| 199 | 
            +
                  end
         | 
| 200 | 
            +
                end
         | 
| 201 | 
            +
             | 
| 202 | 
            +
                task :option do
         | 
| 203 | 
            +
                  module ExhaustivePatternMatch
         | 
| 204 | 
            +
                    def initialize(*)
         | 
| 205 | 
            +
                      super
         | 
| 206 | 
            +
                      @default ||= self.else { raise Fear::MatchError }
         | 
| 207 | 
            +
                    end
         | 
| 208 | 
            +
                  end
         | 
| 209 | 
            +
             | 
| 210 | 
            +
                  SomeBranch = Qo.create_branch(name: 'some', precondition: Fear::Some, extractor: :get)
         | 
| 211 | 
            +
                  NoneBranch = Qo.create_branch(name: 'none', precondition: Fear::None)
         | 
| 212 | 
            +
             | 
| 213 | 
            +
                  PatternMatch = Qo.create_pattern_match(
         | 
| 214 | 
            +
                    branches: [
         | 
| 215 | 
            +
                      SomeBranch,
         | 
| 216 | 
            +
                      NoneBranch,
         | 
| 217 | 
            +
                    ],
         | 
| 218 | 
            +
                  ).prepend(ExhaustivePatternMatch)
         | 
| 219 | 
            +
             | 
| 220 | 
            +
                  Fear::Some.include(PatternMatch.mixin(as: :qo_match))
         | 
| 221 | 
            +
             | 
| 222 | 
            +
                  some = Fear::Some.new(4)
         | 
| 223 | 
            +
             | 
| 224 | 
            +
                  some_case = Dry::Matcher::Case.new(
         | 
| 225 | 
            +
                    match: lambda { |option, *pattern|
         | 
| 226 | 
            +
                      option.is_a?(Fear::Some) && pattern.all? { |p| p === option.get }
         | 
| 227 | 
            +
                    },
         | 
| 228 | 
            +
                    resolve: ->(try) { try.get },
         | 
| 229 | 
            +
                  )
         | 
| 230 | 
            +
             | 
| 231 | 
            +
                  none_case = Dry::Matcher::Case.new(
         | 
| 232 | 
            +
                    match: lambda { |option, *pattern|
         | 
| 233 | 
            +
                      Fear::None == option && pattern.all? { |p| p === option }
         | 
| 234 | 
            +
                    },
         | 
| 235 | 
            +
                    resolve: ->(value) { value },
         | 
| 236 | 
            +
                  )
         | 
| 237 | 
            +
             | 
| 238 | 
            +
                  else_case = Dry::Matcher::Case.new(
         | 
| 239 | 
            +
                    match: ->(*) { true },
         | 
| 240 | 
            +
                    resolve: ->(value) { value },
         | 
| 241 | 
            +
                  )
         | 
| 242 | 
            +
             | 
| 243 | 
            +
                  # Build the matcher
         | 
| 244 | 
            +
                  matcher = Dry::Matcher.new(some: some_case, none: none_case, else: else_case)
         | 
| 245 | 
            +
             | 
| 246 | 
            +
                  option_matcher = Fear::Option.matcher do |m|
         | 
| 247 | 
            +
                    m.some(->(y) { y % 3 == 0 }) { |y| y }
         | 
| 248 | 
            +
                    m.some(->(y) { y % 4 == 0 }) { |y| y }
         | 
| 249 | 
            +
                    m.none { 'none' }
         | 
| 250 | 
            +
                    m.else { 'else' }
         | 
| 251 | 
            +
                  end
         | 
| 252 | 
            +
             | 
| 253 | 
            +
                  Benchmark.ips do |x|
         | 
| 254 | 
            +
                    x.report('Qo') do
         | 
| 255 | 
            +
                      some.qo_match do |m|
         | 
| 256 | 
            +
                        m.some(->(y) { y % 3 == 0 }) { |y| y }
         | 
| 257 | 
            +
                        m.some(->(y) { y % 4 == 0 }) { |y| y }
         | 
| 258 | 
            +
                        m.none { 'none' }
         | 
| 259 | 
            +
                        m.else { 'else' }
         | 
| 260 | 
            +
                      end
         | 
| 261 | 
            +
                    end
         | 
| 262 | 
            +
             | 
| 263 | 
            +
                    x.report('Fear::Some#math') do
         | 
| 264 | 
            +
                      some.match do |m|
         | 
| 265 | 
            +
                        m.some(->(y) { y % 3 == 0 }) { |y| y }
         | 
| 266 | 
            +
                        m.some(->(y) { y % 4 == 0 }) { |y| y }
         | 
| 267 | 
            +
                        m.none { 'none' }
         | 
| 268 | 
            +
                        m.else { 'else' }
         | 
| 269 | 
            +
                      end
         | 
| 270 | 
            +
                    end
         | 
| 271 | 
            +
             | 
| 272 | 
            +
                    x.report('Fear::Option.mather') do
         | 
| 273 | 
            +
                      option_matcher.call(some)
         | 
| 274 | 
            +
                    end
         | 
| 275 | 
            +
             | 
| 276 | 
            +
                    x.report('Dry::Matcher') do
         | 
| 277 | 
            +
                      matcher.call(some) do |m|
         | 
| 278 | 
            +
                        m.some(->(y) { y % 3 == 0 }) { |y| y }
         | 
| 279 | 
            +
                        m.some(->(y) { y % 4 == 0 }) { |y| y }
         | 
| 280 | 
            +
                        m.none { 'none' }
         | 
| 281 | 
            +
                        m.else { 'else' }
         | 
| 282 | 
            +
                      end
         | 
| 283 | 
            +
                    end
         | 
| 284 | 
            +
             | 
| 285 | 
            +
                    x.compare!
         | 
| 286 | 
            +
                  end
         | 
| 287 | 
            +
                end
         | 
| 288 | 
            +
             | 
| 289 | 
            +
                task :option_execution do
         | 
| 290 | 
            +
                  module ExhaustivePatternMatch
         | 
| 291 | 
            +
                    def initialize(*)
         | 
| 292 | 
            +
                      super
         | 
| 293 | 
            +
                      @default ||= self.else { raise Fear::MatchError }
         | 
| 294 | 
            +
                    end
         | 
| 295 | 
            +
                  end
         | 
| 296 | 
            +
             | 
| 297 | 
            +
                  SomeBranch = Qo.create_branch(name: 'some', precondition: Fear::Some, extractor: :get)
         | 
| 298 | 
            +
                  NoneBranch = Qo.create_branch(name: 'none', precondition: Fear::None)
         | 
| 299 | 
            +
             | 
| 300 | 
            +
                  PatternMatch = Qo.create_pattern_match(
         | 
| 301 | 
            +
                    branches: [
         | 
| 302 | 
            +
                      SomeBranch,
         | 
| 303 | 
            +
                      NoneBranch,
         | 
| 304 | 
            +
                    ],
         | 
| 305 | 
            +
                  ).prepend(ExhaustivePatternMatch)
         | 
| 306 | 
            +
             | 
| 307 | 
            +
                  some = Fear::Some.new(4)
         | 
| 308 | 
            +
             | 
| 309 | 
            +
                  qo_matcher = PatternMatch.new do |m|
         | 
| 310 | 
            +
                    m.some(->(y) { y % 3 == 0 }) { |y| y }
         | 
| 311 | 
            +
                    m.some(->(y) { y % 4 == 0 }) { |y| y }
         | 
| 312 | 
            +
                    m.none { 'none' }
         | 
| 313 | 
            +
                    m.else { 'else' }
         | 
| 314 | 
            +
                  end
         | 
| 315 | 
            +
             | 
| 316 | 
            +
                  fear_matcher = Fear::OptionPatternMatch.new do |m|
         | 
| 317 | 
            +
                    m.some(->(y) { y % 3 == 0 }) { |y| y }
         | 
| 318 | 
            +
                    m.some(->(y) { y % 4 == 0 }) { |y| y }
         | 
| 319 | 
            +
                    m.none { 'none' }
         | 
| 320 | 
            +
                    m.else { 'else' }
         | 
| 321 | 
            +
                  end
         | 
| 322 | 
            +
             | 
| 323 | 
            +
                  Benchmark.ips do |x|
         | 
| 324 | 
            +
                    x.report('Qo') do
         | 
| 325 | 
            +
                      qo_matcher.call(some)
         | 
| 326 | 
            +
                    end
         | 
| 327 | 
            +
             | 
| 328 | 
            +
                    x.report('Fear') do
         | 
| 329 | 
            +
                      fear_matcher.call(some)
         | 
| 330 | 
            +
                    end
         | 
| 331 | 
            +
             | 
| 332 | 
            +
                    x.compare!
         | 
| 333 | 
            +
                  end
         | 
| 334 | 
            +
                end
         | 
| 335 | 
            +
             | 
| 336 | 
            +
                task :factorial do
         | 
| 337 | 
            +
                  factorial_proc = proc do |n|
         | 
| 338 | 
            +
                    if n <= 1
         | 
| 339 | 
            +
                      1
         | 
| 340 | 
            +
                    else
         | 
| 341 | 
            +
                      n * factorial_proc.call(n - 1)
         | 
| 342 | 
            +
                    end
         | 
| 343 | 
            +
                  end
         | 
| 344 | 
            +
             | 
| 345 | 
            +
                  factorial_pm = Fear.matcher do |m|
         | 
| 346 | 
            +
                    m.case(->(n) { n <= 1 }) { 1 }
         | 
| 347 | 
            +
                    m.else { |n| n * factorial_pm.call(n - 1) }
         | 
| 348 | 
            +
                  end
         | 
| 349 | 
            +
             | 
| 350 | 
            +
                  factorial_qo = Qo.match do |m|
         | 
| 351 | 
            +
                    m.when(->(n) { n <= 1 }) { 1 }
         | 
| 352 | 
            +
                    m.else { |n| n * factorial_qo.call(n - 1) }
         | 
| 353 | 
            +
                  end
         | 
| 354 | 
            +
             | 
| 355 | 
            +
                  Benchmark.ips do |x|
         | 
| 356 | 
            +
                    x.report('Proc') do
         | 
| 357 | 
            +
                      factorial_proc.call(100)
         | 
| 358 | 
            +
                    end
         | 
| 359 | 
            +
             | 
| 360 | 
            +
                    x.report('Fear') do
         | 
| 361 | 
            +
                      factorial_pm.call(100)
         | 
| 362 | 
            +
                    end
         | 
| 363 | 
            +
             | 
| 364 | 
            +
                    x.report('Qo') do
         | 
| 365 | 
            +
                      factorial_qo.call(100)
         | 
| 366 | 
            +
                    end
         | 
| 367 | 
            +
             | 
| 368 | 
            +
                    x.compare!
         | 
| 369 | 
            +
                  end
         | 
| 370 | 
            +
                end
         | 
| 371 | 
            +
             | 
| 372 | 
            +
                task :construction_vs_execution do
         | 
| 373 | 
            +
                  matcher = Fear::PatternMatch.new do |m|
         | 
| 374 | 
            +
                    m.case(Integer) { |x| x * 2 }
         | 
| 375 | 
            +
                    m.case(String) { |x| x.to_i(10) * 2 }
         | 
| 376 | 
            +
                  end
         | 
| 377 | 
            +
             | 
| 378 | 
            +
                  Benchmark.ips do |x|
         | 
| 379 | 
            +
                    x.report('construction') do
         | 
| 380 | 
            +
                      Fear::PatternMatch.new do |m|
         | 
| 381 | 
            +
                        m.case(Integer) { |y| y * 2 }
         | 
| 382 | 
            +
                        m.case(String) { |y| y.to_i(10) * 2 }
         | 
| 383 | 
            +
                      end
         | 
| 384 | 
            +
                    end
         | 
| 385 | 
            +
             | 
| 386 | 
            +
                    x.report('execution') do
         | 
| 387 | 
            +
                      matcher.call(42)
         | 
| 388 | 
            +
                    end
         | 
| 389 | 
            +
             | 
| 390 | 
            +
                    x.compare!
         | 
| 391 | 
            +
                  end
         | 
| 392 | 
            +
                end
         | 
| 393 | 
            +
              end
         | 
| 394 | 
            +
            end
         | 
    
        data/fear.gemspec
    CHANGED
    
    | @@ -1,5 +1,4 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
            lib = File.expand_path('../lib', __FILE__)
         | 
| 1 | 
            +
            lib = File.expand_path('lib', __dir__)
         | 
| 3 2 |  | 
| 4 3 | 
             
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 5 4 |  | 
| @@ -19,14 +18,22 @@ Gem::Specification.new do |spec| | |
| 19 18 | 
             
              spec.test_files    = spec.files.grep(%r{^spec\/})
         | 
| 20 19 | 
             
              spec.require_paths = ['lib']
         | 
| 21 20 |  | 
| 21 | 
            +
              spec.post_install_message = <<-MSG
         | 
| 22 | 
            +
                Fear v0.11.0 introduces backwards-incompatible changes.
         | 
| 23 | 
            +
                Please see https://github.com/bolshakov/fear/blob/master/CHANGELOG.md#0110 for details.
         | 
| 24 | 
            +
                Successfully installed fear-#{Fear::VERSION}
         | 
| 25 | 
            +
              MSG
         | 
| 26 | 
            +
             | 
| 22 27 | 
             
              spec.add_runtime_dependency 'dry-equalizer', '<= 0.2.1'
         | 
| 23 28 |  | 
| 24 29 | 
             
              spec.add_development_dependency 'appraisal'
         | 
| 30 | 
            +
              spec.add_development_dependency 'benchmark-ips'
         | 
| 25 31 | 
             
              spec.add_development_dependency 'bundler'
         | 
| 32 | 
            +
              spec.add_development_dependency 'dry-matcher'
         | 
| 33 | 
            +
              spec.add_development_dependency 'qo'
         | 
| 26 34 | 
             
              spec.add_development_dependency 'rake', '~> 10.0'
         | 
| 27 35 | 
             
              spec.add_development_dependency 'rspec', '~> 3.1'
         | 
| 28 | 
            -
              spec.add_development_dependency 'rubocop', '0. | 
| 29 | 
            -
              spec.add_development_dependency 'rubocop-rspec', '1. | 
| 30 | 
            -
              spec.add_development_dependency ' | 
| 31 | 
            -
              spec.add_development_dependency 'spbtv_code_style'
         | 
| 36 | 
            +
              spec.add_development_dependency 'rubocop', '0.65.0'
         | 
| 37 | 
            +
              spec.add_development_dependency 'rubocop-rspec', '1.32.0'
         | 
| 38 | 
            +
              spec.add_development_dependency 'yard'
         | 
| 32 39 | 
             
            end
         | 
| @@ -1,26 +1,36 @@ | |
| 1 | 
            +
            GIT
         | 
| 2 | 
            +
              remote: git://github.com/baweaver/qo.git
         | 
| 3 | 
            +
              revision: 8951ce899559118eb60321014b43cf4211730bd0
         | 
| 4 | 
            +
              specs:
         | 
| 5 | 
            +
                qo (0.99.0)
         | 
| 6 | 
            +
                  any (= 0.1.0)
         | 
| 7 | 
            +
             | 
| 1 8 | 
             
            PATH
         | 
| 2 9 | 
             
              remote: ..
         | 
| 3 10 | 
             
              specs:
         | 
| 4 | 
            -
                fear (0. | 
| 11 | 
            +
                fear (0.11.0)
         | 
| 5 12 | 
             
                  dry-equalizer (<= 0.2.1)
         | 
| 6 13 |  | 
| 7 14 | 
             
            GEM
         | 
| 8 15 | 
             
              remote: https://rubygems.org/
         | 
| 9 16 | 
             
              specs:
         | 
| 17 | 
            +
                any (0.1.0)
         | 
| 10 18 | 
             
                appraisal (2.2.0)
         | 
| 11 19 | 
             
                  bundler
         | 
| 12 20 | 
             
                  rake
         | 
| 13 21 | 
             
                  thor (>= 0.14.0)
         | 
| 14 22 | 
             
                ast (2.4.0)
         | 
| 23 | 
            +
                benchmark-ips (2.7.2)
         | 
| 15 24 | 
             
                diff-lcs (1.3)
         | 
| 16 | 
            -
                docile (1.3.1)
         | 
| 17 25 | 
             
                dry-equalizer (0.1.0)
         | 
| 18 | 
            -
                 | 
| 26 | 
            +
                dry-matcher (0.7.0)
         | 
| 27 | 
            +
                jaro_winkler (1.5.2)
         | 
| 28 | 
            +
                parallel (1.14.0)
         | 
| 19 29 | 
             
                parser (2.6.0.0)
         | 
| 20 30 | 
             
                  ast (~> 2.4.0)
         | 
| 21 31 | 
             
                powerpack (0.1.2)
         | 
| 22 | 
            -
                 | 
| 23 | 
            -
             | 
| 32 | 
            +
                psych (3.1.0)
         | 
| 33 | 
            +
                rainbow (3.0.0)
         | 
| 24 34 | 
             
                rake (10.5.0)
         | 
| 25 35 | 
             
                rspec (3.8.0)
         | 
| 26 36 | 
             
                  rspec-core (~> 3.8.0)
         | 
| @@ -35,44 +45,38 @@ GEM | |
| 35 45 | 
             
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 36 46 | 
             
                  rspec-support (~> 3.8.0)
         | 
| 37 47 | 
             
                rspec-support (3.8.0)
         | 
| 38 | 
            -
                 | 
| 39 | 
            -
                   | 
| 40 | 
            -
             | 
| 41 | 
            -
                  parser (>= 2. | 
| 48 | 
            +
                rubocop (0.65.0)
         | 
| 49 | 
            +
                  jaro_winkler (~> 1.5.1)
         | 
| 50 | 
            +
                  parallel (~> 1.10)
         | 
| 51 | 
            +
                  parser (>= 2.5, != 2.5.1.1)
         | 
| 42 52 | 
             
                  powerpack (~> 0.1)
         | 
| 43 | 
            -
                   | 
| 53 | 
            +
                  psych (>= 3.1.0)
         | 
| 54 | 
            +
                  rainbow (>= 2.2.2, < 4.0)
         | 
| 44 55 | 
             
                  ruby-progressbar (~> 1.7)
         | 
| 45 | 
            -
                  unicode-display_width (~> 1. | 
| 46 | 
            -
                rubocop- | 
| 47 | 
            -
                  rubocop (>= 0. | 
| 48 | 
            -
                rubocop-rspec (1.13.0)
         | 
| 49 | 
            -
                  rubocop (>= 0.42.0)
         | 
| 56 | 
            +
                  unicode-display_width (~> 1.4.0)
         | 
| 57 | 
            +
                rubocop-rspec (1.32.0)
         | 
| 58 | 
            +
                  rubocop (>= 0.60.0)
         | 
| 50 59 | 
             
                ruby-progressbar (1.10.0)
         | 
| 51 | 
            -
                simplecov (0.16.1)
         | 
| 52 | 
            -
                  docile (~> 1.1)
         | 
| 53 | 
            -
                  json (>= 1.8, < 3)
         | 
| 54 | 
            -
                  simplecov-html (~> 0.10.0)
         | 
| 55 | 
            -
                simplecov-html (0.10.2)
         | 
| 56 | 
            -
                spbtv_code_style (1.7.0)
         | 
| 57 | 
            -
                  rspec_junit_formatter
         | 
| 58 | 
            -
                  rubocop-checkstyle_formatter
         | 
| 59 60 | 
             
                thor (0.20.3)
         | 
| 60 61 | 
             
                unicode-display_width (1.4.1)
         | 
| 62 | 
            +
                yard (0.9.18)
         | 
| 61 63 |  | 
| 62 64 | 
             
            PLATFORMS
         | 
| 63 65 | 
             
              ruby
         | 
| 64 66 |  | 
| 65 67 | 
             
            DEPENDENCIES
         | 
| 66 68 | 
             
              appraisal
         | 
| 69 | 
            +
              benchmark-ips
         | 
| 67 70 | 
             
              bundler
         | 
| 68 71 | 
             
              dry-equalizer (= 0.1.0)
         | 
| 72 | 
            +
              dry-matcher
         | 
| 69 73 | 
             
              fear!
         | 
| 74 | 
            +
              qo!
         | 
| 70 75 | 
             
              rake (~> 10.0)
         | 
| 71 76 | 
             
              rspec (~> 3.1)
         | 
| 72 | 
            -
              rubocop (= 0. | 
| 73 | 
            -
              rubocop-rspec (= 1. | 
| 74 | 
            -
               | 
| 75 | 
            -
              spbtv_code_style
         | 
| 77 | 
            +
              rubocop (= 0.65.0)
         | 
| 78 | 
            +
              rubocop-rspec (= 1.32.0)
         | 
| 79 | 
            +
              yard
         | 
| 76 80 |  | 
| 77 81 | 
             
            BUNDLED WITH
         | 
| 78 82 | 
             
               1.16.2
         | 
| @@ -1,26 +1,36 @@ | |
| 1 | 
            +
            GIT
         | 
| 2 | 
            +
              remote: git://github.com/baweaver/qo.git
         | 
| 3 | 
            +
              revision: 8951ce899559118eb60321014b43cf4211730bd0
         | 
| 4 | 
            +
              specs:
         | 
| 5 | 
            +
                qo (0.99.0)
         | 
| 6 | 
            +
                  any (= 0.1.0)
         | 
| 7 | 
            +
             | 
| 1 8 | 
             
            PATH
         | 
| 2 9 | 
             
              remote: ..
         | 
| 3 10 | 
             
              specs:
         | 
| 4 | 
            -
                fear (0. | 
| 11 | 
            +
                fear (0.11.0)
         | 
| 5 12 | 
             
                  dry-equalizer (<= 0.2.1)
         | 
| 6 13 |  | 
| 7 14 | 
             
            GEM
         | 
| 8 15 | 
             
              remote: https://rubygems.org/
         | 
| 9 16 | 
             
              specs:
         | 
| 17 | 
            +
                any (0.1.0)
         | 
| 10 18 | 
             
                appraisal (2.2.0)
         | 
| 11 19 | 
             
                  bundler
         | 
| 12 20 | 
             
                  rake
         | 
| 13 21 | 
             
                  thor (>= 0.14.0)
         | 
| 14 22 | 
             
                ast (2.4.0)
         | 
| 23 | 
            +
                benchmark-ips (2.7.2)
         | 
| 15 24 | 
             
                diff-lcs (1.3)
         | 
| 16 | 
            -
                docile (1.3.1)
         | 
| 17 25 | 
             
                dry-equalizer (0.2.1)
         | 
| 18 | 
            -
                 | 
| 26 | 
            +
                dry-matcher (0.7.0)
         | 
| 27 | 
            +
                jaro_winkler (1.5.2)
         | 
| 28 | 
            +
                parallel (1.14.0)
         | 
| 19 29 | 
             
                parser (2.6.0.0)
         | 
| 20 30 | 
             
                  ast (~> 2.4.0)
         | 
| 21 31 | 
             
                powerpack (0.1.2)
         | 
| 22 | 
            -
                 | 
| 23 | 
            -
             | 
| 32 | 
            +
                psych (3.1.0)
         | 
| 33 | 
            +
                rainbow (3.0.0)
         | 
| 24 34 | 
             
                rake (10.5.0)
         | 
| 25 35 | 
             
                rspec (3.8.0)
         | 
| 26 36 | 
             
                  rspec-core (~> 3.8.0)
         | 
| @@ -35,44 +45,38 @@ GEM | |
| 35 45 | 
             
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 36 46 | 
             
                  rspec-support (~> 3.8.0)
         | 
| 37 47 | 
             
                rspec-support (3.8.0)
         | 
| 38 | 
            -
                 | 
| 39 | 
            -
                   | 
| 40 | 
            -
             | 
| 41 | 
            -
                  parser (>= 2. | 
| 48 | 
            +
                rubocop (0.65.0)
         | 
| 49 | 
            +
                  jaro_winkler (~> 1.5.1)
         | 
| 50 | 
            +
                  parallel (~> 1.10)
         | 
| 51 | 
            +
                  parser (>= 2.5, != 2.5.1.1)
         | 
| 42 52 | 
             
                  powerpack (~> 0.1)
         | 
| 43 | 
            -
                   | 
| 53 | 
            +
                  psych (>= 3.1.0)
         | 
| 54 | 
            +
                  rainbow (>= 2.2.2, < 4.0)
         | 
| 44 55 | 
             
                  ruby-progressbar (~> 1.7)
         | 
| 45 | 
            -
                  unicode-display_width (~> 1. | 
| 46 | 
            -
                rubocop- | 
| 47 | 
            -
                  rubocop (>= 0. | 
| 48 | 
            -
                rubocop-rspec (1.13.0)
         | 
| 49 | 
            -
                  rubocop (>= 0.42.0)
         | 
| 56 | 
            +
                  unicode-display_width (~> 1.4.0)
         | 
| 57 | 
            +
                rubocop-rspec (1.32.0)
         | 
| 58 | 
            +
                  rubocop (>= 0.60.0)
         | 
| 50 59 | 
             
                ruby-progressbar (1.10.0)
         | 
| 51 | 
            -
                simplecov (0.16.1)
         | 
| 52 | 
            -
                  docile (~> 1.1)
         | 
| 53 | 
            -
                  json (>= 1.8, < 3)
         | 
| 54 | 
            -
                  simplecov-html (~> 0.10.0)
         | 
| 55 | 
            -
                simplecov-html (0.10.2)
         | 
| 56 | 
            -
                spbtv_code_style (1.7.0)
         | 
| 57 | 
            -
                  rspec_junit_formatter
         | 
| 58 | 
            -
                  rubocop-checkstyle_formatter
         | 
| 59 60 | 
             
                thor (0.20.3)
         | 
| 60 61 | 
             
                unicode-display_width (1.4.1)
         | 
| 62 | 
            +
                yard (0.9.18)
         | 
| 61 63 |  | 
| 62 64 | 
             
            PLATFORMS
         | 
| 63 65 | 
             
              ruby
         | 
| 64 66 |  | 
| 65 67 | 
             
            DEPENDENCIES
         | 
| 66 68 | 
             
              appraisal
         | 
| 69 | 
            +
              benchmark-ips
         | 
| 67 70 | 
             
              bundler
         | 
| 68 71 | 
             
              dry-equalizer (= 0.2.1)
         | 
| 72 | 
            +
              dry-matcher
         | 
| 69 73 | 
             
              fear!
         | 
| 74 | 
            +
              qo!
         | 
| 70 75 | 
             
              rake (~> 10.0)
         | 
| 71 76 | 
             
              rspec (~> 3.1)
         | 
| 72 | 
            -
              rubocop (= 0. | 
| 73 | 
            -
              rubocop-rspec (= 1. | 
| 74 | 
            -
               | 
| 75 | 
            -
              spbtv_code_style
         | 
| 77 | 
            +
              rubocop (= 0.65.0)
         | 
| 78 | 
            +
              rubocop-rspec (= 1.32.0)
         | 
| 79 | 
            +
              yard
         | 
| 76 80 |  | 
| 77 81 | 
             
            BUNDLED WITH
         | 
| 78 82 | 
             
               1.16.2
         |