Skip to content

Instantly share code, notes, and snippets.

@danslapman
Created December 7, 2016 19:08
Show Gist options
  • Save danslapman/fb460ff71c28810b10a9b700e3d408cd to your computer and use it in GitHub Desktop.
Save danslapman/fb460ff71c28810b10a9b700e3d408cd to your computer and use it in GitHub Desktop.
Selectors
val book =
('author ->> "Benjamin Pierce") ::
('title ->> "Types and Programming Languages") ::
('id ->> 262162091) ::
('price ->> 44.11d) ::
HNil
def readBook[B <: HList](book:B)(implicit
author: Selector.Aux[B, Witness.`'author`.T, String],
title: Selector.Aux[B, Witness.`'title`.T, String],
price: Selector.Aux[B, Witness.`'price`.T, Double]
): Unit = {
println(s"${author(book)}: ${title(book)}, ${price(book)}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment