// @flow import { HKT } from './HKT' import type { Functor } from './Functor' import type { Foldable } from './Foldable' import type { Applicative } from './Applicative' import { id } from './Identity' // `Traversable` represents data structures which can be _traversed_, // accumulating results and effects in some `Applicative` functor. // // - `traverse` runs an action for every element in a data structure, // and accumulates the results. // - `sequence` runs the actions _contained_ in a data structure, // and accumulates the results. export interface Traversable extends Functor, Foldable { traverse(applicative: Applicative, f: (a: A) => HKT, ta: HKT): HKT>; } export function sequence( applicative: Applicative, traversable: Traversable, tfa: HKT>): HKT> { return traversable.traverse(applicative, id, tfa) }