/*! * Copyright (c) 2017-2018 by The Funfix Project Developers. * Some rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* @flow */ import type { HK, HK2 } from "funland" import { Setoid, Monad } from "funland" import type { Throwable } from "./errors" declare export class Either<+L, +R> { +value: L | R; get(): R; getOrElse(fallback: RR): R | RR; getOrElseL(thunk: () => RR): R | RR; isLeft(): boolean; isRight(): boolean; contains(elem: R): boolean; exists(p: (r: R) => boolean): boolean; filterOrElse(p: (r: R) => boolean, zero: () => LL): Either; flatMap(f: (r: R) => Either): Either; fold(left: (l: L) => S, right: (r: R) => S): S; forAll(p: (r: R) => boolean): boolean; map(f: (r: R) => C): Either; forEach(cb: (r: R) => void): void; swap(): Either; toOption(): Option; equals(that: Either): boolean; hashCode(): number; // Implements Constructor static +_Class: Either; static left(value: L): Either; static right(value: R): Either; static map2( fa1: Either, fa2: Either, f: (A1, A2) => R): Either; static map3( fa1: Either, fa2: Either, fa3: Either, f: (A1, A2, A3) => R): Either; static map4( fa1: Either, fa2: Either, fa3: Either, fa4: Either, f: (A1, A2, A3, A4) => R): Either; static map5( fa1: Either, fa2: Either, fa3: Either, fa4: Either, fa5: Either, f: (A1, A2, A3, A4, A5) => R): Either; static map6( fa1: Either, fa2: Either, fa3: Either, fa4: Either, fa5: Either, fa6: Either, f: (A1, A2, A3, A4, A5, A6) => R): Either; static tailRecM(a: A, f: (a: A) => Either>): Either; } declare export class TLeft<+L> extends Either { +value: L; } declare export class TRight<+R> extends Either { +value: R; } declare export function Left(value: L): TLeft; declare export function Right(value: R): TRight; export type EitherURI = (x: [U, L, A]) => Either; export type EitherK = HK2; export type EitherTypes = Setoid> & Monad; declare export var EitherModule: EitherTypes; declare export class Option<+A> { +value: void | A; get(): A; getOrElse(fallback: AA): A | AA; getOrElseL(thunk: () => AA): A | AA; orElse(fallback: Option): Option; orElseL(thunk: () => Option): Option; orNull(): A | null; orUndefined(): A | void; chain(f: (a: A) => Option): Option; contains(elem: A): boolean; equals(that: Option): boolean; exists(p: (a: A) => boolean): boolean; filter(p: (a: A) => boolean): Option; flatMap(f: (a: A) => Option): Option; fold(fallback: () => B, f: (a: A) => B): B; forAll(p: (a: A) => boolean): boolean; forEach(cb: (a: A) => void): void; hashCode(): number; isEmpty(): boolean; map(f: (a: A) => B): Option; nonEmpty(): boolean; // Implements Constructor static +_Class: Option; static empty(): Option; static none(): Option; static of(value: ?A): Option; static pure(value: A): Option; static some(value: A): Option; static map2( fa1: Option, fa2: Option, f: (A1, A2) => R): Option; static map3( fa1: Option, fa2: Option, fa3: Option, f: (A1, A2, A3) => R): Option; static map4( fa1: Option, fa2: Option, fa3: Option, fa4: Option, f: (A1, A2, A3, A4) => R): Option; static map5( fa1: Option, fa2: Option, fa3: Option, fa4: Option, fa5: Option, f: (A1, A2, A3, A4, A5) => R): Option; static map6( fa1: Option, fa2: Option, fa3: Option, fa4: Option, fa5: Option, fa6: Option, f: (A1, A2, A3, A4, A5, A6) => R): Option; static tailRecM(a: A, f: (a: A) => Option>): Option; } declare export class TSome extends Option { +value: A; } declare export class TNone extends Option { +value: void; } declare export function Some(value: A): TSome; declare export var None: TNone; export type OptionURI = (x: [U, L, A]) => Option; export type OptionK = HK; export type OptionTypes = Setoid> & Monad; declare export var OptionModule: OptionTypes; declare export class Try<+A> { +value: Throwable | A; get(): A; getOrElse(fallback: AA): A | AA; getOrElseL(thunk: () => AA): A | AA; orElse(fallback: Try): Try; orElseL(thunk: () => Try): Try; orNull(): A | null; orUndefined(): A | void; isSuccess(): boolean; isFailure(): boolean; failed(): Try; fold(failure: (error: Throwable) => R, success: (a: A) => R): R; filter(p: (a: A) => boolean): Try; flatMap(f: (a: A) => Try): Try; chain(f: (a: A) => Try): Try; map(f: (a: A) => B): Try; forEach(cb: (a: A) => void): void; recover(f: (error: Throwable) => AA): Try; recoverWith(f: (error: Throwable) => Try): Try; toOption(): Option; toEither(): Either; equals(that: Try): boolean; hashCode(): number; // Implements Constructor static +_Class: Try; static of(thunk: () => A): Try; static pure(value: A): Try; static unit(): Try; static success(value: A): Try; static failure(e: Throwable): Try; static raise(e: Throwable): Try; static map2( fa1: Try, fa2: Try, f: (A1, A2) => R): Try; static map3( fa1: Try, fa2: Try, fa3: Try, f: (A1, A2, A3) => R): Try; static map4( fa1: Try, fa2: Try, fa3: Try, fa4: Try, f: (A1, A2, A3, A4) => R): Try; static map5( fa1: Try, fa2: Try, fa3: Try, fa4: Try, fa5: Try, f: (A1, A2, A3, A4, A5) => R): Try; static map6( fa1: Try, fa2: Try, fa3: Try, fa4: Try, fa5: Try, fa6: Try, f: (A1, A2, A3, A4, A5, A6) => R): Try; static tailRecM(a: A, f: (a: A) => Try>): Try; } declare export class TSuccess extends Try { +value: A; } declare export class TFailure extends Try { +value: void; } declare export function Success(value: A): TSuccess; declare export function Failure(e: Throwable): TFailure; export type TryURI = (x: [U, L, A]) => Try; export type TryK = HK; export type TryTypes = Setoid> & Monad; declare export var TryModule: TryTypes;