import { None } from './none' ; import { Some } from './some' ; /**
 * An Option represents a collection of size 0 or 1.  Traditionally it's used as a replacement for
 * `null` or `undefined` to explicitly encode if a value can be empty or not.
 *
 * :TODO: Narrow self-type in `getOrElse` and `orElse` interfaces.
 */ interface Option < A > { isDefined : boolean ; isEmpty : boolean ; equals < B > ( other ) : boolean ; filter ( predicate ) : Option < A > ; filterNot ( predicate ) : Option < A > ; flatMap < B > ( flatMapper ) : Option < B > ; foreach ( run ) : void ; get ( ) : A ; getOrElse < B > ( defaultValue ) : B ; map < B > ( mapper ) : Option < B > ; match < B > ( matcher ) : B ; orElse < B > ( alternative ) : Option < B > ; } function Option < A > ( value ) { if ( ( value === null ) || ( value === undefined ) ) { return None ; } else { return new Some ( value ) ; } } namespace Option { /**
     * This error is thrown when `None.get()` is called.
     */ export class NoSuchElementError extends Error { constructor ( ) { super ( ) ; this . name = 'NoSuchElementError' ; this . message = 'Monapt.Option.get(): No such element.' ; this . stack = ( new Error ( ) ) . stack ; } } export function flatten < A > ( options ) { return options . filter ( ( option ) : boolean => option . isDefined ) . map ( ( option ) : A => option . get ( ) ) ; } } export { Option } ;