-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from TinkoffCreditSystems/higher-kind
Add more representableK instances, widening for logs, syntax for embe…
- Loading branch information
Showing
25 changed files
with
122 additions
and
60 deletions.
There are no files selected for viewing
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
58 changes: 58 additions & 0 deletions
58
higherKindCore/src/main/scala/tofu/higherKind/Function2K.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package tofu.higherKind | ||
import cats.data.Tuple2K | ||
import cats.{FlatMap, ~>} | ||
import tofu.syntax.functionK.funK | ||
import tofu.syntax.monadic._ | ||
|
||
trait Function2K[F[_], G[_], H[_]] { | ||
def apply[A](fa: F[A], ga: G[A]): H[A] | ||
|
||
def tupled: Tuple2K[F, G, *] ~> H = funK(t2k => apply(t2k.first, t2k.second)) | ||
} | ||
|
||
object Function2K { | ||
private[this] val representableAny = new Function2KRepresentable[Any, Any] | ||
|
||
implicit def representableK[F[_], G[_]]: RepresentableK[Function2K[F, G, *[_]]] = | ||
representableAny.asInstanceOf[RepresentableK[Function2K[F, G, *[_]]]] | ||
|
||
def apply[F[_], G[_], H[_]](maker: MakeFunctionK[F, G, H]): Function2K[F, G, H] = maker | ||
|
||
def untupled[F[_], G[_], H[_]](fk: Tuple2K[F, G, *] ~> H): Function2K[F, G, H] = apply((f, g) => fk(Tuple2K(f, g))) | ||
|
||
abstract class MakeFunctionK[F[_], G[_], H[_]] extends Function2K[F, G, H] { | ||
|
||
def applyArbitrary(f: F[Arbitrary], g: G[Arbitrary]): H[Arbitrary] | ||
|
||
def apply[A](fa: F[A], ga: G[A]): H[A] = | ||
applyArbitrary(fa.asInstanceOf[F[Arbitrary]], ga.asInstanceOf[G[Arbitrary]]).asInstanceOf[H[A]] | ||
} | ||
type Arbitrary | ||
|
||
private class Function2KRepresentable[X[_], Y[_]] extends RepresentableK[Function2K[X, Y, *[_]]] { | ||
final def tabulate[F[_]](hom: RepK[Function2K[X, Y, *[_]], *] ~> F): Function2K[X, Y, F] = | ||
Function2K((xa, ya) => hom(RepK[Function2K[X, Y, *[_]]](_.apply(xa, ya)))) | ||
|
||
//just optimized allocationwise redefinitions | ||
final override def mapK[F[_], G[_]](af: Function2K[X, Y, F])(fk: F ~> G): Function2K[X, Y, G] = | ||
Function2K((xa, ya) => fk(af(xa, ya))) | ||
|
||
final override def productK[F[_], G[_]]( | ||
af: Function2K[X, Y, F], | ||
ag: Function2K[X, Y, G] | ||
): Function2K[X, Y, Tuple2K[F, G, *]] = | ||
Function2K((xa, ya) => Tuple2K(af(xa, ya), ag(xa, ya))) | ||
|
||
final override def embed[F[_]: FlatMap](ft: F[Function2K[X, Y, F]]): Function2K[X, Y, F] = | ||
Function2K((xa, ya) => ft.flatMap(_(xa, ya))) | ||
|
||
override def zipWith2K[F[_], G[_], H[_]](af: Function2K[X, Y, F], ag: Function2K[X, Y, G])( | ||
f2: Function2K[F, G, H] | ||
): Function2K[X, Y, H] = | ||
Function2K((xa, ya) => f2(af(xa, ya), ag(xa, ya))) | ||
|
||
override def pureK[F[_]](p: Point[F]): Function2K[X, Y, F] = | ||
Function2K((_, _) => p.point) | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../src/main/scala/tofu/higherKind/Pre.scala → .../src/main/scala/tofu/higherKind/Pre.scala
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion
1
...rc/main/scala/tofu/syntax/functionK.scala → ...rc/main/scala/tofu/syntax/functionK.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
package tofu.syntax | ||
|
||
import cats.~> | ||
|
||
object functionK { | ||
|
File renamed without changes.
File renamed without changes.
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
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
1 change: 0 additions & 1 deletion
1
optics/macro/src/test/scala/tofu/optics/macros/GenContainsSpec.scala
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
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