Any quantum operation (put aside reset and measurement) is a unitary operation and can be represented by a unitary matrix. Any unitary matrix can be built of quantum gates. So if you can encode $f(x)$ into a unitary matrix $U$ then there must be some series of quantum gates that yields $U$.
For example, let $n = 2$ be the number of qubits in the system, and $N = 4$ be the dimension of the Hilbert space that the quantum statevector of the system $|\psi\rangle$ resides in. A simple example is $U_1 = I \otimes Z $:
$U_1 = I \otimes Z = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & -1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{bmatrix}$
Let $f(x) = (-1)^x$. From the matrix of $U_1$ we can deduce that $U_1|x\rangle = (-1)^x|x\rangle = f(x)|x\rangle$, i.e we have encoded $f(x)$ into $U_1$.
We can create $U_1$ by applying the $Z$ gate to $q_0$ and do nothing to to $q_1$ so $U_1 = I \otimes Z $ (using little endian).
Another example would be $U_2 = I \otimes S$:
$U_2 = I \otimes S = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & i & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & i \end{bmatrix}$
Let $g(x) = i^{x (mod\ 2)}$. From the matrix of $U_2$ wen can deduce that $U_2|x\rangle = i^{x (mod\ 2)}|x\rangle = g(x)|x\rangle$, i.e we have encoded $g(x)$ into $U_2$.
We can create $U_2$ by applying the $S$ gate to $q_0$ and do nothing to to $q_1$ so $U_2 = I \otimes S $ (again little endian).
These are just 2 examples and there are more, but I guess (not sure though) that without using extra qubits we are pretty limited (Someone reading this correct me if I am wrong). If we add more qubits then we can do much more.