Is there an identity function already defined Elixir ?
Something like:
identity = fn a -> a end
An Elixir function is typically named, and is called a "named function". Functions are defined with the def keyword followed by a parameter list. A function also has a body containing the contents of the function. Like modules, the function body begins with the do keyword and ends with the end keyword.
Basically it's a reference to “string” type which is being used by functions from Elixir's String module.
@focused is correct - 1.10-dev has added the identity function.
Documentation
Old Answer: No such function has been predefined (at least that I'm aware of). It can trivially be written as you've done in your question, or more succinctly as &(&1)
.
Function.identity/1
has been added to Elixir v1.10.0-dev recently:
Commit
Usage example:
Enum.map([1, 2, 3, 4], &Function.identity/1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With