-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luka Jacobowitz
committed
Nov 8, 2017
0 parents
commit c6ece2f
Showing
13 changed files
with
844 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target/ | ||
project/project/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version = 0.13.16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(_ + _) | ||
} |
Oops, something went wrong.