Skip to content

Instantly share code, notes, and snippets.

@dkowis
Created November 24, 2014 16:17
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 dkowis/c3a603537d101c04b779 to your computer and use it in GitHub Desktop.
Save dkowis/c3a603537d101c04b779 to your computer and use it in GitHub Desktop.
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