Module: Dry::Monads::RightBiased::Left

Included in:
Maybe::None, Dry::Monads::Result::Failure, Try::Error
Defined in:
lib/dry/monads/right_biased.rb

Overview

Left/wrong/erroneous part

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.trace_callerString

Returns Caller location.

Returns:

  • (String)

    Caller location


166
167
168
# File 'lib/dry/monads/right_biased.rb', line 166

def self.trace_caller
  caller_locations(2, 2)[0].to_s
end

Instance Method Details

#applyRightBiased::Left

Ignores the input parameter and returns self. It exists to keep the interface identical to that of Right.

Returns:


237
238
239
# File 'lib/dry/monads/right_biased.rb', line 237

def apply(*)
  self
end

#bindRightBiased::Left

Ignores the input parameter and returns self. It exists to keep the interface identical to that of Right.

Returns:


179
180
181
# File 'lib/dry/monads/right_biased.rb', line 179

def bind(*)
  self
end

#discardRightBiased::Left

Returns self back. It exists to keep the interface identical to that of Right.

Returns:


245
246
247
# File 'lib/dry/monads/right_biased.rb', line 245

def discard
  fmap { Unit }
end

#fmapRightBiased::Left

Ignores the input parameter and returns self. It exists to keep the interface identical to that of Right.

Returns:


195
196
197
# File 'lib/dry/monads/right_biased.rb', line 195

def fmap(*)
  self
end

#orObject

Left-biased #bind version.

Examples:

Dry::Monads.Left(ArgumentError.new('error message')).or(&:message) # => "error message"
Dry::Monads.None.or('no value') # => "no value"
Dry::Monads.None.or { Time.now } # => current time

Returns:

  • (Object)

Raises:

  • (NotImplementedError)

207
208
209
# File 'lib/dry/monads/right_biased.rb', line 207

def or(*)
  raise NotImplementedError
end

#or_fmapRightBiased::Left, RightBiased::Right

A lifted version of #or. This is basically #or + #fmap.

Examples:

Dry::Monads.None.or('no value') # => Some("no value")
Dry::Monads.None.or { Time.now } # => Some(current time)

Returns:

Raises:

  • (NotImplementedError)

218
219
220
# File 'lib/dry/monads/right_biased.rb', line 218

def or_fmap(*)
  raise NotImplementedError
end

#teeRightBiased::Left

Ignores the input parameter and returns self. It exists to keep the interface identical to that of Right.

Returns:


187
188
189
# File 'lib/dry/monads/right_biased.rb', line 187

def tee(*)
  self
end

#value!Object

Raises an error on accessing internal value

Raises:


171
172
173
# File 'lib/dry/monads/right_biased.rb', line 171

def value!
  raise UnwrapError.new(self)
end

#value_or(val = nil) ⇒ Object

Returns the passed value

Returns:

  • (Object)

225
226
227
228
229
230
231
# File 'lib/dry/monads/right_biased.rb', line 225

def value_or(val = nil)
  if block_given?
    yield
  else
    val
  end
end