Skip to content

Commit

Permalink
better documentation for logic API
Browse files Browse the repository at this point in the history
  • Loading branch information
rssh committed Jan 20, 2024
1 parent 9d43449 commit 4cb2efb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ lazy val root = project
Sphinx / sourceDirectory := baseDirectory.value / "docs",
SiteScaladocPlugin.scaladocSettings(CpsJVM, cps.jvm / Compile / packageDoc / mappings, "api/jvm"),
SiteScaladocPlugin.scaladocSettings(CpsJS, cps.js / Compile / packageDoc / mappings, "api/js"),
SiteScaladocPlugin.scaladocSettings(CpsNative, cps.native / Compile / packageDoc / mappings, "api/native"),
SiteScaladocPlugin.scaladocSettings(Root, logic.jvm / Compile / packageDoc / mappings, "api/logic/jvm"),
siteDirectory := baseDirectory.value / "target" / "site",
git.remoteRepo := "[email protected]:rssh/dotty-cps-async.git",
publishArtifact := false,
Expand Down Expand Up @@ -68,7 +70,7 @@ lazy val cps = crossProject(JSPlatform, JVMPlatform, NativePlatform)

lazy val CpsJVM = config("cps.jvm")
lazy val CpsJS = config("cps.js")
//lazy val CpsNative = config("cps.native")
lazy val CpsNative = config("cps.native")
lazy val Root = config("root")

lazy val cpsLoomAddOn = project.in(file("jvm-loom-addon"))
Expand Down
8 changes: 6 additions & 2 deletions logic/shared/src/main/scala/cps/CpsSyncLogicMonad.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ trait CpsSyncLogicMonad[M[_]] extends CpsLogicMonad[M] {
override type Observer[T] = T

override def observerCpsMonad: CpsTryMonad[Observer] = CpsIdentityMonad

def toLazyList[T](m:M[T]): LazyList[T]

}


extension [M[_]:CpsSyncLogicMonad,A](ma:M[A])

def toLazyList: LazyList[A] =
summon[CpsSyncLogicMonad[M]].toLazyList(ma)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class DefaultLogicMonadBasicTest {
@Test
def logicMonadFromCollection() = {
val m = LogicStream.fromCollection(List(1,2,3))

}


Expand Down
15 changes: 12 additions & 3 deletions logic/shared/src/test/scala/cps/logic/PrimesTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cps.logic

import cps.*
import cps.monads.*
import cps.monads.logic.{*, given}
import cps.monads.logic.{*}
import org.junit.{Test,Ignore}

import scala.collection.immutable.TreeSet
Expand All @@ -13,18 +13,27 @@ class PrimesTest {
@Test
def testPrimes(): Unit = {
val first10 = PrimesTest.primes.observeN(10)
println(s"first10 = $first10")
//println(s"first10 = $first10")
assert(first10.toSeq == Seq(2,3,5,7,11,13,17,19,23,29))
}

@Test
def testToLazyList() = {
val first10 = PrimesTest.primes.toLazyList.take(10)
//println(s"first10 = $first10")
assert(first10.toSeq == Seq(2,3,5,7,11,13,17,19,23,29))
}


}

object PrimesTest {

def primes: LogicStream[Int] = {
eratosphen(2, TreeSet.empty[Int])
}



def eratosphen(c:Int, knownPrimes: TreeSet[Int]): LogicStream[Int] = reify[LogicStream]{
guard(
knownPrimes.takeWhile(x => x*x <= c).forall(x => c % x != 0)
Expand Down

0 comments on commit 4cb2efb

Please sign in to comment.