Skip to content

Instantly share code, notes, and snippets.

@mankyKitty
Last active July 1, 2016 04:07
Show Gist options
  • Save mankyKitty/ef2267fbf6ef9ab5538a06c59e9bfafe to your computer and use it in GitHub Desktop.
Save mankyKitty/ef2267fbf6ef9ab5538a06c59e9bfafe to your computer and use it in GitHub Desktop.
trait HasAString[A] {
def getTheString( a: A ): String
}
// This shenanigan has been pulled from Scalaz Functor definition
object HasAString {
@inline def apply[A](implicit a:HasAString[A]): HasAString[A] = a
}
object Zuh {
implicit val wutHasAString: HasAString[Wut] = new HasAString[Wut] {
def getTheString( a:Wut ): String =
a.totes.has.string
}
def zooms[A: HasAString]( xs: List[A] ): List[A] =
xs.foldr(List.empty[A])( (x,acc) => {
val s = HasAString[A].getTheString(x)
fugfug(x, s) :: acc
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment