class FunctionIterator[X, R] extends AbstractIterator[Try[R]]
The FunctionIterator class wraps an existing iterator to apply a function f to its elements,
returning an iterator that yields Try[R], where R is the result type of the function application.
This class processes elements from a given iterator of type X and handles various scenarios such as:
- Validating inputs against a custom Joinable type class.
- Handling exceptions during function execution and input processing.
- Providing support for "multi-line" inputs that can be joined using the Joinable logic.
- X
The input type of the iterator. Must have an implicit type class
Joinablethat provides methods for validation, joining, and a zero value.- R
The result type produced by applying function
fto elements of typeX.
- Note
The
FunctionIteratormay use a mutable variableryinternally to store the result of the last element processed.
- Alphabetic
- By Inheritance
- FunctionIterator
- AbstractIterator
- Iterator
- IterableOnceOps
- IterableOnce
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new FunctionIterator(f: (X) => Try[R])(xs: Iterator[X])(implicit arg0: Joinable[X])
Creates a
FunctionIteratorthat wraps the input iterator and applies the given function to its elements.Creates a
FunctionIteratorthat wraps the input iterator and applies the given function to its elements. Usage example:implicit object StringJoinable extends Joinable[String] { def join(t1: String, t2: String): String = t1 + t2 val zero: String = "" def valid(t: String): Boolean = t.nonEmpty } val inputs = Iterator("abc", "123", "") val function: String => Try[Int] = str => Try(str.toInt) val functionIterator = new FunctionIterator(function)(inputs) while (functionIterator.hasNext) { println(functionIterator.next()) }
- f
A function from
XtoTry[R]that is applied to each element of the iterator.- xs
An
Iterator[X]containing the input elements to be processed. The class extendsAbstractIterator[Try[R]]and provides these key methods:
Type Members
- class GroupedIterator[B >: A] extends AbstractIterator[Seq[B]]
- Definition Classes
- Iterator
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ++[B >: Try[R]](xs: => IterableOnce[B]): Iterator[B]
- Definition Classes
- Iterator
- Annotations
- @inline()
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def addString(b: StringBuilder): b.type
- Definition Classes
- IterableOnceOps
- Annotations
- @inline()
- final def addString(b: StringBuilder, sep: String): b.type
- Definition Classes
- IterableOnceOps
- Annotations
- @inline()
- def addString(b: StringBuilder, start: String, sep: String, end: String): b.type
- Definition Classes
- IterableOnceOps
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def buffered: BufferedIterator[Try[R]]
- Definition Classes
- Iterator
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def collect[B](pf: PartialFunction[Try[R], B]): Iterator[B]
- Definition Classes
- Iterator → IterableOnceOps
- def collectFirst[B](pf: PartialFunction[Try[R], B]): Option[B]
- Definition Classes
- IterableOnceOps
- def concat[B >: Try[R]](xs: => IterableOnce[B]): Iterator[B]
- Definition Classes
- Iterator
- def contains(elem: Any): Boolean
- Definition Classes
- Iterator
- def copyToArray[B >: Try[R]](dest: Array[B], start: Int, n: Int): Int
- Definition Classes
- IterableOnceOps
- def copyToArray[B >: Try[R]](dest: Array[B], start: Int): Int
- Definition Classes
- IterableOnceOps
- Annotations
- @deprecatedOverriding()
- def copyToArray[B >: Try[R]](dest: Array[B]): Int
- Definition Classes
- IterableOnceOps
- Annotations
- @deprecatedOverriding()
- def corresponds[B](that: IterableOnce[B])(p: (Try[R], B) => Boolean): Boolean
- Definition Classes
- IterableOnceOps
- def count(p: (Try[R]) => Boolean): Int
- Definition Classes
- IterableOnceOps
- def distinct: Iterator[Try[R]]
- Definition Classes
- Iterator
- def distinctBy[B](f: (Try[R]) => B): Iterator[Try[R]]
- Definition Classes
- Iterator
- def drop(n: Int): Iterator[Try[R]]
- Definition Classes
- Iterator → IterableOnceOps
- def dropWhile(p: (Try[R]) => Boolean): Iterator[Try[R]]
- Definition Classes
- Iterator → IterableOnceOps
- def duplicate: (Iterator[Try[R]], Iterator[Try[R]])
- Definition Classes
- Iterator
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def exists(p: (Try[R]) => Boolean): Boolean
- Definition Classes
- IterableOnceOps
- def filter(p: (Try[R]) => Boolean): Iterator[Try[R]]
- Definition Classes
- Iterator → IterableOnceOps
- def filterNot(p: (Try[R]) => Boolean): Iterator[Try[R]]
- Definition Classes
- Iterator → IterableOnceOps
- def find(p: (Try[R]) => Boolean): Option[Try[R]]
- Definition Classes
- IterableOnceOps
- def flatMap[B](f: (Try[R]) => IterableOnce[B]): Iterator[B]
- Definition Classes
- Iterator → IterableOnceOps
- def flatten[B](implicit ev: (Try[R]) => IterableOnce[B]): Iterator[B]
- Definition Classes
- Iterator → IterableOnceOps
- def fold[A1 >: Try[R]](z: A1)(op: (A1, A1) => A1): A1
- Definition Classes
- IterableOnceOps
- def foldLeft[B](z: B)(op: (B, Try[R]) => B): B
- Definition Classes
- IterableOnceOps
- def foldRight[B](z: B)(op: (Try[R], B) => B): B
- Definition Classes
- IterableOnceOps
- def forall(p: (Try[R]) => Boolean): Boolean
- Definition Classes
- IterableOnceOps
- def foreach[U](f: (Try[R]) => U): Unit
- Definition Classes
- IterableOnceOps
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def grouped[B >: Try[R]](size: Int): GroupedIterator[B]
- Definition Classes
- Iterator
- def hasNext: Boolean
- Definition Classes
- FunctionIterator → Iterator
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def indexOf[B >: Try[R]](elem: B, from: Int): Int
- Definition Classes
- Iterator
- def indexOf[B >: Try[R]](elem: B): Int
- Definition Classes
- Iterator
- def indexWhere(p: (Try[R]) => Boolean, from: Int): Int
- Definition Classes
- Iterator
- def isEmpty: Boolean
- Definition Classes
- Iterator → IterableOnceOps
- Annotations
- @deprecatedOverriding()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isTraversableAgain: Boolean
- Definition Classes
- IterableOnceOps
- final def iterator: Iterator[Try[R]]
- Definition Classes
- Iterator → IterableOnce
- Annotations
- @inline()
- def knownSize: Int
- Definition Classes
- IterableOnce
- final def length: Int
- Definition Classes
- Iterator
- Annotations
- @inline()
- def map[B](f: (Try[R]) => B): Iterator[B]
- Definition Classes
- Iterator → IterableOnceOps
- def max[B >: Try[R]](implicit ord: Ordering[B]): Try[R]
- Definition Classes
- IterableOnceOps
- def maxBy[B](f: (Try[R]) => B)(implicit ord: Ordering[B]): Try[R]
- Definition Classes
- IterableOnceOps
- def maxByOption[B](f: (Try[R]) => B)(implicit ord: Ordering[B]): Option[Try[R]]
- Definition Classes
- IterableOnceOps
- def maxOption[B >: Try[R]](implicit ord: Ordering[B]): Option[Try[R]]
- Definition Classes
- IterableOnceOps
- def min[B >: Try[R]](implicit ord: Ordering[B]): Try[R]
- Definition Classes
- IterableOnceOps
- def minBy[B](f: (Try[R]) => B)(implicit ord: Ordering[B]): Try[R]
- Definition Classes
- IterableOnceOps
- def minByOption[B](f: (Try[R]) => B)(implicit ord: Ordering[B]): Option[Try[R]]
- Definition Classes
- IterableOnceOps
- def minOption[B >: Try[R]](implicit ord: Ordering[B]): Option[Try[R]]
- Definition Classes
- IterableOnceOps
- final def mkString: String
- Definition Classes
- IterableOnceOps
- Annotations
- @inline()
- final def mkString(sep: String): String
- Definition Classes
- IterableOnceOps
- Annotations
- @inline()
- final def mkString(start: String, sep: String, end: String): String
- Definition Classes
- IterableOnceOps
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def next(): Try[R]
- Definition Classes
- FunctionIterator → Iterator
- def nextOption(): Option[Try[R]]
- Definition Classes
- Iterator
- def nonEmpty: Boolean
- Definition Classes
- IterableOnceOps
- Annotations
- @deprecatedOverriding()
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def padTo[B >: Try[R]](len: Int, elem: B): Iterator[B]
- Definition Classes
- Iterator
- def partition(p: (Try[R]) => Boolean): (Iterator[Try[R]], Iterator[Try[R]])
- Definition Classes
- Iterator
- def patch[B >: Try[R]](from: Int, patchElems: Iterator[B], replaced: Int): Iterator[B]
- Definition Classes
- Iterator
- def product[B >: Try[R]](implicit num: Numeric[B]): B
- Definition Classes
- IterableOnceOps
- def reduce[B >: Try[R]](op: (B, B) => B): B
- Definition Classes
- IterableOnceOps
- def reduceLeft[B >: Try[R]](op: (B, Try[R]) => B): B
- Definition Classes
- IterableOnceOps
- def reduceLeftOption[B >: Try[R]](op: (B, Try[R]) => B): Option[B]
- Definition Classes
- IterableOnceOps
- def reduceOption[B >: Try[R]](op: (B, B) => B): Option[B]
- Definition Classes
- IterableOnceOps
- def reduceRight[B >: Try[R]](op: (Try[R], B) => B): B
- Definition Classes
- IterableOnceOps
- def reduceRightOption[B >: Try[R]](op: (Try[R], B) => B): Option[B]
- Definition Classes
- IterableOnceOps
- def reversed: Iterable[Try[R]]
- Attributes
- protected
- Definition Classes
- IterableOnceOps
- def sameElements[B >: Try[R]](that: IterableOnce[B]): Boolean
- Definition Classes
- Iterator
- def scanLeft[B](z: B)(op: (B, Try[R]) => B): Iterator[B]
- Definition Classes
- Iterator → IterableOnceOps
- def size: Int
- Definition Classes
- IterableOnceOps
- def slice(from: Int, until: Int): Iterator[Try[R]]
- Definition Classes
- Iterator → IterableOnceOps
- def sliceIterator(from: Int, until: Int): Iterator[Try[R]]
- Attributes
- protected
- Definition Classes
- Iterator
- def sliding[B >: Try[R]](size: Int, step: Int): GroupedIterator[B]
- Definition Classes
- Iterator
- def span(p: (Try[R]) => Boolean): (Iterator[Try[R]], Iterator[Try[R]])
- Definition Classes
- Iterator → IterableOnceOps
- def splitAt(n: Int): (Iterator[Try[R]], Iterator[Try[R]])
- Definition Classes
- IterableOnceOps
- def stepper[S <: Stepper[_]](implicit shape: StepperShape[Try[R], S]): S
- Definition Classes
- IterableOnce
- def sum[B >: Try[R]](implicit num: Numeric[B]): B
- Definition Classes
- IterableOnceOps
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def take(n: Int): Iterator[Try[R]]
- Definition Classes
- Iterator → IterableOnceOps
- def takeWhile(p: (Try[R]) => Boolean): Iterator[Try[R]]
- Definition Classes
- Iterator → IterableOnceOps
- def tapEach[U](f: (Try[R]) => U): Iterator[Try[R]]
- Definition Classes
- Iterator → IterableOnceOps
- def to[C1](factory: Factory[Try[R], C1]): C1
- Definition Classes
- IterableOnceOps
- def toArray[B >: Try[R]](implicit arg0: ClassTag[B]): Array[B]
- Definition Classes
- IterableOnceOps
- final def toBuffer[B >: Try[R]]: Buffer[B]
- Definition Classes
- IterableOnceOps
- Annotations
- @inline()
- def toIndexedSeq: IndexedSeq[Try[R]]
- Definition Classes
- IterableOnceOps
- def toList: List[Try[R]]
- Definition Classes
- IterableOnceOps
- def toMap[K, V](implicit ev: <:<[Try[R], (K, V)]): Map[K, V]
- Definition Classes
- IterableOnceOps
- def toSeq: Seq[Try[R]]
- Definition Classes
- IterableOnceOps
- def toSet[B >: Try[R]]: Set[B]
- Definition Classes
- IterableOnceOps
- def toString(): String
- Definition Classes
- Iterator → AnyRef → Any
- def toVector: Vector[Try[R]]
- Definition Classes
- IterableOnceOps
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def withFilter(p: (Try[R]) => Boolean): Iterator[Try[R]]
- Definition Classes
- Iterator
- def zip[B](that: IterableOnce[B]): Iterator[(Try[R], B)]
- Definition Classes
- Iterator
- def zipAll[A1 >: Try[R], B](that: IterableOnce[B], thisElem: A1, thatElem: B): Iterator[(A1, B)]
- Definition Classes
- Iterator
- def zipWithIndex: Iterator[(Try[R], Int)]
- Definition Classes
- Iterator → IterableOnceOps
Deprecated Value Members
- final def /:[B](z: B)(op: (B, Try[R]) => B): B
- Definition Classes
- IterableOnceOps
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.13.0) Use foldLeft instead of /:
- final def :\[B](z: B)(op: (Try[R], B) => B): B
- Definition Classes
- IterableOnceOps
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.13.0) Use foldRight instead of :\
- def aggregate[B](z: => B)(seqop: (B, Try[R]) => B, combop: (B, B) => B): B
- Definition Classes
- IterableOnceOps
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) For sequential collections, prefer
foldLeft(z)(seqop). For parallel collections, useParIterableLike#aggregate.
- final def copyToBuffer[B >: Try[R]](dest: Buffer[B]): Unit
- Definition Classes
- IterableOnceOps
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.13.0) Use
dest ++= collinstead
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
(Since version 9)
- final def hasDefiniteSize: Boolean
- Definition Classes
- Iterator → IterableOnceOps
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.13.0) hasDefiniteSize on Iterator is the same as isEmpty
- def scanRight[B](z: B)(op: (Try[R], B) => B): Iterator[B]
- Definition Classes
- Iterator
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Call scanRight on an Iterable instead.
- def seq: FunctionIterator.this.type
- Definition Classes
- Iterator
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Iterator.seq always returns the iterator itself
- final def toIterator: Iterator[Try[R]]
- Definition Classes
- IterableOnceOps
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.13.0) Use .iterator instead of .toIterator
- final def toStream: Stream[Try[R]]
- Definition Classes
- IterableOnceOps
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.13.0) Use .to(LazyList) instead of .toStream