import { Applicative } from "@siteimprove/alfa-applicative" ; import { Callback } from "@siteimprove/alfa-callback" ; import { Comparable , Comparison , Comparer } from "@siteimprove/alfa-comparable" ; import { Equatable } from "@siteimprove/alfa-equatable" ; import { Foldable } from "@siteimprove/alfa-foldable" ; import { Functor } from "@siteimprove/alfa-functor" ; import { Hashable } from "@siteimprove/alfa-hash" ; import { Serializable } from "@siteimprove/alfa-json" ; import { Mapper } from "@siteimprove/alfa-mapper" ; import { Monad } from "@siteimprove/alfa-monad" ; import { Predicate } from "@siteimprove/alfa-predicate" ; import { Reducer } from "@siteimprove/alfa-reducer" ; import { Refinement } from "@siteimprove/alfa-refinement" ; import { Thunk } from "@siteimprove/alfa-thunk" ; import { None } from "./none" ; import { Some } from "./some" ; public export interface Option < T > extends Functor < T > , Applicative < T > , Monad < T > , Foldable < T > , Iterable < T > , Equatable , Hashable , Serializable < Option . JSON < T > > { isSome ( ) : this is Some < T > ; isNone ( ) : this is None ; map < U > ( mapper ) : Option < U > ; apply < U > ( mapper ) : Option < U > ; flatMap < U > ( mapper ) : Option < U > ; flatten < T > ( this ) : Option < T > ; reduce < U > ( reducer , accumulator ) : U ; filter < U extends T > ( refinement ) : Option < U > ; filter ( predicate ) : Option < T > ; reject < U extends T > ( refinement ) : Option < Exclude < T , U > > ; reject ( predicate ) : Option < T > ; includes ( value ) : this is Some < T > ; some < U extends T > ( refinement ) : this is Some < U > ; some ( predicate ) : this is Some < T > ; none < U extends T > ( refinement ) : this is Option < Exclude < T , U > > ; none ( predicate ) : boolean ; every < U extends T > ( refinement ) : this is Option < U > ; every ( predicate ) : boolean ; and < U > ( option ) : Option < U > ; andThen < U > ( option ) : Option < U > ; or < U > ( option ) : Option < T | U > ; orElse < U > ( option ) : Option < T | U > ; get ( message ? ) : T ; getOr < U > ( value ) : T | U ; getOrElse < U > ( value ) : T | U ; tee ( callback ) : Option < T > ; compare < T > ( this , option ) : Comparison ; compareWith < U = T > ( option , comparer ) : Comparison ; toArray ( ) : Array < T > ; toJSON ( ) : Option . JSON < T > ; } public export namespace Option { export type Maybe < T > = T | Option < T > ; export type JSON < T > = Some . JSON < T > | None . JSON ; export function isOption < T > ( value ) ; export function isOption < T > ( value ) ; export function isOption < T > ( value ) { return isSome ( value ) || isNone ( value ) ; } export function isSome < T > ( value ) ; export function isSome < T > ( value ) ; export function isSome < T > ( value ) { return Some . isSome ( value ) ; } export function isNone < T > ( value ) ; export function isNone ( value ) ; export function isNone ( value ) { return value === None ; } export function of < T > ( value ) { return Some . of ( value ) ; } export function empty < T > ( ) { return None ; } export function from < T > ( value ) { return value === null || value === undefined ? None : Some . of ( value ! ) ; } }