ValueLabel Module
Access and transform individual ValueLabel pairs.
A ValueLabel is an (Int, String) pair — an integer code and its human-readable label. ValueLabel data lives inside enum variants defined with the ValueLabel built-in type. This module provides functions to extract, create, transform, and query individual pairs.
All functions accept both standalone tuples and enum variants containing ValueLabel data.
Common patterns
import ValueLabel
type Gender
= Male (ValueLabel 1 "Male")
| Female (ValueLabel 2 "Female")
ValueLabel.value Gender::Male -- 1
ValueLabel.label Gender::Female -- "Female"
Gender::Male |> ValueLabel.toString -- "1: Male"
Functions
Access
ValueLabel.value
ValueLabel -> Int
Extract the integer value from a ValueLabel.
import ValueLabel
enum Gender
= Male (ValueLabel 1 "Male")
| Female (ValueLabel 2 "Female")
ValueLabel.value Gender::MaleTry itNotes: Accepts both standalone (Int, String) tuples and enum variants with ValueLabel data.
See also: ValueLabel.label, ValueLabel.toPair
ValueLabel.label
ValueLabel -> String
Extract the string label from a ValueLabel.
import ValueLabel
enum Gender
= Male (ValueLabel 1 "Male")
| Female (ValueLabel 2 "Female")
ValueLabel.label Gender::FemaleTry itNotes: Accepts both standalone (Int, String) tuples and enum variants with ValueLabel data.
See also: ValueLabel.value, ValueLabel.toPair
Create
ValueLabel.create
Int -> String -> ValueLabel
Create a standalone ValueLabel tuple from an integer value and a string label.
import ValueLabel
let vl = ValueLabel.create 1 "Yes"
ValueLabel.value vlTry itSee also: ValueLabel.value, ValueLabel.label
Convert
ValueLabel.toPair
ValueLabel -> (Int, String)
Convert a ValueLabel to a plain (Int, String) tuple. For standalone tuples this is the identity; for enum variants it unwraps the ValueLabel data.
import ValueLabel
enum Gender
= Male (ValueLabel 1 "Male")
| Female (ValueLabel 2 "Female")
ValueLabel.toPair Gender::MaleTry itSee also: ValueLabel.value, ValueLabel.label
ValueLabel.toString
ValueLabel -> String
Format a ValueLabel as "value: label" (e.g., "1: Male").
import ValueLabel
enum Gender
= Male (ValueLabel 1 "Male")
| Female (ValueLabel 2 "Female")
ValueLabel.toString Gender::MaleTry itSee also: ValueLabel.value, ValueLabel.label
Transform
ValueLabel.mapValue
(Int -> Int) -> ValueLabel -> ValueLabel
Transform the integer value of a ValueLabel, keeping the label unchanged.
import ValueLabel
enum Gender
= Male (ValueLabel 1 "Male")
| Female (ValueLabel 2 "Female")
Gender::Male |> ValueLabel.mapValue (|v| v * 10) |> ValueLabel.valueTry itSee also: ValueLabel.mapLabel
ValueLabel.mapLabel
(String -> String) -> ValueLabel -> ValueLabel
Transform the string label of a ValueLabel, keeping the value unchanged.
import ValueLabel
import String
enum Gender
= Male (ValueLabel 1 "Male")
| Female (ValueLabel 2 "Female")
Gender::Male |> ValueLabel.mapLabel String.toUpper |> ValueLabel.labelTry itSee also: ValueLabel.mapValue
Query
ValueLabel.matchesValue
Int -> ValueLabel -> Bool
Check if a ValueLabel's integer value matches the given value.
import ValueLabel
enum Gender
= Male (ValueLabel 1 "Male")
| Female (ValueLabel 2 "Female")
ValueLabel.matchesValue 1 Gender::MaleTry itSee also: ValueLabel.matchesLabel
ValueLabel.matchesLabel
String -> ValueLabel -> Bool
Check if a ValueLabel's string label matches the given label.
import ValueLabel
enum Gender
= Male (ValueLabel 1 "Male")
| Female (ValueLabel 2 "Female")
ValueLabel.matchesLabel "Male" Gender::MaleTry itSee also: ValueLabel.matchesValue