In a category with finite coproducts and products (with initial object $0$ and terminal object $1$) where the distributive law holds, I read it is possible to make a "test function" as follows:
$$A \xrightarrow{\langle 1_A,\varphi\rangle } A \times 2 \xrightarrow{i} A+A \xrightarrow{[f,g]} B.$$
Here $2 = 1+ 1,$ and $\varphi:A\rightarrow 2$ and $i$ the isomorphism that comes about from the distributive law, and $f,g:A \rightarrow B.$
If we call the above composition $h$ then I read that composing $h$ with an arrow $1 \xrightarrow{a} A$ will either yield $f(a)$ or $g(a),$ dependent on the value that $\varphi(a)$ takes in $2.$
I like the idea of being able to encode such "if .. then .." statements, but I want to be able to do it in a topos, dependent on the value of an arrow into the subobject classifier $\Omega.$
My question is, is it possible to make a similar "if .. then .." type setup in a topos, which depends on the truth value returned by composing with an arrow $A \xrightarrow{\psi} \Omega$ (rather than the above example, which depends on the value returned by composing with $A \xrightarrow{\varphi} 2$) ? Basically, I want to control whether I compose with $f$ or $g$ based on a truth value. I'm not sure what a sensible arena is to formulate the problem, but for the sake of saying something definite, lets say I want to define an arrow $h'$ from $A$ to $B$ that is such that for $1 \xrightarrow{a} A$ we have that $h'(a) = f(a)$ if $\psi (a)$ is true and $h'(a) = g(a)$ otherwise.
Like I say, I'm not sure if this is a sensible way to formulate what I am trying to do (or whether there is some other way using functional relations, or some other topos theory idea). I'm also not sure if the general idea makes sense. I would appreciate any feedback.
This is a good and well-posed question. The answer is no.
By the internal language of toposes, what you can do in a topos is the same as what you can do in constructive mathematics (by which I mean mathematics based on intuitionistic logic). Hence we can analyze the situation in a simpler language, the usual naive element-based language of mathematics in the topos $\mathrm{Set}$.
We can also simplify and restrict to the case $A = \mathbf{1}$ (the singleton set).
So we are given a truth value $\varphi \in \Omega$ and two candidate values $f \in B$ and $g \in B$. We want an element of $B$ which would deserve the name $\mathsf{if}\ \varphi\ \mathsf{then}\ f\ \mathsf{else}\ g$.
In classical logic, $\varphi$ would either be true or false and the problem would be trivial.
In intuitionistic logic, the best we can do is write down the set $K = \{ x \in B \,|\, (\varphi \wedge x = f) \vee (\neg\varphi \wedge x = g) \} \subseteq B$. This set is a subterminal (in the sense that any two elements are equal). If $\varphi$, then $K = \{ f \}$; if $\neg\varphi$, then $K = \{ g \}$.
In general, this is the best you can do. In case that $B$ is flabby, you can improve on the situation, but only by a little: In this case there will be an element $x \in B$ (depending only on $\varphi$, $f$ and $g$) such that, if $\varphi$ then $x = f$, and if $\neg\varphi$ then $x = g$. However, this element $x$ will not be uniquely determined.