Funx Banner

Funx - Functional Programming Patterns for Elixir

Continuous Integration

Hex.pm

⚠️ Beta notice: Funx is in active development. APIs may change until version 1.0. Feedback and contributions are welcome.

As a rule, functional libraries consider teaching functional programming as out of scope. This one does not.

Funx was built alongside Advanced Functional Programming with Elixir, which helps you build lasting mental models of functional programming—showing not just how these abstractions work, but how to apply them in real systems using Elixir.

Advanced Functional Programming with Elixir Book Cover

Funx is a functional programming library for Elixir providing protocols and combinators for equality, ordering, monoids, monads, and other core abstractions.

Elixir doesn’t have a static type system, so it can’t enforce functional patterns through the compiler. Instead, it uses pattern matching, protocols, and structs to model abstractions at runtime.

Funx brings functional programming patterns into Elixir using the language’s own tools—without sacrificing its dynamic nature.

Equality

The Eq protocol defines how two values are compared, making equality explicit and adaptable to your domain.

Ordering

The Ord protocol defines ordering relationships in a structured way, without relying on Elixir’s built-in comparison operators.

Monads

Monads encapsulate computations, allowing operations to be chained while handling concerns like optional values, failures, dependencies, or deferred effects.

Monoids

Monoids combine values using an associative operation and an identity element. They are useful for accumulation, selection, and combining logic.

Predicates

Predicates are functions that return true or false. Funx provides combinators for composing them cleanly.

Folding

The Foldable protocol defines how to reduce a structure to a single result.

Useful for accumulating values, transforming collections, or extracting data.

Filtering

The Filterable protocol defines how to conditionally retain values within a context.

Sequencing

Sequencing runs a series of monadic operations in order, combining the results.

Lifting

Lifting functions promote ordinary logic into a monadic or contextual form.

Interop

Funx integrates with common Elixir patterns like {:ok, value} and {:error, reason}.

Installation

To use Funx, add it to the list of dependencies in mix.exs:

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

Then, run the following command to fetch the dependencies:

mix deps.get

Documentation

Full documentation is available on GitHub Pages.

Usage Rules

Each module includes usage rules designed for humans and LLMs:

➡️ Browse Usage Rules

Contributing

  1. Fork the repository.
  2. Create a new branch for the feature or bugfix (git checkout -b feature-branch).
  3. Commit changes (git commit -am 'Add new feature').
  4. Push the branch (git push origin feature-branch).
  5. Create a pull request.

License

This project is licensed under the MIT License.