Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR ELIXIR

elixir for loop

## Use Enum.map or Enum.each

  @spec map(t(), (element() -> any())) :: list()

Returns a list where each element is the result of invoking fun on each
corresponding element of enumerable.

For maps, the function expects a key-value tuple.

## Examples

    iex> Enum.map([1, 2, 3], fn x -> x * 2 end)
    [2, 4, 6]

    iex> Enum.map([a: 1, b: 2], fn {k, v} -> {k, -v} end)
    [a: -1, b: -2]




@spec each(t(), (element() -> any())) :: :ok

Invokes the given fun for each element in the enumerable.

Returns :ok.

## Examples

    Enum.each(["some", "example"], fn x -> IO.puts(x) end)
    "some"
    "example"
    #=> :ok
 
PREVIOUS NEXT
Tagged: #elixir #loop
ADD COMMENT
Topic
Name
4+2 =