Is there a way to accomplish this without using the intermediate Buffer
?
case class Folder(id: Long, name: String)
case class FolderWithParentId(id: Long, name: String, parentId: Option[Long])
val folderList = mutable.Buffer[FolderWithParentId]()
List(Folder(1, "Top folder"), Folder(2, "Subfolder"))
.scanLeft(Option.empty[Long]) { case (parentFolderId, item) =>
folderList += FolderWithParentId(item.id, item.name, parentFolderId)
Some(item.id)
}
Thanks.
–
Andreas