Finding the first stream of non-repeating elements in Scala (without recursion or side-effects)
This is a fold, not a scan. A scan produces something with the same number of elements, and change the elements. A fold produces something new.

def firstDistinct[T](s: Seq[T]) = s.foldLeft(Seq[T]() -&gt; false) {
  case (result @ (_, true), _)           =&gt; result
  case ((seq, _), el) if seq contains el =&gt; seq -&gt; true
  case ((seq, _), el)                    =&gt; (seq :+ el) -&gt; false
}._1