Skip to content

Commit

Permalink
Bring back the braces
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Nov 12, 2023
1 parent 0cb9a92 commit 8bbefe8
Show file tree
Hide file tree
Showing 73 changed files with 829 additions and 494 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ val MunitVersion = "1.0.0-M10"
val DisciplineMunitVersion = "2.0.0-M3"
val MunitCatsEffectVersion = "2.0.0-M3"

ThisBuild / scalacOptions ++= Seq("-new-syntax", "-indent", "-source:future")
ThisBuild / scalacOptions ++= Seq("-new-syntax", "-no-indent", "-source:future")
ThisBuild / Test / testOptions += Tests.Argument("+l")

val commonJvmSettings = Seq(
Expand Down
18 changes: 12 additions & 6 deletions core/src/main/scala/schrodinger/RVIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,20 @@ import scala.util.NotGiven

opaque type RVIO[S, +A] = IO[A]

object RVIO:
extension [S, A](rvioa: RVIO[S, A])
object RVIO {
extension [S, A](rvioa: RVIO[S, A]) {
inline def evalMap[B](f: A => IO[B]): RVIO[S, B] =
rvioa.flatMap(a => eval(f(a)))
}

type Par[S, A] = ParallelF[RVIO[S, _], A]

inline def eval[S, A](ioa: IO[A]): RVIO[S, A] = ioa

def evalK[S]: IO ~> RVIO[S, _] =
new:
new {
def apply[A](ioa: IO[A]): RVIO[S, A] = ioa
}

def algebra[S: SplittableRng]: IO[Algebra[S]] = IOLocal[State[S]](null).map(Algebra(_))

Expand All @@ -72,7 +74,7 @@ object RVIO:
extends Async[RVIO[S0, _]],
PseudoRandom[RVIO[S0, _]],
RngDispatcher[RVIO[S0, _]],
GaussianCache[RVIO[S0, _], Double]:
GaussianCache[RVIO[S0, _], Double] {

type G[A] = IO[A]
type S = S0
Expand Down Expand Up @@ -150,8 +152,9 @@ object RVIO:
): RVIO[S, A] =
fa.guaranteeCase(finalizer)

extension [A](fa: RVIO[S, A])
extension [A](fa: RVIO[S, A]) {
def simulate(seed: S): IO[A] = IO(State(seed.copy())).flatMap(state.set) *> fa
}

def int: RVIO[S, Int] = state.get.flatMap(s => IO(s.rng.nextInt()))

Expand All @@ -171,9 +174,11 @@ object RVIO:
def set(x: Double): RVIO[S, Unit] = state.get.flatMap(s => IO(s.cachedGaussian = x))

def suspend[A](hint: Sync.Type)(thunk: => A): RVIO[S, A] = IO.suspend(hint)(thunk)
}

given [S, A](using show: Show[IO[A]]): Show[RVIO[S, A]] with
given [S, A](using show: Show[IO[A]]): Show[RVIO[S, A]] with {
def show(rv: RVIO[S, A]): String = s"RV${show.show(rv)}"
}

given [S, A](using m: Monoid[IO[A]]): Monoid[RVIO[S, A]] = m
given [S, A](using
Expand All @@ -184,3 +189,4 @@ object RVIO:
given [S]: Align[RVIO[S, _]] = IO.alignForIO
given [S](using Spawn[RVIO[S, _]]): Parallel[RVIO[S, _]] = spawn.parallelForGenSpawn
given [S]: Console[RVIO[S, _]] = IO.consoleForIO
}
Loading

0 comments on commit 8bbefe8

Please sign in to comment.