Skip to content

Instantly share code, notes, and snippets.

import cats.syntax.traverse._
import cats.instances.future._
import cats.syntax.option._
import cats.instances.option._
val optionalValue: Option[Int] = 35.some
val finalResult: Future[Option[Int]] = optionalValue.traverse(value => Future(value + 1))
import cats.implicits._
val listValue: List[Option[Int]] = List(35.some, 45.some, 55.some))
val result: Option[List[Int]] = listValue.flatTraverse(_.map(x=>List(x)))
import cats.data.EitherT
import cats.syntax.either._
val eitherValue: Either[Boolean, Int] = 35.asRight[Boolean]
val futureEitherValue: Future[Either[Boolean, Int]] = Future(eitherValue)
val eitherTValue: EitherT[Future, Boolean, Int] = EitherT(futureEitherValue)
val extractedFutureValue: Future[Either[Boolean, Int]] = eitherTValue.value
import cats.data.OptionT
val futureValue: Future[Option[Int]] = Future(Option(23))
val optionTValue: OptionT[Future, Int] = OptionT(futureValue)
val extractedFutureValue: Future[Option[Int]] = optionTValue.value
import cats.instances.future._
import cats.syntax.cartesian._
val addFutureValue = Future(2 + 1)
val multiplyFutureValue = Future(2 * 1)
val substractFutureValue = Future(2 - 1)
val result: Future[Int] = (addFutureValue |@| multiplyFutureValue |@| substractFutureValue).map{ (addedValue, multipiedValue, substractedValue) =>
addedValue + multipiedValue + substractedValue
import cats.syntax.either._
val eitherRightValue: Either[Boolean, Int] = 35.asRight[Boolean]
val eitherLeftValue: Either[Int, Boolean] = 35.asLeft[Boolean]
import cats.syntax.option._
val optionValue: Option[Int] = 35.some
val noneValue: Option[Int] = none[Int]
import akka.actor.Props
import akka.persistence.{PersistentActor, SnapshotOffer}
import com.knoldus.models._
import com.knoldus.persistence.CounterPersistentActor.Response
class CounterPersistentActor(id: String) extends PersistentActor {
override val persistenceId: String = id
var state = State(count = 0)
<SOW>
<Topic>
<Name>sow-topic</Name>
<FileName>sow/%n.sow</FileName>
<Expiration>enabled</Expiration>
<Key>/id</Key>
<MessageType>json</MessageType>
</Topic>
</SOW>
@akhilvijayan05
akhilvijayan05 / AMPS Subscriber
Last active October 13, 2018 12:02
A simple example for an AMPS subscriber
import com.crankuptheamps.client.Client;
import com.crankuptheamps.client.exception.AMPSException;
import scala.collection.JavaConverters._
object Subscriber extends App {
val client = new Client("subscribe")
try {
client.connect("tcp://127.0.0.1:9007/amps/json")