Revisions
-
NightRa revised this gist
Feb 10, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal 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 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)) -
nuttycom revised this gist
Sep 24, 2013 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal 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(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[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(l) => Left(l) } }
-
nuttycom revised this gist
Sep 24, 2013 . 1 changed file with 15 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal 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(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) } }
-
nuttycom created this gist
Sep 24, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal 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 } }