Step overview

A slightly nicer way to conceptualize tail-rec. This is really just Either, but contains helpers with friendly names

Added in v1.0.0


Table of contents


Constructors

done

Constructs a Done or Right value which instructs ChainRec to stop looping

Signature

export declare const done: <A, E = never>(a: A) => Step<E, A>

Added in v1.0.0

loop

Constructs a Loop or Left value which instructs ChainRec to keep looping

Signature

export declare const loop: <E, A = never>(e: E) => Step<E, A>

Added in v1.0.0

loopIf

Similar to E.fromPredicate, but the predicate is negated

Signature

export declare const loopIf: <Iterant>(
  shouldLoop: (a: Iterant) => boolean,
  iterate: (a: Iterant) => Iterant
) => (a: Iterant) => Step<Iterant, Iterant>

Added in v1.0.0

loopUnless

Alias for stopIf

Signature

export declare const loopUnless: <Iterant>(
  shouldStop: (a: Iterant) => boolean,
  iterate: (a: Iterant) => Iterant
) => (a: Iterant) => Step<Iterant, Iterant>

Added in v1.0.0

stopIf

Similar to E.fromPredicate

Signature

export declare const stopIf: <Iterant>(
  shouldStop: (a: Iterant) => boolean,
  iterate: (a: Iterant) => Iterant
) => (a: Iterant) => Step<Iterant, Iterant>

Added in v1.0.0

stopUnless

Alias for loopIf

Signature

export declare const stopUnless: <Iterant>(
  shouldLoop: (a: Iterant) => boolean,
  iterate: (a: Iterant) => Iterant
) => (a: Iterant) => Step<Iterant, Iterant>

Added in v1.0.0

Instance Methods

mapBoth

Same as E.bimap

Signature

export declare const mapBoth: <E, F, A, B>(
  mapIterant: (e: E) => F,
  mapResult: (a: A) => B
) => (step: Step<E, A>) => Step<F, B>

Added in v1.1.0

mapIterant

Same as E.mapLeft

Signature

export declare const mapIterant: <E, F>(f: (e: E) => F) => <A>(step: Step<E, A>) => Step<F, A>

Added in v1.1.0

mapResult

Same as E.map

Signature

export declare const mapResult: <A, B>(f: (a: A) => B) => <E>(step: Step<E, A>) => Step<E, B>

Added in v1.1.0

Model

Done (interface)

A type which instructs ChainRec to stop looping

Signature

export interface Done<A> extends E.Right<A> {}

Added in v1.0.0

Loop (interface)

A type which instructs ChainRec to keep looping

Signature

export interface Loop<E> extends E.Left<E> {}

Added in v1.0.0

Step (type alias)

An alias for Either

Signature

export type Step<E, A> = Loop<E> | Done<A>

Added in v1.0.0