Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.util.Random
- /** my use case is:
- * I have a List[Item]; Item has a field id that is sometimes
- * not defined == "" ; I want to generate a complete map with id as a key
- * when defined or else a new key . */
- object UpdateKey extends App {
- case class Item(val id: String)
- val list = List(Item("bla"), Item(""))
- val listOfPairs = list.map {
- item =>
- {
- if (item.id != "")
- (item.id, item)
- else
- (Random.nextInt(), item)
- }
- }
- println(Map(listOfPairs: _*))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement