Class: Qo::Branches::ErrorBranch

Inherits:
Branch
  • Object
show all
Defined in:
lib/qo/branches/error_branch.rb

Overview

A tuple branch that will be triggered when the first value is :err.

ResultPatternMatch.new { |m|
  m.error { |v| "This is the error: #{v}" }
}.call([:err, 'OH NO!'])
# => "This is the error: OH NO!"

Author:

  • baweaver

Since:

  • 1.0.0

Constant Summary

Constants inherited from Branch

Branch::UNMATCHED

Instance Attribute Summary

Attributes inherited from Branch

#name

Instance Method Summary collapse

Methods inherited from Branch

create, #create_matcher, #default?

Constructor Details

#initialize(destructure: false) ⇒ ErrorBranch

Returns a new instance of ErrorBranch

Since:

  • 1.0.0



16
17
18
19
20
21
22
23
# File 'lib/qo/branches/error_branch.rb', line 16

def initialize(destructure: false)
  super(
    name: 'error',
    destructure: destructure,
    precondition: -> v { v.first == :err },
    extractor: :last,
  )
end