Infinitive clauses can be used to say what somebody found out or learnt at the end of a journey or task.
- I arrived home to find that the house had been burgled.
The idea of surprise or disappointment can be emphasised by using only.
- At last we got to Amy’s place, only to discover that she was away.
- He spent four years studying, only to learn that there were no jobs.