Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test minor change in test and readme
LICENSE refactoring and readme update
package.exs package.exs


Syntactic sugar for defining lambda functions with explicit scope. Supports short lambda definitions which are not possible with Elixir capture syntax.

  import Lambda

  ld(_1 + _2 + _3)    # same as &(&1 + &2 + &3)
  ld(1 + 2)           # zero arity function
  ld(_1)              # identity function
  ld(_2 * 2)          # guesses arity from the highest index, not all arguments have to be used
  ld(4, _2 + 3)       # explicitly set arity to 4, not all arguments have to be used 

In addition, two macros are included to compensate for pipeline shortcomings. The macro ldp can pipeline to any argument in the function call:

  |> ldp(:gb_trees.enter(:a, 1, _1))
  |> ldp(:gb_trees.enter(:b, 2, _1))

When pipelining to the last argument, this can be shortened with the ldl macro:

  |> ldl(:gb_trees.enter(:a, 1))
  |> ldl(:gb_trees.enter(:b, 2))

ldl is specifically useful with records pipelining:

  defrecord TestRecord, [a: 0, b: 0] do
    import Lambda

    def create do
      # pipelining inside the record module
      |> ldl(a(1))
      |> ldl(b(2))
      |> ldl(update_a(&(&1 + 2)))

  # pipelining outside the record module
  |> ldl(TestRecord.a(1))
  |> ldl(TestRecord.b(2))
  |> ldl(TestRecord.update_a(&(&1 + 2)))
Something went wrong with that request. Please try again.