Skip to content

Commit

Permalink
syntax adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
szymon-rd committed Jan 5, 2024
1 parent 55da5b7 commit 7f0f5cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
13 changes: 1 addition & 12 deletions core/src/main/scala/com/virtuslab/lynx/syntax.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
package com.virtuslab.lynx

// temporary syntax from monadic-reflection
type require[A, M[_]] = CanReflect[M] ?=> A

type in[A, M[_]] = CanReflect[M] ?=> A

inline def reify[M[_]: Monadic]: ReifyBuilder[M] = ReifyBuilder()

case class ReifyBuilder[M[_]]()(using M: Monadic[M]) {
inline def in[R](prog: R in M) = M.reify[R] { prog }
inline def apply[R](prog: R in M) = M.reify[R] { prog }
}

extension [M[_], R](mr: M[R])
inline def reflect(using r: CanReflect[M]): R = r.reflect(mr)
10 changes: 5 additions & 5 deletions core/src/test/scala/com/virtuslab/lynx/data/StateTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ class StateTest extends munit.FunSuite {
test("userService") {
case class User(name: String)
trait UserService[Cap[_]] {
def addUser(name: String): Unit in Cap
def getUser(name: String): Option[User] in Cap
def addUser(name: String): Unit require Cap
def getUser(name: String): Option[User] require Cap
}

type Storage[A] = StateM[List[User], A]
case class StateUserService() extends UserService[Storage] {

override def addUser(name: String): Unit in Storage = {
override def addUser(name: String): Unit require Storage = {
println("Adding user: " + name)
val newUser = User(name)
State[List[User]].update(newUser :: _)
}

override def getUser(name: String): Option[User] in Storage =
override def getUser(name: String): Option[User] require Storage =
println("Getting user: " + name)
State[List[User]].get().find(_.name == name)
}

def program[F[_]](userService: UserService[F]): Option[User] in F = {
def program[F[_]](userService: UserService[F]): Option[User] require F = {
userService.addUser("John")
userService.addUser("Jane")
userService.getUser("John")
Expand Down

0 comments on commit 7f0f5cd

Please sign in to comment.