Module: Mayak::Monads::Result

Extended by:
T::Generic, T::Helpers, T::Sig
Included in:
Failure, Success
Defined in:
lib/mayak/monads/result.rb

Defined Under Namespace

Classes: Failure, Success

Constant Summary collapse

FailureType =
type_member(:out)
SuccessType =
type_member(:out)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sequence(results) ⇒ Object



217
218
219
220
221
222
223
224
# File 'lib/mayak/monads/result.rb', line 217

def self.sequence(results)
  init = Success[T.type_parameter(:FailureType), T::Array[T.type_parameter(:SuccessType)]].new([])
  results.reduce(init) do |result, element|
    result.flat_map do |array|
      element.map { |value| array + [value] }
    end
  end
end

Instance Method Details

#==(another) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/mayak/monads/result.rb', line 143

def ==(another)
  case self
  when Mayak::Monads::Result::Success
    case another
    when Mayak::Monads::Result::Success then T.unsafe(success) == another.success
    when Mayak::Monads::Result::Failure then false
    else T.absurd(another)
    end
  when Mayak::Monads::Result::Failure
    case another
    when Mayak::Monads::Result::Success then false
    when Mayak::Monads::Result::Failure then T.unsafe(failure) == another.failure
    else T.absurd(another)
    end
  else
    T.absurd(self)
  end
end

#as(new_value) ⇒ Object



167
168
169
# File 'lib/mayak/monads/result.rb', line 167

def as(new_value)
  map { |_| new_value }
end

#either(failure_branch, success_branch) ⇒ Object



98
99
# File 'lib/mayak/monads/result.rb', line 98

def either(failure_branch, success_branch)
end

#failure?Boolean

Returns:

  • (Boolean)


51
52
# File 'lib/mayak/monads/result.rb', line 51

def failure?
end

#failure_as(new_failure) ⇒ Object



106
107
108
# File 'lib/mayak/monads/result.rb', line 106

def failure_as(new_failure)
  map_failure { |_| new_failure }
end

#failure_or(value) ⇒ Object



69
70
# File 'lib/mayak/monads/result.rb', line 69

def failure_or(value)
end

#filter_or(error, &blk) ⇒ Object



43
44
# File 'lib/mayak/monads/result.rb', line 43

def filter_or(error, &blk)
end

#flat_map(&blk) ⇒ Object



34
35
# File 'lib/mayak/monads/result.rb', line 34

def flat_map(&blk)
end

#flat_map_failure(&blk) ⇒ Object



139
140
# File 'lib/mayak/monads/result.rb', line 139

def flat_map_failure(&blk)
end

#flipObject



73
74
# File 'lib/mayak/monads/result.rb', line 73

def flip
end

#map(&blk) ⇒ Object



23
24
# File 'lib/mayak/monads/result.rb', line 23

def map(&blk)
end

#map_failure(&blk) ⇒ Object



127
128
# File 'lib/mayak/monads/result.rb', line 127

def map_failure(&blk)
end

#recover(value) ⇒ Object



177
178
# File 'lib/mayak/monads/result.rb', line 177

def recover(value)
end

#recover_with(&blk) ⇒ Object



186
187
# File 'lib/mayak/monads/result.rb', line 186

def recover_with(&blk)
end

#recover_with_result(&blk) ⇒ Object



198
199
# File 'lib/mayak/monads/result.rb', line 198

def recover_with_result(&blk)
end

#success?Boolean

Returns:

  • (Boolean)


47
48
# File 'lib/mayak/monads/result.rb', line 47

def success?
end

#success_or(value) ⇒ Object



60
61
# File 'lib/mayak/monads/result.rb', line 60

def success_or(value)
end

#tee(&blk) ⇒ Object



115
116
# File 'lib/mayak/monads/result.rb', line 115

def tee(&blk)
end

#to_maybeObject



85
86
# File 'lib/mayak/monads/result.rb', line 85

def to_maybe
end

#to_try(&blk) ⇒ Object



81
82
# File 'lib/mayak/monads/result.rb', line 81

def to_try(&blk)
end