From dc1c9bdd6d93d08d3d566e9a378be7d5139d0482 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 5 May 2025 05:32:23 -0400 Subject: [PATCH] stdlib: Add map* for Option and Result --- stdlib/std/option.cl | 7 +++++++ stdlib/std/result.cl | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/stdlib/std/option.cl b/stdlib/std/option.cl index 902123a..e36458f 100644 --- a/stdlib/std/option.cl +++ b/stdlib/std/option.cl @@ -19,4 +19,11 @@ impl Option { None => true, } } + /// Maps from one option space to another + // pub fn map(self: Self, f: fn(T) -> U) -> Option { + // match self { + // Some(value) => Some(f(value)), + // None => None, + // } + // } } diff --git a/stdlib/std/result.cl b/stdlib/std/result.cl index 4b9b12b..2275ff7 100644 --- a/stdlib/std/result.cl +++ b/stdlib/std/result.cl @@ -19,4 +19,18 @@ impl Result { Err(_) => true, } } + /// Maps the value inside the Result::Ok, leaving errors alone. + // pub fn map(self, f: fn(T) -> U) -> Result { + // match self { + // Ok(t) => Ok(f(t)), + // Err(e) => Err(e), + // } + // } + /// Maps the value inside the Result::Err, leaving values alone. + // pub fn map_err(self, f: fn(E) -> F) -> Result { + // match self { + // Ok(t) => Ok(t), + // Err(e) => Err(f(e)), + // } + // } }