Last active
March 21, 2019 21:05
-
-
Save OlegYch/9972bcd6679e515e5c0588684b766847 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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