loteks / recurse

Explicit recursion inside functions with a recursive block.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Recurse

hex.pm hex.pm hex.pm hexdocs.pm

Explicit recursion inside functions with a recursive block.

Installation

The package can be installed by adding recurse to your list of dependencies in mix.exs:

def deps do
  [
    {:recurse, "~> 0.1.0"}
  ]
end

Usage

Without Recurse, a tail-recursive definition of reverse could be written like this:

def reverse(list), do: do_reverse(list, [])

defp do_reverse([], acc), do: acc
defp do_reverse([head | tail], acc) do
  do_reverse(tail, [head | acc])
end

With Recurse, you could do it like this:

def reverse(list) do
  recurse on list, [] do
    [], acc -> acc
    [head | tail], acc -> recurse tail, [head | acc]
  end
end

License

Recurse is released under the GPL-3.0 license - see the LICENSE file.

About

Explicit recursion inside functions with a recursive block.

License:GNU General Public License v3.0


Languages

Language:Elixir 100.0%