glint/constraint

Types

Constraint type for verifying flag values

pub type Constraint(a) =
  fn(a) -> snag.Result(a)

Functions

pub fn each(
  constraint: fn(a) -> Result(a, Snag),
) -> fn(List(a)) -> Result(List(a), Snag)

This is a convenience function for applying a Constraint(a) to a List(a). This is useful because the default behaviour for constraints on lists is that they will apply to the list as a whole.

For example, to apply one_of to all items in a List(Int):

Via use:

import glint
import glint/constraint
...
use li <- glint.flag_constraint(glint.int_flag("my_flag"))
use i <- constraint.each()
i |> one_of([1, 2, 3, 4])

via a pipe:

import glint
import glint/constraint
...
glint.int_flag("my_flag")
|> glint.flag_constraint(
  constraint.one_of([1,2,3,4])
  |> constraint.each
)
pub fn none_of(disallowed: List(a)) -> fn(a) -> Result(a, Snag)

Returns a Constraint that ensures the parsed flag value is not one of the disallowed values.

import glint
import glint/constraint
...
glint.int_flag("my_flag")
|> glint.constraint(constraint.none_of([1, 2, 3, 4]))
pub fn one_of(allowed: List(a)) -> fn(a) -> Result(a, Snag)

Returns a Constraint that ensures the parsed flag value is one of the allowed values.

import glint
import glint/constraint
...
glint.int_flag("my_flag")
|> glint.constraint(constraint.one_of([1, 2, 3, 4]))
Search Document