Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/array.rb

Overview

Reopen Array to add some handy capabilities idoimatic to Ruby.

Instance Method Summary collapse

Instance Method Details

#into_resultMonadOxide::Result<Array<V>, Array<E>>

Take an Array of Results and convert them to a single Result whose value is an Array of Ok or Err values. Ok Results will have only Ok values, and Err Results will have only Err values. A single Err in the input Array will convert the entire Result into an Err.

array of all of the Oks or Errs in the Array.

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/array.rb', line 12

def into_result()
  tracker = {
    oks: [],
    errs: [],
  }
  self.each do |result|
    result.match({
      MonadOxide::Ok => ->(x) { tracker[:oks].push(x) },
      MonadOxide::Err => ->(e) { tracker[:errs].push(e) },
    })
  end
  tracker[:errs].empty?() ?
    MonadOxide.ok(tracker[:oks]) :
    MonadOxide.err(tracker[:errs])
end