Skip to content

breakIf

The breakIf() function tests a value with a predicate and breaks the current flow branch when the predicate returns true. If the predicate fails, the value is returned and the flow continues.

Interactive example

Syntax

typescript
function breakIf<
	GenericValue extends unknown
>(
	value: GenericValue,
	thePredicate: (value: GenericValue) => boolean
): Generator<Break<GenericValue>, GenericValue>

Parameters

  • value: The value to test.
  • thePredicate: Predicate used to decide whether the current branch must stop.

Return value

A generator that yields a break effect when the predicate returns true, otherwise returns the original value.

See also

  • exitIf - Exits the whole running flow instead of only breaking locally
  • run - Executes a flow and handles break effects

Released under the MIT license.