Skip to content

Instantly share code, notes, and snippets.

@alexlee85
Created November 17, 2014 04:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexlee85/352b61386abc501b2334 to your computer and use it in GitHub Desktop.
Save alexlee85/352b61386abc501b2334 to your computer and use it in GitHub Desktop.
Scala Slick dynamic filter
implicit class QueryHelper[T, E](query: Query[T, E, Seq]) {
def optionFilter[X, R: CanBeQueryCondition](name: Option[X])(f: (T, X) => R) =
name.map(v => query.withFilter(f(_, v))).getOrElse(query)
}
query.optionFilter(name)(_.name === _)
.optionFilter(email)(_.email === _).list
@gandalftheFFFFFF
Copy link

Hi! I was searching for a solution of sharing a join query, and this gist really helped me! Very short and concise, but really useful. Just wanted to say thank you for sharing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment