“para loop em elixir” Respostas de código

para loop em elixir

 for x <- 0..10 do 
   IO.puts "x is: #{x}" 

#But elixir programmer use more the following style of "loop" using Enum 
Enum.each(0..9, fn x ->
  IO.puts "x is: #{x}" 
Yan Basile

elixir para 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)
    #=> :ok

Respostas semelhantes a “para loop em elixir”

Perguntas semelhantes a “para loop em elixir”

Procure respostas de código populares por idioma

Procurar outros idiomas de código