I started to wonder if one of forall and exists should be removed.
I think they should both stay. While one could be used to replace the other in terms of functionality, clarity of the code will sometimes suffer quite a bit.
4 Likes
How about add an indexed function,which return an Traversable[Int,T]? ,means return an index first of zipWithIndex?
You can emulate such indexed with zipWithIndex.map(_.swap)
zipWithIndex is actually intuitive. I think it’s sufficient for indexing purposes.
def iForeach(f: (A, Int) => Unit, count: Int = 0): Unit
def iMap[B](f: (A, Int) => B, count: Int = 0): Seq[B]
def iFlatMap[B](f: (A, Int) => Seq[B], count: Int = 0): Seq[B]
don’t like names but this is great idea. There is lot of places where .zipWithIndex kills performance.
i propose rather something like:
def mapWithIndex[E](f:(T,Int) => E):Seq[E]
def foreachWithIndex[E](f:(T,Int) => E):Seq[E]
//flatMap seams to be to specific?
2 Likes
I started to wonder if one of
forallandexistsshould be removed.
clarification:
seq.forall(pred(_)) == !seq.exists(!pred(_))
for any pred