diff --git a/emis_funky_funktions.py b/emis_funky_funktions.py index d37eb78..53e0401 100644 --- a/emis_funky_funktions.py +++ b/emis_funky_funktions.py @@ -184,6 +184,12 @@ 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]: + match o: + case Some(val): + return Ok(val) + case None: + return Err(e) # Results! @dataclass(frozen=True) @@ -204,4 +210,16 @@ def bind_res(f: Callable[[A], Result[C, B]], r: Result[A, B]) -> Result[C, B]: case Ok(val): return f(val) case not_okay: - return not_okay \ No newline at end of file + return not_okay +def map_err(f: Callable[[B], C], r: Result[A, B]) -> Result[A, C]: + match r: + case Err(e): + return Err(f(e)) + case oki_doke: + return oki_doke +def hush(r: Result[A, Any]) -> Option[A]: + match r: + case Ok(val): + return Some(val) + case not_okay: + return None \ No newline at end of file