Created
April 14, 2024 13:45
Revisions
-
sshark created this gist
Apr 14, 2024 .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,28 @@ //import cats.Applicative //import cats.implicits.* /* def sequence[A, F[_], G[_]](fga: F[G[A]])(using Traverse[F], Applicative[G]): G[F[A]] = traverse(fga)(identity) trait Traverse[F[_]]: def traverse[A, B, G[_]](fa: F[A])(f: A => G[B])(using Applicative[G]): G[F[B]] */ trait Functor[F[_]] { def map[A, B](fa: F[A])(f: A => B): F[B] } trait Applicative[F[_]] extends Functor[F] { override def map[A, B](fa: F[A])(f: A => B): F[B] = ??? def apply[A, B](fa: F[A])(ff: F[A => B]): F[B] = ??? def map2[A, B, C](fa: F[A])(fb: F[B])(f: (A, B) => C)(implicit ev: Functor[F]): F[C] = apply(fb)(ev.map(fa)(a => (b => f(a, b)))) } /* val foo: Either[Nothing, List[Int]] = List(Right(1), Right(2)).traverse(r => r.asInstanceOf[Either[Nothing, Int]]) println(foo) */