Skip to content

Instantly share code, notes, and snippets.

@nrinaudo
Created March 10, 2016 15:54
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 nrinaudo/7e9369427bc2c5abc5f7 to your computer and use it in GitHub Desktop.
Save nrinaudo/7e9369427bc2c5abc5f7 to your computer and use it in GitHub Desktop.
package foo
trait Decoder[E, D] {
def decode(e: E): D
}
package object foo {
type StringDecoder[A] = Decoder[String, A]
}
scala> import foo._
import foo._
scala> implicit val test: StringDecoder[Float] = StringDecoder(_.toFloat)
test: foo.StringDecoder[Float] = foo.StringDecoder$$anon$1@40a4337a
scala> StringDecoder.foobar
<console>:15: error: value foobar is not a member of object foo.StringDecoder
StringDecoder.foobar
package foo
object StringDecoder {
def apply[A](f: String => A): StringDecoder[A] = new StringDecoder[A] { override def decode(s: String) = f(s) }
def apply[A](implicit da: StringDecoder[A]): StringDecoder[A] = da
def foobar: Unit = println("foobar")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment