import { Applicative } from "@siteimprove/alfa-applicative" ; import { Either , Left , Right } from "@siteimprove/alfa-either" ; import { Equatable } from "@siteimprove/alfa-equatable" ; import { Functor } from "@siteimprove/alfa-functor" ; import { Hash , 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 { Refinement } from "@siteimprove/alfa-refinement" ; /**
 *  https public export class Selective < S , T = never > implements Functor < T > , Applicative < T > , Monad < T > , Iterable < S | T > , Equatable , Hashable , Serializable < Selective . JSON < S , T > > { public static of < T > ( value ) { return new Selective ( Left . of ( value ) ) ; } private readonly _value : Either < S , T > ; private constructor ( value ) { this . _value = value ; } public map < U > ( mapper ) { return new Selective ( this . _value . map ( mapper ) ) ; } public apply < U > ( mapper ) { return mapper . flatMap ( ( mapper ) => this . map ( mapper ) ) ; } public flatMap < U > ( mapper ) { return new Selective ( this . _value . flatMap ( ( value ) => mapper ( value ) . _value ) ) ; } public flatten < S , T > ( this ) { return this . flatMap ( ( selective ) => selective ) ; } public if < P extends S , U > ( refinement , mapper ) ; public if < U > ( predicate , mapper ) ; public if < U > ( predicate , mapper ) { return this . _value . either ( ( value ) => predicate ( value ) ? new Selective < S , U > ( Right . of ( mapper ( value ) ) ) : this , ( ) => this ) ; } public else < U > ( mapper ) { return new Selective < never , T | U > ( Right . of ( this . _value . either < T | U > ( ( value ) => mapper ( value ) , ( value ) => value ) ) ) ; } public get ( ) { return this . _value . get ( ) ; } /**
     * Ensure that this  {@link (Selective:class)} is exhaustively matched, returning
     * its resulting value.
     *
     *  remarks This method should only be used for cases where  {@link (Selective:class).get} * is insufficient. If in doubt, assume that it isn't.
      public exhaust < T > ( this ) { return this . get ( ) ; } public equals < S , T > ( value ) ; public equals ( value ) ; public equals ( value ) { return value instanceof Selective && value . _value . equals ( this . _value ) ; } public hash ( hash ) { hash . writeHashable ( this . _value ) ; } public * iterator ( ) { yield this . _value . get ( ) ; } public [ Symbol . iterator ] ( ) { return this . iterator ( ) ; } public toJSON ( ) { return this . _value . toJSON ( ) ; } public toString ( ) { return `Selective { ${ this . _value } }` ; } } public export namespace Selective { export type JSON < S , T = never > = Either . JSON < S , T > ; }