Skip to content

Instantly share code, notes, and snippets.

@kulikov
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kulikov/8951585 to your computer and use it in GitHub Desktop.
Save kulikov/8951585 to your computer and use it in GitHub Desktop.
l = ["1", "32", "hello", "3", "my 43"]
return [int(_) for _ in filter(lambda _: _.isdigit(), l)]
val l = List("1", "32", "hello", "3", "my 43")
l flatMap (i => Try(i.toInt).toOption)
// или
l filter (_ forall Character.isDigit) map (_.toInt)
// или
l collect { case i if i forall Character.isDigit => i.toInt }
// или
for (i <- l if i forall Character.isDigit) yield i.toInt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment