Skip to content

Explicit recursion inside functions with a recursive block.

License

Notifications You must be signed in to change notification settings

CarlosHSF99/recurse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages