lib/dry/monads/list.rb
# Lifts a block/proc and runs it against each member of the list.
# The block must return a value coercible to a list.
# As in other monads if no block given the first argument will
# be treated as callable and used instead.
#
# @example
#   Dry::Monads::List[1, 2].bind { |x| [x + 1] } # => List[2, 3]
#   Dry::Monads::List[1, 2].bind(-> x { [x, x + 1] }) # => List[1, 2, 2, 3]
#
# @param args [Array<Object>] arguments will be passed to the block or proc
# @return [List]
Lifts a block/proc and runs it against each member of the list.
The block must return a value coercible to a list.
As in other monads if no block given the first argument will
be treated as callable and used instead.
Lifts a block / proc and runs it against each member of the list . The block must return a value coercible to a list . As in other monads if no block given the first argument will be treated as callable and used instead .
def bind(*args)
        if block_given?
          List.coerce(value.map { |v| yield(v, *args) }.reduce([], &:+))
        else
          obj, *rest = args
          List.coerce(value.map { |v| obj.(v, *rest) }.reduce([], &:+))
        end
      end
def bind ( * args ) if block_given? List . coerce ( value . map { | v | yield ( v , * args ) } . reduce ( [ ] , & :+ ) ) else obj , * rest = args List . coerce ( value . map { | v | obj . ( v , * rest ) } . reduce ( [ ] , & :+ ) ) end end
Lifts a block/proc and runs it against each member of the list.
Lifts a block / proc and runs it against each member of the list .
None
List
args
arguments will be passed to the block or proc
arguments will be passed to the block or proc
example
None