From 9a4245a686341257b9c21b288314a72667f94c9f Mon Sep 17 00:00:00 2001 From: mandubian Date: Tue, 17 May 2016 08:58:19 +0200 Subject: [PATCH] pushed to bintray --- LICENSE | 8 ++++++ build.sbt | 5 +++- project/plugins.sbt | 1 + src/main/scala/package.scala | 4 +-- src/test/scala/AppSpec.scala | 53 +++++++++++++++++++++++++++--------- 5 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 LICENSE create mode 100644 project/plugins.sbt diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4baedcb --- /dev/null +++ b/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. \ No newline at end of file diff --git a/build.sbt b/build.sbt index ad4e1a8..8c4be95 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,5 @@ lazy val commonSettings = Seq( - organization := "com.projectseptember" + organization := "com.mandubian" , version := "0.1.0" , resolvers ++= Seq( Resolver.mavenLocal @@ -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( @@ -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(".")). diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000..8dd913f --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0") diff --git a/src/main/scala/package.scala b/src/main/scala/package.scala index cc68642..e2c0a7f 100644 --- a/src/main/scala/package.scala +++ b/src/main/scala/package.scala @@ -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)) diff --git a/src/test/scala/AppSpec.scala b/src/test/scala/AppSpec.scala index 2c3f934..d7b074d 100644 --- a/src/test/scala/AppSpec.scala +++ b/src/test/scala/AppSpec.scala @@ -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 */ @@ -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) } @@ -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) => @@ -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() + } } - - +} @@ -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, ?], ?]]] -} +