Skip to content

Commit

Permalink
pushed to bintray
Browse files Browse the repository at this point in the history
  • Loading branch information
mandubian committed May 17, 2016
1 parent b4e336b commit 9a4245a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 16 deletions.
8 changes: 8 additions & 0 deletions LICENSE
@@ -0,0 +1,8 @@
This software is licensed under the Apache 2 license, quoted below.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
5 changes: 4 additions & 1 deletion build.sbt
@@ -1,5 +1,5 @@
lazy val commonSettings = Seq(
organization := "com.projectseptember"
organization := "com.mandubian"
, version := "0.1.0"
, resolvers ++= Seq(
Resolver.mavenLocal
Expand All @@ -8,6 +8,8 @@ lazy val commonSettings = Seq(
)
// , scalaVersion := "2.11.8"
, scalaVersion := "2.11.8"
, bintrayOrganization := Some("mandubian")
, licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0"))
, addCompilerPlugin("com.milessabin" % "si2712fix-plugin" % "1.2.0" cross CrossVersion.full)
, addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.7.1")
, libraryDependencies ++= Seq(
Expand All @@ -17,6 +19,7 @@ lazy val commonSettings = Seq(
, "com.milessabin" % "si2712fix-library" % "1.2.0" cross CrossVersion.full
, "org.scalatest" % "scalatest_2.11" % "2.1.3" % "test"
)

)

lazy val root = (project in file(".")).
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
@@ -0,0 +1 @@
addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0")
4 changes: 2 additions & 2 deletions src/main/scala/package.scala
Expand Up @@ -10,8 +10,8 @@ package object freek {
implicit subCop: SubCop[C, D]
): Freek[D, A] = {

def nat[F[_] <: CoproductK[_], G[_] <: CoproductK[_]](implicit subCop: SubCop[F, G]) = new (F ~> G) {
def apply[A](fa: F[A]): G[A] = subCop(fa)
val nat = new (C ~> D) {
def apply[A](fa: C[A]): D[A] = subCop(fa)
}

new Freek(freek.free.mapSuspension(nat))
Expand Down
53 changes: 40 additions & 13 deletions src/test/scala/AppSpec.scala
Expand Up @@ -125,8 +125,39 @@ object Http {
}
}


class AppSpec extends FlatSpec with Matchers {

/** weird this is not provided in cats apparently */
implicit val fc = new cats.Comonad[Function0] {
def extract[A](x: () => A): A = x()
def coflatMap[A, B](fa: () => A)(f: (() => A) => B): () => B = () => f(fa)
def map[A, B](fa: () => A)(f: A => B): () => B = () => f(fa())
}


// "foldMap" should "be stack safe" in {
// trait FTestApi[A]
// case class TB(i: Int) extends FTestApi[Int]

// type FTest[A] = Free[FTestApi, A]

// def tb(i: Int): FTest[Int] = Free.liftF(TB(i))

// def a(i: Int): FTest[Int] = for {
// j <- tb(i)
// z <- if (j<10000000) a(j) else Free.pure[FTestApi, Int](j)
// } yield z

// def runner: FTestApi ~> Trampoline = new (FTestApi ~> Trampoline) {
// def apply[A](fa: FTestApi[A]): Trampoline[A] = fa match {
// case TB(i) => Trampoline.done(i+1)
// }
// }

// assert(10000000 == a(0).foldMap(runner).run)
// }

"ShapeApp" should "freek" in {

/** Declare programs */
Expand All @@ -145,7 +176,7 @@ class AppSpec extends FlatSpec with Matchers {
for {
_ <- Log.debug("Searching for entity id:"+id).freek
res <- FindById(id).freek
_ <- Log.debug("Search result:"+res).freek
// _ <- Log.debug("Search result:"+res).freek
} yield (res)
}

Expand Down Expand Up @@ -180,7 +211,7 @@ class AppSpec extends FlatSpec with Matchers {
for {
recv <- HttpInteract.receive().freek
_ <- Log.info("HttpReceived Request:"+recv).freek
res <- (recv match {
res <- (recv match {
case Xor.Left(err) => HttpInteract.stop(Xor.left(err)).freek

case Xor.Right(req) =>
Expand Down Expand Up @@ -243,24 +274,20 @@ class AppSpec extends FlatSpec with Matchers {
*/
val interpreter: Interpreter[HttpService.PRG, cats.Id] = HttpInteraction >>: HttpHandler >>: Logger >>: DBManager

/** weird this is not provided in cats apparently */
implicit val fc = new cats.Comonad[Function0] {
def extract[A](x: () => A): A = x()
def coflatMap[A, B](fa: () => A)(f: (() => A) => B): () => B = () => f(fa)
def map[A, B](fa: () => A)(f: A => B): () => B = () => f(fa())
}

/** as we use a recursive program, we need to trampoline it in order to prevent stack overflow */
object Trampolined extends (cats.Id ~> Trampoline) {
def apply[A](a: cats.Id[A]) = Trampoline.done(a)
}

// execute final program as a simple free with combined interpreter composed with a trampoline
HttpService.serve().free.foldMap(Trampolined compose interpreter.nat).run
try {
HttpService.serve().free.foldMap(Trampolined compose interpreter.nat).run
} catch {
case e:Throwable => e.printStackTrace()
}
}



}



Expand Down Expand Up @@ -300,5 +327,5 @@ class AppSpec extends FlatSpec with Matchers {
// implicitly[MergeCopHK.Aux[ConsK[F, ConsK[G, CNilK, ?], ?], ConsK[G, CNilK, ?], ConsK[F, ConsK[G, CNilK, ?], ?]]]


}


0 comments on commit 9a4245a

Please sign in to comment.