Skip to content

Instantly share code, notes, and snippets.

@OlegYch
Last active March 21, 2019 21:05
Show Gist options
  • Save OlegYch/9972bcd6679e515e5c0588684b766847 to your computer and use it in GitHub Desktop.
Save OlegYch/9972bcd6679e515e5c0588684b766847 to your computer and use it in GitHub Desktop.
object qwe extends App {
def str = {
def find[A](s: Stream[A])(p: A => Boolean): Option[A] = {
s.headOption match {
case Some(x) if p(x) => Some(x)
case None => None
case _ => find(s.tail)(p)
}
}
// Stream.iterate(1)(_ + 1).find(str => false).get
find(Stream.iterate(1)(_ + 1))(_ => false)
}
str
}
object qwe extends App {
def str = {
def find[A](s: Stream[A])(p: A => Boolean): Option[A] = {
var these = s
while (!these.isEmpty) {
if (p(these.head)) return Some(these.head)
these = these.tail
}
None
}
// Stream.iterate(1)(_ + 1).find(str => false).get
find(Stream.iterate(1)(_ + 1))(_ => false)
}
str
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment