import { None } from '../option/none' ; import { Option } from '../option/option' ; import { Try } from './try' ; /**
 * Failure represents a computation that threw an exception during execution.  It signals that a
 * computation that may or may not have succeeded ended up failing.
 */ class Failure < A > implements Try < A > { private error : Error ; get exception ( ) : Error { return this . error ; } get isFailure ( ) : boolean { return true ; } get isSuccess ( ) : boolean { return false ; } constructor ( error ) { this . error = error ; } equals < B > ( other ) { return ( other instanceof Failure ) && this . error === other . error ; } filter ( predicate ) { return this ; } flatMap < B > ( f ) { return new Failure < B > ( this . error ) ; } foreach ( run ) { } get ( ) { throw this . error ; } getOrElse < B , A extends B > ( this , defaultValue ) { return defaultValue ( ) ; } map < B > ( f ) { return new Failure < B > ( this . error ) ; } match < B > ( matcher ) { return matcher . Failure ( this . error ) ; } orElse < B , A extends B > ( this , alternative ) { return alternative ( ) ; } recover ( fn ) { return Try ( ( ) => fn ( this . error ) ) ; } recoverWith ( fn ) { return fn ( this . error ) ; } toOption ( ) { return None ; } } export { Failure } ;