Skip to content

Instantly share code, notes, and snippets.

@mpilquist
Created June 11, 2019 13:19
Show Gist options
  • Select an option

  • Save mpilquist/79c6a12313a53b44fcad8883765bc426 to your computer and use it in GitHub Desktop.

Select an option

Save mpilquist/79c6a12313a53b44fcad8883765bc426 to your computer and use it in GitHub Desktop.
package leopards {
trait Functor[F[_]] {
def (fa: F[A]) map[A, B](f: A => B): F[B]
def (fa: F[A]) void[A]: F[Unit] = fa.map(_ => ())
}
delegate for Functor[List] {
def (fa: List[A]) map[A, B](f: A => B): List[B] =
fa.map(f)
}
delegate [T] for Functor[[X] =>> T => X] {
def (fa: T => A) map[A, B](f: A => B): T => B =
fa.andThen(f)
}
}
package usage {
import delegate leopards._
val ex1 = List(1, 2, 3).void
}
/*
-- [E007] Type Mismatch Error: prio.scala:21:16 --------------------------------
21 | val ex1 = List(1, 2, 3).void
| ^^^^^^^^^^^^^
|Found: List[Int]
|Required: ?{ void: ? }
|Note that implicit extension methods cannot be applied because they are ambiguous;
|both object Functor_List_instance in package leopards and method Functor_Function_instance in package leopards provide an extension method `void` on List[Int]
one error found
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment