Skip to content

Instantly share code, notes, and snippets.

@andyscott
Last active January 13, 2016 00:17
Show Gist options
  • Save andyscott/09471d62665647781186 to your computer and use it in GitHub Desktop.
Save andyscott/09471d62665647781186 to your computer and use it in GitHub Desktop.
val cl = // a valid ClassLoader
val classNames: List[String] =
classOf[String].getName :: "$$$$" :: List.getClass.getName :: Nil
type Acc = (List[Throwable], List[Class[_]])
val res = classNames.foldLeft((Nil, Nil): Acc) { (acc, className) ⇒
Try(Class.forName(className, true, cl)) match {
case Success(c) ⇒ (acc._1, c :: acc._2)
case Failure(f) ⇒ (f :: acc._1, acc._2)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment