Now studying Streams in Scala. Can anybody help me with function that will delete all n'th element from Stream.
[2,3,99,1,66,3,4];3 must return this: [2,3,1,66,4]
myStream.zipWithIndex //attach index to every element
.filter(x => (1 + x._2) % n > 0) //adjust index, remove every nth
.map(_._1) //remove index
Oops, almost forgot: filter
and map
can be combined.
myStream.zipWithIndex
.collect{case (e,x) if (1 + x) % n > 0 => e}