Fibonacci in Elixir

Published on 28 May 2026 (Updated: 28 May 2026)

Welcome to the Fibonacci in Elixir page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

defmodule Fibonacci do
  @doc """
  Returns the first `number` elements of the Fibonacci sequence as a list.
  """  
  @spec fibonacci(number :: integer()) :: list(integer())
  def fibonacci(number) do
    Stream.unfold({1, 1}, fn {m, n} -> {m, {n, m+n}} end)
    |> Enum.take(number)
  end
end

with [number] <- System.argv(),
     {number, ""} <- Integer.parse(number) do
  Fibonacci.fibonacci(number)
  |> Enum.with_index(1)
  |> Enum.each(fn {n, i} -> IO.puts("#{i}: #{n}") end)
else
  _ -> IO.puts("Usage: please input the count of fibonacci numbers to output")
end

Fibonacci in Elixir was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.