/*---------------------------------------------------------------------------
  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<$43,$44> : eitherstd/core/types/either: (V, V) -> V<aa: V,bb: V> )result: -> total maybe<78> : maybestd/core/types/maybe: V -> V<bb: V>
  match ee: either<$43,$44>
    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: $44) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $44)

// 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<$86,$87> : eitherstd/core/types/either: (V, V) -> V<aa: V,bb: V>, ff: ($87) -> $89 $88 : bb: V -> ee: E cc: V  )result: -> 145 either<142,144> : ee: E eitherstd/core/types/either: (V, V) -> V<aa: V,cc: V>
  match ee: either<$86,$87>
    Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(xx: $87) -> Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(ff: ($87) -> $89 $88(xx: $87))
    Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(xx: $86)  -> Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(xx: $86)

// 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<$158,$159> : eitherstd/core/types/either: (V, V) -> V<aa: V,bb: V>, @implicit/left/show?left/show: ($158) -> $160 string : aa: V -> ee: E stringstd/core/types/string: V, @implicit/right/show?right/show: ($159) -> $160 string : bb: V -> ee: E stringstd/core/types/string: V )result: -> 238 string : ee: E stringstd/core/types/string: V
  match ee: either<$158,$159>
    Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(xx: $159) -> "Right("literal: string
count= 6
++std/core/types/(++): (x : string, y : string) -> $160 string xx: $159.show?right/show: ($159) -> $160 string ++std/core/types/(++): (x : string, y : string) -> $160 string ")"literal: string
count= 1
Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(yy: $158) -> "Left("literal: string
count= 5
++std/core/types/(++): (x : string, y : string) -> $160 string yy: $158.show?left/show: ($158) -> $160 string ++std/core/types/(++): (x : string, y : string) -> $160 string ")"literal: string
count= 1