Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (23 sloc) 980 Bytes
// Copyright Jay Conrod. All rights reserved.
//
// This file is part of the Gypsum standard library. Use of this
// source code is governed by the 3-clause BSD license that can be
// found in the LICENSE.txt file.
public abstract class Result[static +V, static +E]
public abstract def is-ok: boolean
public abstract def to-opt: Option[V]
public def get = to-opt.get
public final class Ok[static +V](public value: V) <: Result[V, Nothing]
public static def try-match(result: Result[V, _]): Option[V] =
match (result)
case ok: Ok[V] => Some[V](ok.value)
case _ => None
public override def is-ok = true
public override def to-opt = Some[V](value)
public final class Err[static +E](public error: E) <: Result[Nothing, E]
public static def try-match(result: Result[_, E]): Option[E] =
match (result)
case err: Err[E] => Some[E](err.error)
case _ => None
public override def is-ok = false
public override def to-opt = None