View Source Funx.Monoid.Utils (funx v0.1.0)

Utility functions for working with Monoids.

This module provides functions to combine monoidal values using m_append/3 and m_concat/2.

Summary

Functions

Appends two values within a given monoid.

Concatenates a list of values using the given monoid.

Functions

@spec m_append(struct(), any(), any()) :: any()

Appends two values within a given monoid.

This function wraps the input values using the provided monoid, applies the append/2 operation, and then unwraps the result.

Parameters

  • monoid – A monoid struct defining how values should be combined.
  • a – The first raw value.
  • b – The second raw value.

Examples

iex> alias Funx.Monoid.Sum
iex> Funx.Monoid.Utils.m_append(%Sum{}, 3, 5)
8
Link to this function

m_concat(monoid, values)

View Source
@spec m_concat(
  struct(),
  list()
) :: any()

Concatenates a list of values using the given monoid.

This function wraps each value using the provided monoid, folds the list using the monoid's identity and append operation, and then unwraps the result.

Parameters

  • monoid – A monoid struct defining how values should be combined.
  • values – A list of raw values.

Examples

iex> alias Funx.Monoid.Sum
iex> Funx.Monoid.Utils.m_concat(%Sum{}, [1, 2, 3])
6