HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to ElixirVariablesData TypesOperatorsStringsListsConditions (if / else)Iteration (Enum)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
🔢 Numbers & Math
✍️ String
📚 List & Enum
🔀 Condition
🧩 Function
Anonymous function (fn)def (module function)
Elixir›REFERENCE›Function›Anonymous function (fn)

Anonymous function (fn)

Unnamed function.

Syntax

f = fn param -> expression end;  f.(x)

Description

Defined with fn ... -> ... end and bound to a variable. When called, a DOT is required: f.(x). Frequently used in Enum callbacks.

Example

Loading editor…

Expected output

25

When to use?

Enum.map/each callbacks, short operations.

Common mistakes

  • ⚠️ A dot is required when calling an anonymous function: square.(5).

Related commands

def (module function)
def (module function) →
HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code