This file contains hidden or 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 ValidatedValue._ | |
| final case class Row(a: Int, b: Double, c: String, aOpt: Option[Int], list: List[Int]) | |
| sealed trait ValidatedValue[+A] { self => | |
| def flatMap[B](f: A => ValidatedValue[B]): ValidatedValue[B] = | |
| self match { | |
| case Valid(v) => | |
| f(v) |
This file contains hidden or 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 net.demo.example | |
| import akka.actor.ExtendedActorSystem | |
| import akka.actor.typed.{ActorRef, ActorSystem} | |
| import akka.serialization.SerializerWithStringManifest | |
| import net.demo.example.Reply.{JoinReply, LeaveReply} | |
| import java.io.NotSerializableException | |
| final case class ChatId(value: String) extends AnyVal |
This file contains hidden or 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
| //> using scala "2" | |
| //> using jvm "graalvm-java17:22.3.2" | |
| //> using repository "jitpack" | |
| //> using dep "com.typesafe.akka::akka-stream:2.6.20" | |
| import akka.actor.ActorSystem | |
| import scala.concurrent.Future | |
| import akka.stream.scaladsl.{ Flow, Keep, Sink, Source } | |
| // using jvm "17" |
This file contains hidden or 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 akka.actor.typed.ActorSystem | |
| import akka.actor.typed.scaladsl.Behaviors | |
| import akka.http.scaladsl.Http | |
| import akka.stream.alpakka.s3.{MultipartUploadResult} | |
| import akka.stream.alpakka.s3.scaladsl.S3 | |
| import akka.stream.scaladsl.{Keep, Sink, Source} | |
| import akka.util.ByteString | |
| import com.typesafe.config.ConfigFactory | |
| import java.util.UUID |
This file contains hidden or 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 java.nio.charset.StandardCharsets | |
| import java.security.MessageDigest | |
| import java.util.{Base64, UUID} | |
| import scala.collection.mutable | |
| import scala.reflect.ClassTag | |
| import scala.util.Try | |
| object HashRingBuffer { | |
| type Hash = Array[Byte] |
This file contains hidden or 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
| /** {{{ | |
| * +---------------------------------------------------------------------------------------------------------------------------------------------+ | |
| * | +------------+ +------------+ +-----------------------+ +--------------------+ +--------------+ +------------+ | | |
| * | |OPENED(usr) ○---->|PAID((usr)) ○----->|READY_FOR_DELIVERY(amz)○----->|OUT_OF_DELIVERY(amz)○----->|DELIVERED(amz)○------>|RETURNED(usr) | | |
| * | +------------+ +------------+ +-----------------------+ +--------------------+ +--------------+ +------------+ | | |
| * | | | | +-------------+ | | |
| * | +------------------+---------------------+------->|CANCELED(usr)| | | |
| * | +-------------+ |
This file contains hidden or 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 JvmInternals { | |
| def writeDouble(d: Double): Array[Byte] = | |
| writeLong(java.lang.Double.doubleToRawLongBits(d)) | |
| def readDouble(bytes: Array[Byte]) = | |
| java.lang.Double.longBitsToDouble(readLong(bytes)) | |
| def writeLong(i: Long): Array[Byte] = { | |
| val array = Array.ofDim[Byte](8) |
This file contains hidden or 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 JvmInternals { | |
| def arrayOf[T: scala.reflect.ClassTag] = { | |
| val cl = Array.ofDim[T](0).getClass | |
| java.lang.invoke.MethodHandles.byteArrayViewVarHandle(cl, ByteOrder.BIG_ENDIAN) | |
| } | |
| def getByInd[T: scala.reflect.ClassTag](vh: java.lang.invoke.VarHandle, array: Array[Byte], i: Int): T = { | |
| implicitly[scala.reflect.ClassTag[T]].getClass | |
| vh.get(array, i).asInstanceOf[T] |
This file contains hidden or 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
| //an implementation that gives more control over when the work in a Future starts. | |
| import scala.concurrent.ExecutionContext.Implicits.global | |
| val p = Promise[Unit]() | |
| val f = p.future | |
| val _ = f.map { _ => | |
| var i = 0 | |
| while (i < 10) { | |
| i += 1 |
This file contains hidden or 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 sample.blog.eg | |
| import java.util.concurrent.ThreadLocalRandom | |
| import akka.actor.{ ActorSystem, Scheduler } | |
| import akka.stream.QueueOfferResult.{ Dropped, Enqueued } | |
| import akka.stream.scaladsl.SourceQueueWithComplete | |
| import akka.stream.{ ActorAttributes, ActorMaterializer, Materializer, OverflowStrategy, QueueOfferResult } | |
| import akka.stream.scaladsl.{ FlowWithContext, Keep, Sink, Source } |
NewerOlder