Funx Banner

Funx - Functional Programming Patterns for Elixir

Continuous IntegrationHex.pm

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

Official website:https://www.funxlib.com
Code and API documentation:https://hex.pm/packages/funx

Installation

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

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

Then, run the following command to fetch the dependencies:

mix deps.get

Usage Rules

Funx includes embedded usage rules in addition to API documentation.
They are written for development workflows assisted by LLMs.

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.

Either DSL

The Either monad includes a DSL for writing declarative pipelines that handle errors gracefully:

use Funx.Monad.Either
either user_id do
bind fetch_user()
bind validate_active()
map transform_to_dto()
end

Supported operations:

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}.

Documentation

The authoritative API documentation is published on HexDocs.

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.