-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added RepresentableK instances with hand implementation without macros.
- Loading branch information
Showing
5 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
17 changes: 16 additions & 1 deletion
17
modules/kernel/src/main/scala-3/tofu/concurrent/AtomInstances.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,3 +1,18 @@ | ||
package tofu.concurrent | ||
|
||
trait AtomInstances | ||
import cats.~> | ||
import tofu.higherKind.{RepresentableK, RepK} | ||
|
||
trait AtomInstances { | ||
// TODO: use higherKind.derived macro when it is ready for scala 3 | ||
given representableKInstance[A]: RepresentableK[({ type L[x[_]] = Atom[x, A] })#L] = | ||
new RepresentableK[({ type L[x[_]] = Atom[x, A] })#L] { | ||
def tabulate[F[_]](hom: RepK[({ type L[x[_]] = Atom[x, A] })#L, _] ~> F): Atom[F, A] = new Atom[F, A] { | ||
def get: F[A] = hom(RepK[({ type L[x[_]] = Atom[x, A] })#L](_.get)) | ||
def set(a: A): F[Unit] = hom(RepK[({ type L[x[_]] = Atom[x, A] })#L](_.set(a))) | ||
def getAndSet(a: A): F[A] = hom(RepK[({ type L[x[_]] = Atom[x, A] })#L](_.getAndSet(a))) | ||
def update(f: A => A): F[Unit] = hom(RepK[({ type L[x[_]] = Atom[x, A] })#L](_.update(f))) | ||
def modify[B](f: A => (A, B)): F[B] = hom(RepK[({ type L[x[_]] = Atom[x, A] })#L](_.modify(f))) | ||
} | ||
} | ||
} |
16 changes: 15 additions & 1 deletion
16
modules/kernel/src/main/scala-3/tofu/concurrent/QVarInstances.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,3 +1,17 @@ | ||
package tofu.concurrent | ||
|
||
trait QVarInstances {} | ||
import cats.~> | ||
import tofu.higherKind.{RepresentableK, RepK} | ||
|
||
trait QVarInstances { | ||
// TODO: use higherKind.derived macro when it is ready for scala 3 | ||
given representableK[A]: RepresentableK[({ type L[x[_]] = QVar[x, A] })#L] = | ||
new RepresentableK[({ type L[x[_]] = QVar[x, A] })#L] { | ||
def tabulate[F[_]](hom: RepK[({ type L[x[_]] = QVar[x, A] })#L, _] ~> F): QVar[F, A] = new QVar[F, A] { | ||
def isEmpty: F[Boolean] = hom(RepK[({ type L[x[_]] = QVar[x, A] })#L](_.isEmpty)) | ||
def put(a: A): F[Unit] = hom(RepK[({ type L[x[_]] = QVar[x, A] })#L](_.put(a))) | ||
def take: F[A] = hom(RepK[({ type L[x[_]] = QVar[x, A] })#L](_.take)) | ||
def read: F[A] = hom(RepK[({ type L[x[_]] = QVar[x, A] })#L](_.read)) | ||
} | ||
} | ||
} |
13 changes: 12 additions & 1 deletion
13
modules/kernel/src/main/scala-3/tofu/generate/GenUUIDInstances.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,3 +1,14 @@ | ||
package tofu.generate | ||
|
||
trait GenUUIDInstances {} | ||
import cats.~> | ||
import tofu.higherKind.{RepresentableK, RepK} | ||
import java.util.UUID | ||
|
||
trait GenUUIDInstances { | ||
// TODO: use higherKind.derived macro when it is ready for scala 3 | ||
given genUUIDRepresentableK: RepresentableK[GenUUID] = new RepresentableK[GenUUID] { | ||
def tabulate[F[_]](hom: RepK[GenUUID, _] ~> F): GenUUID[F] = new GenUUID[F] { | ||
def randomUUID: F[UUID] = hom(RepK[GenUUID](_.randomUUID)) | ||
} | ||
} | ||
} |
14 changes: 13 additions & 1 deletion
14
modules/kernel/src/main/scala-3/tofu/generate/GetRandomInstances.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,3 +1,15 @@ | ||
package tofu.generate | ||
|
||
trait GetRandomInstances {} | ||
import cats.~> | ||
import tofu.higherKind.{RepresentableK, RepK} | ||
|
||
trait GetRandomInstances { | ||
// TODO: use higherKind.derived macro when it is ready for scala 3 | ||
given genRandomRepresentableK: RepresentableK[GenRandom] = new RepresentableK[GenRandom] { | ||
def tabulate[F[_]](hom: RepK[GenRandom, _] ~> F): GenRandom[F] = new GenRandom[F] { | ||
def nextLong: F[Long] = hom(RepK[GenRandom](_.nextLong)) | ||
def nextInt(n: Int): F[Int] = hom(RepK[GenRandom](_.nextInt(n))) | ||
} | ||
} | ||
|
||
} |