import { type FactoryWithRequiredInput } from '../getter/getter'; import { type MapFunction, type AsyncMapFunction } from './map'; import { type Maybe } from './maybe.type'; /** * A map function that derives a boolean decision from the input value. */ export type DecisionFunction = MapFunction; /** * Async variant of {@link DecisionFunction}. */ export type AsyncDecisionFunction = AsyncMapFunction>; /** * Factory that creates a {@link DecisionFunction} from a configuration value. */ export type DecisionFunctionFactory = FactoryWithRequiredInput, C>; /** * Creates a {@link DecisionFunction} that always returns the given boolean, regardless of input. * * Useful for providing a constant decision where a function is expected. * * @param decision - The constant boolean value to return. * @returns A decision function that always returns the given boolean. * * @dbxUtil * @dbxUtilCategory value * @dbxUtilKind factory * @dbxUtilTags decision, boolean, predicate, factory, constant * @dbxUtilRelated as-decision-function, invert-decision * * @example * ```ts * const alwaysTrue = decisionFunction(true); * alwaysTrue('anything'); // true * ``` * * @__NO_SIDE_EFFECTS__ */ export declare function decisionFunction(decision: boolean): DecisionFunction; /** * Inverts a decision function so it returns the opposite boolean value. * * When `invert` is false or omitted, the original function is returned unchanged. * * @param fn - the decision function to potentially invert * @param invert - whether to apply the inversion * * @example * ```ts * const isPositive: DecisionFunction = (x) => x > 0; * const isNotPositive = invertDecision(isPositive, true); * isNotPositive(5); // false * ``` */ export declare const invertDecision: >(fn: F, invert?: boolean) => F; /** * Normalizes a boolean value, a {@link DecisionFunction}, or undefined into a consistent {@link DecisionFunction}. * * If the input is undefined, falls back to a constant function returning `defaultIfUndefined`. * * @param valueOrFunction - Boolean constant, {@link DecisionFunction}, or undefined to use the default. * @param defaultIfUndefined - Fallback boolean when the input is nullish (defaults to true) * @returns A {@link DecisionFunction} derived from the input. * * @dbxUtil * @dbxUtilCategory value * @dbxUtilTags decision, normalize, boolean, default, coerce, predicate * @dbxUtilRelated decision-function, invert-decision * * @example * ```ts * const fn = asDecisionFunction(true); * fn('anything'); // true * * const fn2 = asDecisionFunction(undefined, false); * fn2('anything'); // false * ``` * * @__NO_SIDE_EFFECTS__ */ export declare function asDecisionFunction(valueOrFunction: Maybe>, defaultIfUndefined?: boolean): DecisionFunction; /** * Creates a {@link DecisionFunction} that checks strict equality against the given value. * * If the input is already a function, it is returned as-is, allowing callers to pass either a * concrete value or a custom decision function interchangeably. * * @param equalityValue - the value to compare against, or an existing decision function * @returns a decision function that checks strict equality with the given value * * @dbxUtil * @dbxUtilCategory value * @dbxUtilKind factory * @dbxUtilTags decision, equal, equality, factory, predicate, compare * @dbxUtilRelated decision-function, as-decision-function * * @example * ```ts * const isThree = isEqualToValueDecisionFunction(3); * isThree(3); // true * isThree(4); // false * ``` * * @__NO_SIDE_EFFECTS__ */ export declare function isEqualToValueDecisionFunction(equalityValue: T | DecisionFunction): T extends DecisionFunction ? T : DecisionFunction;