What is an idiomatic Scala way to “remove” one element from an immutable List?

I haven’t seen this possibility in the answers above, so:

scala> def remove(num: Int, list: List[Int]) = list diff List(num)
remove: (num: Int,list: List[Int])List[Int]

scala> remove(2,List(1,2,3,4,5))
res2: List[Int] = List(1, 3, 4, 5)

Edit:

scala> remove(2,List(2,2,2))
res0: List[Int] = List(2, 2)

Like a charm :-).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)