0

I use EitherT[Future, Failure, Iterator[A]]. The regular scala can map with index as below.

myList.zipWithIndex.map { case (element, index) => 
   println(element, index) 
   s"${element}(${index})"
}

How to do map with index as the above for structure EitherT[Future, Failure, Iterator[A]] for Iterator[A] ?

Tom
  • 83
  • 8
  • you need to map on your initial structure first `etherT.map(_.zipWithIndex)` in order to transform it to `EitherT[Future, Failure, Iterator[(A,Int)]]` and then use `.map(it:Iterator[(A,Int)] => ...)` – Bogdan Vakulenko Jul 16 '19 at 07:39
  • or use `Nested(ethZipped:EitherT[Future, Failure, Iterator[(A,Int)]]).map{case (element,index) => ...}` – Bogdan Vakulenko Jul 16 '19 at 07:52
  • From structure EitherT[Future, Failure, Iterator[A]], what is the way to get Iterator[A] without using map or traverse ? – Tom Jul 16 '19 at 09:46
  • To extract Iterator value from the structure you need to wait until Future is completed. – Bogdan Vakulenko Jul 16 '19 at 11:08
  • When you “access” Iterator using map or traverse you dont actually access it. You just provide function to be executed when iterator become available. – Bogdan Vakulenko Jul 16 '19 at 11:10
  • @BogdanVakulenko Why two separate `.map` steps? What prevents you from just using a single `.map(_.zipWithIndex.map { case (elem, idx) => etc })`?. @OP: In general, it's unclear what you are asking. `EitherT[F, E, ?]` is a `Monad`, thus a `Functor`, thus it has `map`. Just replace `myList` by an underscore and feed this entire expression to the `map`, what's the problem? – Andrey Tyukin Jul 16 '19 at 12:08

0 Answers0