Module: Mangrove::Result Abstract

Extended by:
T::Generic, T::Helpers, T::Sig
Includes:
Kernel
Included in:
Err, Ok
Defined in:
lib/mangrove/result.rb,
lib/mangrove/result/control_signal.rb

Overview

This module is abstract.

Subclasses must implement the ‘abstract` methods below.

Result is a type that represents either success (‘Ok`) or failure (`Err`).

Defined Under Namespace

Classes: ControlSignal, Err, Ok

Constant Summary collapse

OkType =
type_member
ErrType =
type_member

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_results(results) ⇒ Result[OkType, ErrType]

Parameters:

Returns:



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/mangrove/result.rb', line 53

def from_results(results)
  errs = results.filter(&:err?)

  if errs.empty?
    # This is safe as errs is empty.
    Result::Ok.new(results.map { |r| T.cast(r, Result::Ok[OkType, ErrType]).ok_inner })
  else
    # This is safe as errs is results where err? is true
    Result::Err.new(errs.map { |r| T.cast(r, Result::Err[OkType, ErrType]).err_inner })
  end
end

Instance Method Details

#==(other) ⇒ Boolean

This method is abstract.

Parameters:

  • other (BasicObject)

Returns:

  • (Boolean)


22
# File 'lib/mangrove/result.rb', line 22

def ==(other); end

#err?Boolean

This method is abstract.

Returns:

  • (Boolean)


28
# File 'lib/mangrove/result.rb', line 28

def err?; end

#expect!(message) ⇒ OkType

This method is abstract.

Parameters:

  • message (String)

Returns:



34
# File 'lib/mangrove/result.rb', line 34

def expect!(message); end

#expect_with!(&block) ⇒ OkType

This method is abstract.

Parameters:

  • block (T.proc.returns(T.untyped))

Returns:



37
# File 'lib/mangrove/result.rb', line 37

def expect_with!(&block); end

#map_err(&block) ⇒ Result[OkType, ErrType]

This method is abstract.

Parameters:

Returns:



43
# File 'lib/mangrove/result.rb', line 43

def map_err(&block); end

#map_ok(&block) ⇒ Result[OkType, ErrType]

This method is abstract.

Parameters:

Returns:



40
# File 'lib/mangrove/result.rb', line 40

def map_ok(&block); end

#ok?Boolean

This method is abstract.

Returns:

  • (Boolean)


25
# File 'lib/mangrove/result.rb', line 25

def ok?; end

#unwrap!OkType

This method is abstract.

Returns:



31
# File 'lib/mangrove/result.rb', line 31

def unwrap!; end