# What is name of type " Function->Value->Bool = if (Bool) Function (Value) " in Category theory?

I am very new to functional programming so sorry if the question is stupid.

Having this function

const noname = func => val => bool => bool? func(val) : val


And following situation

// if event.target has css class 'draggable-box' , add drag listener to it, using event
compose(
elem_has_css_class('draggable-box'),
prop('target'),
)(event)


In Category theory, what is the correct name for the noname function? Is there such a type?

I don't believe that there is a standard category theory name for this, because of the Boolean argument. So what this function means would depend on how that is constructed.

In what follows, I'm going to change the argument order by putting that Boolean first.

If you encode the Boolean using Church encoding, the function would look like this in lambda calculus:

$$\lambda b. \lambda f. \lambda x. b\,(f\,x)\,x$$

This doesn't look especially standard to me. In Haskell, the function is called applyWhen.

Interpreting the Boolean as a subobject classifier in an elementary topos is left as an exercise.

Maybe currying is the syntax you refer, and passing arguments as functions:

const sum = (a, b, c) => a + b + c;
const partial = a => b => c => sum(a, b, c);

console.log(partial(1)(2)(3));          // 6

• thanks , but i know currying .it's already in use . all the functions in my code example are curried . Mar 12, 2021 at 2:36
• The code OP gives has almost nothing to do with currying other than it's an implementation detail. The question is how is this type of function called and it appears to be a combinator - a type of higher order function that is generic but works for specific purpose. Some have well known names, like the join combinator: f => x => f(x)(x) or flip combinator: f => x => y => f(y)(x). Currying is more of an implementation detail. flip can also be defined as f => (x, y) => f(y, x) or f => (...args) => f(args.reverse()).
– VLAZ
Mar 15, 2021 at 9:14