Skip to content

Instantly share code, notes, and snippets.

@jlandahl
Last active December 24, 2015 16:39
Show Gist options
  • Save jlandahl/6829934 to your computer and use it in GitHub Desktop.
Save jlandahl/6829934 to your computer and use it in GitHub Desktop.
Code reduction with Option
// candidate.mimeType and candidate.uri are both Options
candidate.mimeType.exists(_.equalsIgnoreCase(MimeTypes.PDF)) ||
candidate.uri.exists(_.getPath.toLowerCase.endsWith(FileExtensions.PDF))
val mimeTypeIsPdf = candidate.mimeType match {
case None => false
case Some(candidateMimeType) => candidateMimeType.equalsIgnoreCase(MimeTypes.PDF)
}
val urlHasPdfExtension = candidate.uri match {
case None => true
LowerCase().endsWith(FileExtensions.PDF)
}
mimeTypeIsPdf || urlHasPdfExtension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment