/*---------------------------------------------------------------------------
  Copyright 2012-2024, Microsoft Research, Daan Leijen.

  This is free software; you can redistribute it and/or modify it under the
  terms of the Apache License, Version 2.0. A copy of the License can be
  found in the LICENSE file at the root of this distribution.
---------------------------------------------------------------------------*/

// Standard `:either` functions.
module std/core/eitherstd/core/either

import std/core/typesstd/core/types
import std/core/hndstd/core/hnd

// Convert a `:either` to a `:maybe` type discarding the value of the `Left` constructor
// and using `Just` for the `Right` constructor.
pub fun maybestd/core/either/maybe: forall<a,b> (e : either<a,b>) -> maybe<b>( ee: either<$103,$104> : eitherstd/core/types/either: (V, V) -> V<aa: V,bb: V> )result: -> total maybe<132> : maybestd/core/types/maybe: V -> V<bb: V>
  match ee: either<$103,$104>
    Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b> -> Nothingstd/core/types/Nothing: forall<a> maybe<a>
    Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(xx: $104) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $104)

// Map over the `Right` component of an `:either` type.
pub fun mapstd/core/either/map: forall<a,b,c,e> (e : either<a,b>, f : (b) -> e c) -> e either<a,c>( ee: either<$43,$44> : eitherstd/core/types/either: (V, V) -> V<aa: V,bb: V>, ff: ($44) -> $46 $45 : bb: V -> ee: E cc: V  )result: -> 90 either<87,89> : ee: E eitherstd/core/types/either: (V, V) -> V<aa: V,cc: V>
  match ee: either<$43,$44>
    Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(xx: $44) -> Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(ff: ($44) -> $46 $45(xx: $44))
    Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(xx: $43)  -> Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(xx: $43)

// Show an `:either` type
pub fun showstd/core/either/show: forall<a,b,e> (e : either<a,b>, @implicit/left/show : (a) -> e string, @implicit/right/show : (b) -> e string) -> e string( ee: either<$140,$141> : eitherstd/core/types/either: (V, V) -> V<aa: V,bb: V>, @implicit/left/show?left/show: ($140) -> $142 string : aa: V -> ee: E stringstd/core/types/string: V, @implicit/right/show?right/show: ($141) -> $142 string : bb: V -> ee: E stringstd/core/types/string: V )result: -> 226 string : ee: E stringstd/core/types/string: V
  match ee: either<$140,$141>
    Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(xx: $141) -> "Right("literal: string
count= 6
++std/core/types/(++): (x : string, y : string) -> $142 string xx: $141.show?right/show: ($141) -> $142 string ++std/core/types/(++): (x : string, y : string) -> $142 string ")"literal: string
count= 1
Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(yy: $140) -> "Left("literal: string
count= 5
++std/core/types/(++): (x : string, y : string) -> $142 string yy: $140.show?left/show: ($140) -> $142 string ++std/core/types/(++): (x : string, y : string) -> $142 string ")"literal: string
count= 1