I would like to left join two list, without lost of the data. Example below:
// two lists
val b = List("John","Alice","Gregor","Mike") // base list
val l = List((List(1,2,3),"Mike"), (List(3,1,2), "Alice")) // list to left join
// sorted
val bs = b.sorted // List("Alice","Gregor","John","Mike")
val ls = l.sortBy(_._2) // List((List(3,1,2), "Alice"),(List(1,2,3),"Mike"))
// left join - expected result:
// Alice and Mike found in both lists, Gregor and John appear only in the base list
// List(("Alice",(List(3,1,2),"Alice"), ("Gregor",Nil), ("John",Nil), ("Mike",List("Alice","Gregor","John","Mike"))))
I found some methods, but they seem to be not proper for me:
- zip - simple 'copy/paste' two lists,
- flatMap - remove elements, which doesn't appear in both lists.
Thank you in advance.