Skip to content

Clone/rewrite module functions (for instance to be able to extend some elixir module functionality)

Notifications You must be signed in to change notification settings

kelostrada/clone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clone

Build Status

Library to clone/rewrite functions in modules if you need to extend some external library

Documentation: https://hexdocs.pm/clone/

Installation

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

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

Example usage

At the begining of your module add use Clone, {Module} or import Clone and use macro clone {Module}.

defmodule MyEnum do
  use Clone, Enum

  def last([]), do: nil
  def last([element]), do: element
  def last([_ | tail] = list) when is_list(list) do
    last(tail)
  end
end

iex> MyEnum.last([1,2,3])
3

iex> MyEnum.min([1,2,3,0,2])
0


defmodule MyEnum do
  import Clone
  clone Enum

  def last([]), do: nil
  def last([element]), do: element
  def last([_ | tail] = list) when is_list(list) do
    last(tail)
  end
end

iex> MyEnum.last([1,2,3])
3

iex> MyEnum.min([1,2,3,0,2])
0

About

Clone/rewrite module functions (for instance to be able to extend some elixir module functionality)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages