Optimal foraging and learning