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

// 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<$105,$106> : eitherstd/core/types/either: (V, V) -> V<aa: V,bb: V>, ff: ($106) -> $108 $107 : bb: V -> ee: E cc: V  )result: -> 167 either<164,166> : ee: E eitherstd/core/types/either: (V, V) -> V<aa: V,cc: V>
  match ee: either<$105,$106>
    Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(xx: $106) -> Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(ff: ($106) -> $108 $107(xx: $106))
    Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(xx: $105)  -> Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(xx: $105)

// Equality on `:either` values
pub fun (==)std/core/either/(==): forall<a,b,e> (e1 : either<a,b>, e2 : either<a,b>, @implicit/left/(==) : (a, a) -> e bool, @implicit/right/(==) : (b, b) -> e bool) -> e bool(e1e1: either<$180,$181>: eitherstd/core/types/either: (V, V) -> V<aa: V,bb: V>, e2e2: either<$180,$181>: eitherstd/core/types/either: (V, V) -> V<aa: V,bb: V>, (@implicit/left/==)?left/(==): ($180, $180) -> $182 bool: (aa: V, aa: V) -> ee: E boolstd/core/types/bool: V, (@implicit/right/==)?right/(==): ($181, $181) -> $182 bool: (bb: V, bb: V) -> ee: E boolstd/core/types/bool: V)result: -> 258 bool : ee: E boolstd/core/types/bool: V
  match e1e1: either<$180,$181>
    Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(l1l1: $180) -> match e2e2: either<$180,$181> 
      Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(l2l2: $180) -> l1l1: $180 ==?left/(==): ($180, $180) -> $182 bool l2l2: $180
      _ -> Falsestd/core/types/False: bool
    Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(r1r1: $181) -> match e2e2: either<$180,$181> 
      Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(r2r2: $181) -> r1r1: $181 ==?right/(==): ($181, $181) -> $182 bool r2r2: $181
      _ -> Falsestd/core/types/False: bool

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