View Source Funx.Monad.Maybe.Just (funx v0.1.0)

Represents the Just variant of the Maybe monad, used to model the presence of a value.

A Just wraps a single value and participates in functional composition by propagating the contained value through monadic operations.

This module implements the following protocols:

  • Funx.Monad: Implements bind/2, map/2, and ap/2 for monadic composition.
  • Funx.Foldable: Provides fold_l/3 and fold_r/3 to fold over the wrapped value.
  • Funx.Filterable: Supports filtering with filter/2, filter_map/2, and guard/2.
  • Funx.Eq: Enables equality checks between Just and other Maybe values.
  • Funx.Ord: Defines ordering behavior between Just and Nothing.

These protocol implementations allow Just to participate in structured computation, validation, filtering, and comparison within the Maybe context.

Summary

Functions

Creates a new Just value.

Types

@type t(value) :: %Funx.Monad.Maybe.Just{value: value}

Functions

@spec pure(value) :: t(value) when value: term()

Creates a new Just value.

The pure/1 function wraps a value in the Just monad, representing the presence of the value.

Examples

iex> Funx.Monad.Maybe.Just.pure(5)
%Funx.Monad.Maybe.Just{value: 5}

Raises

  • ArgumentError if nil is provided.

    iex> Funx.Monad.Maybe.Just.pure(nil) ** (ArgumentError) Cannot wrap nil in a Just