Carl Sagan said this quote

What functions do dreams serve today? One view, published in a reputable scientific paper, holds that the function of dreams is to wake us up a little, every now and then, to see if anyone is about to eat us. But dreams occupy such a relatively small part of normal sleep that this explanation does not seem very compelling. Moreover, as we have seen, the evidence points just the other way: today it is the mammalian predators, not the mammalian prey, who characteristically have dream-filled sleep.