lib/dry/monads/list.rb
# Traverses the list with a block (or without it).
# This methods "flips" List structure with the given monad (obtained from the type).
# Note that traversing requires the list to be typed.
# Also if a block given, its returning type must be equal list's type.
#
# @example
#   List<Result>[Success(1), Success(2)].traverse # => Success([1, 2])
#   List<Maybe>[Some(1), None, Some(3)].traverse # => None
#
# @return [Monad] Result is a monadic value
Traverses the list with a block (or without it).
This methods "flips" List structure with the given monad (obtained from the type).
Note that traversing requires the list to be typed.
Also if a block given, its returning type must be equal list's type.
Traverses the list with a block ( or without it ) . This methods " flips " List structure with the given monad ( obtained from the type ) . Note that traversing requires the list to be typed . Also if a block given its returning type must be equal list ' s type .
def traverse(proc = nil, &block)
        unless typed?
          raise StandardError, "Cannot traverse an untyped list"
        end
        cons = type.pure { |list, i| list + List.pure(i) }
        with = proc || block || Traverse[type]
        foldl(type.pure(EMPTY)) do |acc, el|
          cons.
            apply(acc).
            apply { with.(el) }
        end
      end
def traverse ( proc = nil , & block ) unless typed? raise StandardError , "Cannot traverse an untyped list" end cons = type . pure { | list , i | list + List . pure ( i ) } with = proc || block || Traverse [ type ] foldl ( type . pure ( EMPTY ) ) do | acc , el | cons . apply ( acc ) . apply { with . ( el ) } end end
Traverses the list with a block (or without it).
Traverses the list with a block ( or without it ) .
Result is a monadic value
Result is a monadic value
Monad
proc
<not_specific>
block
<not_specific>
example
None