Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Jacobowitz committed Nov 8, 2017
0 parents commit c6ece2f
Show file tree
Hide file tree
Showing 13 changed files with 844 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
project/project/
.idea/
21 changes: 21 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
enablePlugins(ScalaJSPlugin)

name := "tagless-webgl"

version := "1.0"

scalaVersion := "2.12.4"

libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % "1.0.0-RC1",
"org.typelevel" %%% "cats-effect" % "0.5",
"org.scala-js" %%% "scalajs-dom" % "0.9.2",
"co.fs2" %%% "fs2-core" % "0.10.0-M8"
)

addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.4")

scalaJSUseMainModuleInitializer := true

jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv()

Binary file added car.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>WebGL Tagless</title>
</head>
<body style="margin: 0px">
<script type="text/javascript" src="./target/scala-2.12/tagless-webgl-fastopt.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version = 0.13.16
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("org.lyranthe.sbt" % "partial-unification" % "1.1.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.20")
Binary file added racetrack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions src/main/scala/Par.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import cats._
import cats.arrow.FunctionK
import cats.implicits._
import fs2._
import cats.effect._

import scala.concurrent.ExecutionContext



object ParIO {

def applicativeForParIO(implicit ev: ExecutionContext): Applicative[IO] = new Applicative[IO] {
def ap[A, B](ff: IO[A => B])(fa: IO[A]) = for {
tf <- async.start(ff)
ta <- async.start(fa)
f <- tf
a <- ta
} yield f(a)

def pure[A](a: A): IO[A] = IO.pure(a)
}

implicit def parallelForIO(implicit ev: ExecutionContext): Parallel[IO, IO] = new Parallel[IO, IO] {
def monad: Monad[IO] = IO.ioEffect

def applicative: Applicative[IO] = applicativeForParIO

def sequential = FunctionK.id
def parallel = FunctionK.id
}
}

object Test {
import scala.concurrent.ExecutionContext.Implicits.global
import ParIO._

val x = IO.pure("asd")
val y = IO.pure(234)

(x, y).parMapN(_ + _)
}

case class Par[F[_], A](value: F[A])

object Par {

def applicativeForPar[F[_]: Effect](implicit ev: ExecutionContext): Applicative[Par[F, ?]] = new Applicative[Par[F, ?]] {
def ap[A, B](ff: Par[F, A => B])(fa: Par[F, A]) = Par(for {
tf <- async.start(ff.value)
ta <- async.start(fa.value)
f <- tf
a <- ta
} yield f(a))

def pure[A](a: A): Par[F, A] = Par(Applicative[F].pure(a))
}

implicit def parallelForPar[F[_]: Effect](implicit ev: ExecutionContext): Parallel[F, Par[F, ?]] = new Parallel[F, Par[F, ?]] {
def monad: Monad[F] = Monad[F]

def applicative: Applicative[Par[F, ?]] = applicativeForPar[F]

override def sequential = Lambda[Par[F, ?] ~> F](_.value)
def parallel = Lambda[F ~> Par[F, ?]](g => Par(g))
}
}

object TestPar {
import scala.concurrent.ExecutionContext.Implicits.global
import Par._

val x = IO.pure("asd")
val y = IO.pure(234)

(x, y).parMapN(_ + _)
}
Loading

0 comments on commit c6ece2f

Please sign in to comment.