Skip to content

Instantly share code, notes, and snippets.

@dkowis

dkowis/Sample.scala

Created Nov 24, 2014
Embed
What would you like to do?
def parseDelegationValues(delegationValues: Seq[String]): Seq[HttpDelegationHeaderBean] = {
// TODO: Performance concerns
delegationValues.map(parseDelegationHeader).filter {
case Success(_) =>
true
case Failure(e) =>
LOG.warn("Failed to parse a delegation header: " + e.getMessage)
false
}.map(_.get)
//Using flatmap to auto-extract
delegationValues.map(parseDelegationHeader).flatMap {
case Success(bean) => Some(bean)
case Failure(e) =>
LOG.warn("Failed to parse a delegation header: " + e.getMessage)
None
}
//Least amount of looping
delegationValues.flatMap { value =>
parseDelegationHeader(value) match {
case Success(bean) => Some(bean)
case Failure(e) =>
LOG.warn("Failed to parse a delegation header: " + e.getMessage)
None
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment