Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-log

Structured event logging for Pudu: message templates, enrichment, filtering, formatting, and sinks

0.1.0Apache-2.01

InstallClose

Properties.pudu

Pudu34 lines1.4 KB

GitHub ↗
1/** @Log.Domain.Properties.Module — ordered property lists keyed by name */2module PuduLangLog.Domain.Properties34import Std.List as List5import PuduLangLog as Log67/// The value bound to a name.8export fn find(properties: &Array[Log.Property], name: Str) -> Option[Log.Value] {9  let found = List.find(properties, |property: Log.Property| property.name == name) ?10  Some(found.value)11}1213/// Whether a name is bound.14export fn has(properties: &Array[Log.Property], name: Str) -> Bool {15  List.any(properties, |property: Log.Property| property.name == name)16}1718/// The list with the name bound to the value, replacing an existing binding in place or adding19/// it at the end.20export fn put(properties: &Array[Log.Property], name: Str, value: Log.Value) -> Array[Log.Property] {21  if !has(properties, name) { return properties.push(Log.Property{name: name, value: value}) }22  properties.map(|property: Log.Property| if property.name == name { Log.Property{name: name, value: value} } else { property })23}2425/// The list with the name bound to the value unless it is already bound.26export fn putIfAbsent(properties: &Array[Log.Property], name: Str, value: Log.Value) -> Array[Log.Property] {27  if has(properties, name) { *properties } else { properties.push(Log.Property{name: name, value: value}) }28}2930/// The list without a binding for the name.31export fn remove(properties: &Array[Log.Property], name: Str) -> Array[Log.Property] {32  properties.filter(|property: Log.Property| property.name != name)33}34