With the issue of possibly empty sets $A, B$, you might want to read up a bit on the existence of the Empty function.
In mathematics, an empty function is a function whose domain is the empty set. For each set A, there is exactly one such empty function
$$f_A: \varnothing \rightarrow A.$$
The graph of an empty function is a subset of the Cartesian product ∅ × A. Since the product is empty the only such subset is the empty set ∅. The empty subset is a valid graph since for every x in the domain ∅ there is a unique y in the codomain A such that (x,y) ∈ ∅ × A. This statement is an example of a vacuous truth since there is no x in the domain.
For perhaps a better explanation than that provided by Wikipedia, read this earlier post: