Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mixfix

A simple Elixir library for creating mixfix operators - operators where parts are interspersed with arguments.

What are Mixfix Operators?

Mixfix operators allow you to create custom syntax where operator parts are mixed with arguments. For example, instead of writing if(condition, then_branch, else_branch), you can create a more readable syntax like xif(condition.then(consequence).else(otherwise)).

Usage

Ordered Mixfix Operators

Use defmix to create operators where arguments must be provided in the exact order specified:

defmodule Example do
  import Mixfix

  # Define a mixfix operator with parts: xif, then, else
  defmix xif_then_else(condition, consequence, otherwise) do
    if condition do
      consequence
    else
      otherwise
    end
  end
end

# Usage - arguments must be in order: condition, then, else
xif(true.then("yes").else("no"))   # => "yes"
xif(false.then("yes").else("no"))  # => "no"

Unordered Mixfix Operators

Use defmix_unordered to create operators where arguments can be provided in any order:

defmodule Example do
  import Mixfix

  # Define an unordered mixfix operator
  defmix_unordered xif2_then_else(condition, consequence, otherwise) do
    if condition do
      consequence
    else
      otherwise
    end
  end
end

# Usage - arguments can be in any order
xif2(true.then("yes").else("no"))   # => "yes"
xif2(true.else("no").then("yes"))   # => "yes" (same result!)

About

Cursed mixfix operators in Elixir.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages