Functional Programming Patterns for Elixir

What if learning was in scope?

A solid foundation built not just for use—but for understanding, mastery, and real growth.

Funx Banner

Installation

Add Funx to your mix.exs dependencies:

def deps do
  [
    {:funx, "~> 0.1.5"}
  ]
end

Then run: mix deps.get

Interactive Examples

Don't just read—practice. Use Livebooks to experiment, try patterns with live code, and check your understanding.

Launch Livebooks

Built for AI-Assisted Learning

Every module includes comprehensive usage rules designed specifically for LLMs. Your AI assistant can explain, not just suggest—keeping answers grounded in your code context.

Core Patterns

These modules are ordered so each builds on the last. Start with Eq/Ord, then move through monoids, predicates, and monads.

Equality & Ordering

Eq Protocol

Define what "equal" means for your domain:

  • • Compare by ID, name, or any attribute
  • • Compose multiple comparisons
  • • Works with structs and built-in types

Ord Protocol

Structured ordering without built-in operators:

  • • Order by size, age, or priority
  • • Chain orderings for tiebreakers
  • • Implement for any custom type

Monads

Encapsulate computations and chain operations while handling different concerns:

Maybe

Optional data with Just and Nothing

Either

Two possibilities with Left and Right

Effect

Deferred execution with error handling

Reader

Pass environment for dependency injection

Writer

Thread logs alongside results using monoids

Identity

Simple wrapper for organizing transformations

Monoids

Combine values with associative operations and identity elements:

Sum/Product: Number operations
Eq.All/Any: Equality logic
Predicate.All/Any: Boolean logic
Max/Min: Value selection
ListConcat: Combine lists
StringConcat: Combine strings
Ord: Compositional ordering