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
class Node { | |
constructor(key, value, color, left = null, right = null) { | |
Object.assign(this, { key, value, color, left, right }); | |
} | |
async insert(key, value) { | |
const cmp = key < this.key ? "left" : "right"; | |
const child = this[cmp]; | |
const newChild = child === null ? new Node(key, value, true) : await child.insert(key, value); | |
return newChild.color && this.color ? this.fixup(newChild, cmp) : new Node(this.key, this.value, this.color, cmp === "left" ? newChild : this.left, cmp === "right" ? newChild : this.right); |
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
object Test { | |
import zio._ | |
import zio.duration._ | |
import zio.kafka.consumer._ | |
val settings: ConsumerSettings = | |
ConsumerSettings(List("localhost:9092")) | |
.withGroupId("group") | |
.withClientId("client") |
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
object Test { | |
import zio._ | |
import zio.duration._ | |
import zio.kafka.consumer._ | |
val settings: ConsumerSettings = | |
ConsumerSettings(List("localhost:9092")) | |
.withGroupId("group") | |
.withClientId("client") |
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
import zio._ | |
import zio.console._ | |
import zio.kafka.consumer._ | |
import zio.kafka.serde._ | |
val subscription: Subscription = Subscription.topics("topic") | |
val readKafka: RIO[Console with Blocking with Clock, Unit] = | |
Consumer.consumeWith(settings, subscription, Serde.string, Serde.string) { | |
case (key, value) => | |
putStrLn(s"Received message ${key}: ${value}") |
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
object Test { | |
import zio._ | |
import zio.duration._ | |
import zio.kafka.consumer._ | |
val settings: ConsumerSettings = | |
ConsumerSettings(List("localhost:9092")) | |
.withGroupId("group") | |
.withClientId("client") |
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
name := "zio-kafka-test" | |
version := "0.1" | |
scalaVersion := "2.13.3" | |
libraryDependencies += "dev.zio" %% "zio-kafka" % "0.12.0" | |
libraryDependencies += "dev.zio" %% "zio-streams" % "1.0.0" |
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
sealed trait TreeSeq[+A] { | |
lazy val size: Int = this match { | |
case Leaf(_) => 1 | |
case Branch(l, r) => (l.size + r.size) | |
} | |
def +[A1 >: A](a1: A1): TreeSeq[A1] = TreeSeq(a1) | |
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
package exercises | |
import scala.annotation.tailrec | |
abstract class MyStream[+A] { | |
def isEmpty: Boolean | |
def head: A | |
def tail: MyStream[A] |
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
package repeat | |
abstract class MyList[+A] { | |
def head: A | |
def tail: MyList[A] | |
def isEmpty: Boolean | |
def add[B >: A](element: B): MyList[B] | |
def printElements: String | |
override def toString: String = "[" + printElements + "]" |
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
[info] Benchmark (size) Mode Cnt Score Error Units | |
[info] ArrayBenchmarks.find 1000 avgt 15 40.282 ± 0.109 ns/op | |
[info] ArrayBenchmarks.findOptimized 1000 avgt 15 7.645 ± 0.002 ns/op | |
[info] ArrayBenchmarks.flatMap 1000 avgt 15 31442.367 ± 11.125 ns/op | |
[info] ArrayBenchmarks.flatMapOptimized 1000 avgt 15 14086.659 ± 35.318 ns/op | |
[info] ArrayBenchmarks.fold 1000 avgt 15 13050.998 ± 6.377 ns/op | |
[info] ArrayBenchmarks.map 1000 avgt 15 10070.717 ± 15.476 ns/op | |
[info] ArrayBenchmarks.mapOptimized 1000 avgt 15 461.821 ± 2.040 ns/op | |
[info] ChunkArrayBenchmarks.find 1000 avgt 15 23.068 ± 0.012 ns/op | |
[info] ChunkArrayBenchmarks.flatMap 1000 avgt 15 72463.542 ± 111.816 ns/op |
NewerOlder