/*! * Copyright (c) 2017 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 { Constructor } from "./kinds" import { HK, Equiv } from "./kinds" import { Functor, FunctorLaws } from "./functor" import { Either } from "funfix-core" export interface Apply extends Functor { ap(fa: HK, ff: HK B>): HK; map2(fa: HK, fb: HK, f: (a: A, b: B) => Z): HK; product(fa: HK, fb: HK): HK; // Implements TypeClass static +_funTypeId: string; static +_funSupertypeIds: string[]; static +_funErasure: Apply; } export interface ApplyLaws extends FunctorLaws { +F: Apply; applyComposition(fa: HK, fab: HK B>, fbc: HK C>): Equiv>; applyProductConsistency(fa: HK, f: HK B>): Equiv>; applyMap2Consistency(fa: HK, f: HK B>): Equiv>; } declare export function applyOf(c: Constructor): Apply; declare export function applyLawsOf(instance: Apply): ApplyLaws; export interface Applicative extends Apply { pure(a: A): HK; unit(): HK; // Implements TypeClass static +_funTypeId: string; static +_funSupertypeIds: string[]; static +_funErasure: Applicative; } export interface ApplicativeLaws extends ApplyLaws { +F: Applicative; applicativeIdentity(fa: HK): Equiv>; applicativeHomomorphism(a: A, f: (a: A) => B): Equiv>; applicativeInterchange(a: A, ff: HK B>): Equiv>; applicativeMap(fa: HK, f: (a: A) => B): Equiv>; applicativeComposition(fa: HK, fab: HK B>, fbc: HK C>): Equiv>; applicativeUnit(a: A): Equiv>; } declare export function applicativeOf(c: Constructor): Applicative; declare export function applicativeLawsOf(instance: Applicative): ApplicativeLaws; export interface ApplicativeError extends Applicative { raise(e: E): HK; recoverWith(fa: HK, f: (e: E) => HK): HK; recover(fa: HK, f: (e: E) => A): HK; attempt(fa: HK): HK>; // Implements TypeClass static +_funTypeId: string; static +_funSupertypeIds: string[]; static +_funErasure: ApplicativeError; } export interface ApplicativeErrorLaws extends ApplicativeLaws { +F: ApplicativeError; applicativeErrorRecoverWith(e: E, f: (e: E) => HK): Equiv>; applicativeErrorRecover(e: E, f: (e: E) => A): Equiv>; recoverWithPure(a: A, f: (e: E) => HK): Equiv>; recoverPure(a: A, f: (e: E) => A): Equiv>; raiseErrorAttempt(e: E): Equiv>>; pureAttempt(a: A): Equiv>>; } declare export function applicativeErrorOf(c: Constructor): ApplicativeError; declare export function applicativeErrorLawsOf(instance: ApplicativeError): ApplicativeErrorLaws;