Created
March 10, 2016 15:54
-
-
Save nrinaudo/7e9369427bc2c5abc5f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package foo | |
trait Decoder[E, D] { | |
def decode(e: E): D | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package object foo { | |
type StringDecoder[A] = Decoder[String, A] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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