UNPKG

@dillonkearns/elm-graphql

Version:

<img src="https://cdn.jsdelivr.net/gh/martimatix/logo-graphqelm/logo.svg" alt="dillonearns/elm-graphql logo" width="40%" align="right">

19 lines (15 loc) 448 B
// @flow import type { Chain } from './Chain' import type { Either } from './Either' import { HKT } from './HKT' import * as either from './Either' export interface ChainRec<M> extends Chain<M> { chainRec<A, B>(f: (a: A) => HKT<M, Either<A, B>>, a: A): HKT<M, B>; } export function tailRec<A, B>(f: (a: A) => Either<A, B>, a: A): B { let v = f(a) while (either.isLeft(v)) { v = f(either.fromLeft(v)) } return either.fromRight(v) }