functionbut
Functionbut is a theoretical construct in programming language theory and functional programming that formalizes conditional application of a function. It defines an operator, often denoted as but, that combines a function, a predicate, and a fallback, to produce a new function. The resulting function applies the primary function only when the predicate is satisfied; otherwise, it yields a fallback value or applies an alternate function.
Formal definition commonly uses a triple (f, p, k) where f: X -> Y, p: X -> bool, and
Intuition: functionbut separates the decision about whether to apply f from the actual computation, enabling concise
Example: let f(x) = x + 2, p(x) = x > 0, and k(x) = 0. Then functionbut(f, p, k)(x) returns
History and usage: The term and operator are not part of standard languages; prototypes have appeared in