The importance of sleep for healthy brain function is widely acknowledged. However, it remains unclear how the internal generation of dreams might facilitate cognitive processes. In this perspective, we review a computational approach inspired by artificial intelligence that proposes a framework for how dreams occurring during rapid-eye-movement (REM) sleep can contribute to learning and creativity. In this framework, REM dreams are characterized by an adversarial process that, against the dream reality, tells a discriminator network to classify the internally created sensory activity as real. Such an adversarial dreaming process is shown to facilitate the emergence of real-world semantic representations in higher cortical areas. We further discuss the potential contributions of adversarial dreaming beyond learning, such as balancing fantastic and realistic dream elements and facilitating the occurrence of creative insights. We characterize non-REM (NREM) dreams, where a single hippocampal memory is replayed at a time, as serving the complementary role of improving the robustness of cortical representations to environmental perturbations. We finally explain how subjects can become aware of the adversarial REM dreams, but less of the NREM dreams, and how content- and state-awareness in wake, dream, and lucid dreaming may appear.