First, I supose we'd have to define a definite order in $\,P_n:=P(A_n)\,$ , and for this we could do something ressembling the cycles in the permutations group $\,S_n\,$ (if you still haven't studied this don't worry: you won't need it but perhaps it will help others to feel more comfortable with the following), so we can try the lexicographic order.
First, we agree to "order" the elements within each element in $\,P_n\,$ (i.e., within each subset of $\,A_n\,$) in ascending natural order, so that we'll write $\,\{3,5,6,9\}\,$ and not $\,\{5,9,3,6\}\,$ or $\,\{3,6,5,9\}\,$ , etc.
Take now $\,A,B\in P_n\,,\,A=\{i_1,...,i_r\}\,,\,B=\{j_1,...,j_s\}\,,\,\,i_k,j_m\in A_n\,,\,1\leq r,s,\leq n\,\,$ , and define
$$A\prec B\Longleftrightarrow \begin{cases}|A|<|B|\;\;,\text{ or}\\r=s\,\,\wedge\,\,\exists\, 1<k<r\,\,\;s.t.\;\,\,i_1=j_1\,,\,...,i_k=j_k\,,\,i_{k+1}<j_{k+1} \end{cases}$$
Thus, for example, $\,\{6,7,9\}\prec\{1,2,3,4,\}\,\,,\,\,\{4,7,9\}\prec\{4,7,11\} \,$ , etc.
With the above order we can ennumerate the elements of $\,P_n\,$ , beginning from zero to include the empty set:
$$0\to\emptyset\\1\to\{1\}\\...\\n\to\{n\}\\n+1\to\{1,2\}\\n+2\to\{1,3\}\\...\\n+n-1=2n-1\to\{1,n\}\\...$$
The resulting matching is not the nicest thing one could expect to meet in the street, but it is also not that terrible. Now you can define your function, perhaps first trying some easy examples when $\,n=3,4,5\,$...have fun!