View Source Funx.Macros (funx v0.1.0)

Provides macros for automatically implementing Funx.Eq and Funx.Ord protocols for a given struct based on a specified field.

These macros simplify the process of defining equality and ordering behaviors for custom structs by leveraging an existing field's comparison operations.

Summary

Functions

Generates an implementation of the Funx.Eq protocol for the given struct, using the specified field as the basis for equality comparison.

Generates an implementation of the Funx.Ord protocol for the given struct, using the specified field as the basis for ordering comparisons.

Functions

Link to this macro

eq_for(for_struct, field)

View Source (macro)

Generates an implementation of the Funx.Eq protocol for the given struct, using the specified field as the basis for equality comparison.

Examples

defmodule Person do
  defstruct [:name, :age]
end

require Funx.Macros
Funx.Macros.eq_for(Person, :age)

iex> Eq.eq?(%Person{age: 30}, %Person{age: 30})
true

iex> Eq.eq?(%Person{age: 25}, %Person{age: 30})
false
Link to this macro

ord_for(for_struct, field)

View Source (macro)

Generates an implementation of the Funx.Ord protocol for the given struct, using the specified field as the basis for ordering comparisons.

Examples

defmodule Person do
  defstruct [:name, :age]
end

require Funx.Macros
Funx.Macros.ord_for(Person, :age)

iex> Ord.lt?(%Person{age: 25}, %Person{age: 30})
true

iex> Ord.gt?(%Person{age: 35}, %Person{age: 30})
true