Skip to content

Commit

Permalink
Added zio implementation for EffectBackend. Moved htypes to htypes-core
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenvDam committed Nov 23, 2019
1 parent 54d4cb6 commit 0b5128b
Show file tree
Hide file tree
Showing 56 changed files with 71 additions and 6 deletions.
15 changes: 11 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def createModule(
projectDependencies: Seq[ProjectReference] = Seq.empty
) = Project(id = moduleName, base = file(moduleName))
.dependsOn(projectDependencies.map(_ % "compile->compile;test->test"): _*)
.configs(IntegrationTest)
.settings(
name := moduleName,
libraryDependencies ++= libDependencies,
Expand All @@ -27,14 +26,22 @@ def createModule(
)

lazy val root = (project in file("."))
.settings(
name := "HTypes"
)
.aggregate(
hTypesCore,
hTypesAkkaStream
hTypesAkkaStream,
hTypesCatsEffect,
hTypesZIO
)
.settings(skip in publish := true)

lazy val hTypesCore = createModule("htypes", commonDependencies)
lazy val hTypesCore = createModule("htypes-core", commonDependencies)

lazy val hTypesAkkaStream = createModule("htypes-akka-stream", commonDependencies ++ akkaStream, Seq(hTypesCore))

lazy val hTypesCatsEffect = createModule("htypes-cats-effect", commonDependencies ++ catsEffect, Seq(hTypesCore))
lazy val hTypesCatsEffect = createModule("htypes-cats-effect", commonDependencies ++ catsEffect, Seq(hTypesCore))

lazy val hTypesZIO = createModule("htypes-zio", commonDependencies ++ zio, Seq(hTypesCore))

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ import akka.stream.scaladsl.Source
import com.svenvandam.htypes.stream.StreamBackend

object AkkaStreamBackend {

/**
* Type alias
*/
type AkkaStream[A] = Source[A, NotUsed] // TODO: use Source directly

implicit def akkaStreamBackend = new StreamBackend[AkkaStream] {
/**
* [[StreamBackend]] instance for [[Source]]
*/
implicit val akkaStreamBackend = new StreamBackend[AkkaStream] {
def getStream[A](iterator: Iterator[A]): Source[A, NotUsed] = Source.fromIterator(() => iterator)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import akka.stream.Materializer
import akka.stream.testkit.scaladsl.TestSink
import com.svenvandam.htypes.BaseHbaseTest
import com.svenvandam.htypes.bytes.ByteUtils
import org.apache.hadoop.hbase.client.{Scan, Result, Put}
import org.apache.hadoop.hbase.client.{Put, Result, Scan}
import com.svenvandam.htypes.Implicits._

class AkkaStreamBackendTest extends BaseHbaseTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import cats.effect.IO
import com.svenvandam.htypes.effect.EffectBackend

object CatsEffectBackend {

/**
* [[EffectBackend]] instance for [[IO]]
*/
implicit val catsEffectBackend = new EffectBackend[IO] {
def lift[A](a: => A): IO[A] = IO.delay(a)
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.svenvandam.htypes.effect.zio

import com.svenvandam.htypes.effect.EffectBackend
import zio.Task

object ZIOEffectBackend {

/**
* [[EffectBackend]] instance for [[Task]]
*/
implicit val zioTaskEffectBackend = new EffectBackend[Task] {
def lift[A](a: => A): Task[A] = Task(a)
}
}
8 changes: 8 additions & 0 deletions htypes-zio/src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
log4j.rootLogger = INFO, CONSOLE
log4j.logger.org.apache = ERROR, CONSOLE
log4j.logger.org.eclipse = WARN, CONSOLE
log4j.logger.org.mortbay = WARN, CONSOLE
log4j.logger.com.svenvandam = DEBUG, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.conversionPattern=%d{HH:mm:ss} %-5p %c - %m%n
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.svenvandam.htypes.effect.zio

import com.svenvandam.htypes.effect.EffectUtils
import org.scalatest.FunSuite
import org.scalatest.Matchers._
import ZIOEffectBackend._
import zio.DefaultRuntime

class ZIOEffectBackendTest extends FunSuite {
test("it should delay side effect") {
var x = 0

def action = x = 1

val io = EffectUtils.lift(action)

x shouldBe 0

val runtime = new DefaultRuntime {}

runtime.unsafeRun(io)

x shouldBe 1
}
}

0 comments on commit 0b5128b

Please sign in to comment.