export interface Eq { param other equals ( other ) : boolean ; } export interface PartialOrd { param other partialCompare ( other ) : number ; } export class Maybe { static of < T > ( value ) { return value === undefined || value === null ? None . of ( ) : Some . of ( value ) ; } } export interface MaybeProvider < T > { readonly isSome : boolean ; readonly isNone : boolean ; /**
     * Transform the mapped element and return a new  MaybeProvider with the result.
     *
     *  param f map < R > ( f ) : MaybeProvider < R > ; flatMap < R > ( f ) : MaybeProvider < R > ; get ( ) : T ; param value returns getOrElse ( value ) : T ; param value returns a new  MaybeProvider defaulting ( value ) : MaybeProvider < T > ; } export class Some < T > implements MaybeProvider < T > { readonly isSome : boolean = true ; readonly isNone : boolean = false ; private constructor ( private value ) { } map < R > ( f ) { return Maybe . of ( f ( this . value ) ) ; } flatMap < R > ( f ) { return f ( this . value ) ; } get ( ) { return this . value ; } getOrElse ( _value ) { return this . value ; } defaulting ( value ) { return Maybe . of ( this . getOrElse ( value ) ) ; } static of < T > ( value ) { if ( value === null || value === undefined ) { throw new Error ( 'value is ${value}' ) ; } return new Some ( value ) ; } } export class None < T > implements MaybeProvider < T > { readonly isSome : boolean = false ; readonly isNone : boolean = true ; private constructor ( ) { } get ( ) { throw new Error ( 'value is null' ) ; } getOrElse ( value ) { return value ; } map < R > ( _f ) { return new None < R > ( ) ; } flatMap < R > ( _f ) { return new None < R > ( ) ; } defaulting ( value ) { return Maybe . of ( this . getOrElse ( value ) ) ; } static of < T > ( ) { return new None ( ) ; } }