Scala Futures, Traverse and Side Effects

A month ago I was developing some virtual file system. My code had should read a config file, take a path and create all folders from that path. I had an asynchronous API for that purpose. My code was like this: val list = ( “/a”, “/a/b”, “/a/b/c”, “/a/b/c/d”, “/a/b/c/d/e” ) def isDirExists(str: String): Future[Boolean] = ??? def createDir(str: String): Future[Unit] = ??? Future.traverse(list){dir => isDirExists(dir).flatMap{ isExists => if (isExists) Future.successful(()) else createDir(dir) } } The list consists of paths of folders to be sequentially created. The folder creation starts from the most upper folder. If it doesn’t exist it