/*! * 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 { Either } from "funfix-core" import { Apply, ApplyLaws, Applicative, ApplicativeLaws, ApplicativeError, ApplicativeErrorLaws } from "./applicative" export interface FlatMap extends Apply{ flatMap(fa: HK, f: (a: A) => HK): HK; tailRecM(a: A, f: (a: A) => HK>): HK; followedBy(fa: HK, fb: HK): HK; followedByL(fa: HK, fb: () => HK): HK; forEffect(fa: HK, fb: HK): HK; forEffectL(fa: HK, fb: () => HK): HK; // Implements TypeClass static +_funTypeId: string; static +_funSupertypeIds: string[]; static +_funErasure: FlatMap; } export interface FlatMapLaws extends ApplyLaws { +F: FlatMap; flatMapAssociativity(fa: HK, f: (a: A) => HK, g: (b: B) => HK): Equiv>; flatMapConsistentApply(fa: HK, fab: HK B>): Equiv>; followedByConsistency(fa: HK, fb: HK): Equiv>; followedByLConsistency(fa: HK, fb: HK): Equiv>; forEffectConsistency(fa: HK, fb: HK): Equiv>; forEffectLConsistency(fa: HK, fb: HK): Equiv>; tailRecMConsistentFlatMap(a: A, f: (a: A) => HK): Equiv>; } declare export function flatMapOf(c: Constructor): FlatMap; declare export function flatMapLawsOf(instance: FlatMap): FlatMapLaws; export interface Monad extends FlatMap, Applicative { // Implements TypeClass static +_funTypeId: string; static +_funSupertypeIds: string[]; static +_funErasure: Monad; } export interface MonadLaws extends ApplicativeLaws, FlatMapLaws { +F: Monad; monadLeftIdentity(a: A, f: (a: A) => HK): Equiv>; monadRightIdentity(fa: HK): Equiv>; mapFlatMapCoherence(fa: HK, f: (a: A) => B): Equiv>; tailRecMStackSafety(): Equiv>; } declare export function monadOf(c: Constructor): Monad; declare export function monadLawsOf(instance: Monad): MonadLaws; export interface MonadError extends ApplicativeError, Monad { // Implements TypeClass static +_funTypeId: string; static +_funSupertypeIds: string[]; static +_funErasure: MonadError; } export interface MonadErrorLaws extends ApplicativeErrorLaws, MonadLaws { +F: MonadError; monadErrorLeftZero(e: E, f: (a: A) => HK): Equiv>; } declare export function monadErrorOf(c: Constructor): MonadError; declare export function monadErrorLawsOf(instance: MonadError): MonadErrorLaws;