dc10.scala.predef.namespace.Packages.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dc10-scala_sjs1_3 Show documentation
Show all versions of dc10-scala_sjs1_3 Show documentation
A definitional compiler for generating Scala code.
The newest version!
package dc10.scala.predef.namespace
import cats.data.StateT
import cats.syntax.all.given
import dc10.File
import dc10.scala.{ErrorF, LibDep, Statement, compiler}
import java.nio.file.Path
trait Packages[F[_]]:
def PACKAGE[A](nme: String, files: F[A]): F[A]
object Packages:
trait Mixins extends Packages[
StateT[ErrorF, (Set[LibDep], List[File[Statement]]), _],
]:
def PACKAGE[A](nme: String, files: StateT[ErrorF, (Set[LibDep], List[File[Statement]]), A]): StateT[ErrorF, (Set[LibDep], List[File[Statement]]), A] =
for
((ds, ms), a) <- StateT.liftF[ErrorF, (Set[LibDep], List[File[Statement]]), ((Set[LibDep], List[File[Statement]]), A)](files.runEmpty)
ss = ms.map(s => s.copy(
path = Path.of(nme.replace(".", "/")).resolve(s.path),
contents = List[Statement](Statement.`package`(Some(nme), s.contents))
))
_ <- ds.toList.traverse(l => StateT.modifyF[ErrorF, (Set[LibDep], List[File[Statement]])](ctx => ctx.dep(l)))
_ <- ss.traverse(d => StateT.modifyF[ErrorF, (Set[LibDep], List[File[Statement]])](ctx => ctx.ext(d)))
yield a
© 2015 - 2025 Weber Informatics LLC | Privacy Policy