diff --git a/emis_funky_funktions.py b/emis_funky_funktions.py index 1fec916..802b522 100644 --- a/emis_funky_funktions.py +++ b/emis_funky_funktions.py @@ -530,21 +530,24 @@ def bind_opt(f: Callable[[A], Option[B]], o: Option[A]) -> Option[B]: return f(val) case none: return none -def note(e: B, o: Option[A]) -> 'Result[A, B]': +def note(e: Callable[[], B], o: Option[A]) -> 'Result[A, B]': """ Convert an `Option` to a `Result` by attaching an error to the `None` variants - >>> note('woops!', Some(1)) + `e` should be a zero-argument function which produces the desired error value. It + will be called if and only if `o` is `None`. + + >>> note(lambda: 'woops!', Some(1)) Ok(1) - >>> note('woops!', None) + >>> note(lambda: 'woops!', None) Err('woops!') """ match o: case Some(val): return Ok(val) case None: - return Err(e) + return Err(e()) def unwrap_opt(r: Option[A]) -> A: """