Skip to content

Instantly share code, notes, and snippets.

@NightRa
Forked from nuttycom/gist:6690987
Last active August 29, 2015 13:56

Revisions

  1. NightRa revised this gist Feb 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.scala
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ trait Functor[M[_]] {
    def fmap[A, B](fa: M[A])(f: A => B): M[B]
    }

    implicit class EitherRightFunctor[L] extends Functor[({ type l[a] = Either[L, a] })#l] {
    implicit def EitherRightFunctor[L,a] = new Functor[Either[L, a]] {
    def fmap[A, B](fa: Either[L, A])(f: A => B): Either[L, B] =
    fa match {
    case Right(a) => Right(f(a))
  2. @nuttycom nuttycom revised this gist Sep 24, 2013. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gistfile1.scala
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ implicit class EitherRightFunctor extends Functor { self =>
    def fmap[A0, B0](fa: M { type A = self.L ; type B = A0 })(f: A0 => B0): Either { type A = self.L ; type B = B0 } =
    fa match {
    case Right(a) => Right(f(a))
    case Left(a0) => Left(a0)
    case Left(l) => Left(l)
    }
    }

    @@ -20,11 +20,11 @@ trait Functor[M[_]] {
    def fmap[A, B](fa: M[A])(f: A => B): M[B]
    }

    implicit class EitherRightFunctor[A0] extends Functor[({ type l[a] = Either[A0, a] })#l] {
    def fmap[A, B](fa: Either[A0, A])(f: A => B): Either[A0, B] =
    implicit class EitherRightFunctor[L] extends Functor[({ type l[a] = Either[L, a] })#l] {
    def fmap[A, B](fa: Either[L, A])(f: A => B): Either[L, B] =
    fa match {
    case Right(a) => Right(f(a))
    case Left(a0) => Left(a0)
    case Left(l) => Left(l)
    }
    }

  3. @nuttycom nuttycom revised this gist Sep 24, 2013. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion gistfile1.scala
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,21 @@ implicit class EitherRightFunctor extends Functor { self =>
    def fmap[A0, B0](fa: M { type A = self.L ; type B = A0 })(f: A0 => B0): Either { type A = self.L ; type B = B0 } =
    fa match {
    case Right(a) => Right(f(a))
    case left => left
    case Left(a0) => Left(a0)
    }
    }

    // current Scala

    trait Functor[M[_]] {
    def fmap[A, B](fa: M[A])(f: A => B): M[B]
    }

    implicit class EitherRightFunctor[A0] extends Functor[({ type l[a] = Either[A0, a] })#l] {
    def fmap[A, B](fa: Either[A0, A])(f: A => B): Either[A0, B] =
    fa match {
    case Right(a) => Right(f(a))
    case Left(a0) => Left(a0)
    }
    }

  4. @nuttycom nuttycom created this gist Sep 24, 2013.
    16 changes: 16 additions & 0 deletions gistfile1.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    trait Functor {
    type M <: { type T }
    def fmap[A, B](fa: M { type T = A })(f: A => B): M { type T = B }
    }

    implicit class EitherRightFunctor extends Functor { self =>
    type L
    type M = Either { type A = self.L ; type T = B } //doesn't this specify a subtype of Either, rather than Either itself?

    def fmap[A0, B0](fa: M { type A = self.L ; type B = A0 })(f: A0 => B0): Either { type A = self.L ; type B = B0 } =
    fa match {
    case Right(a) => Right(f(a))
    case left => left
    }
    }