View Scala Cats: flatTraverse
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 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))) |
View Scala Cats: import cats.data.EitherT
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 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 |
View Scala Cats: import cats.data.OptionT
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 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 |
View Scala Cats: import cats.syntax.traverse._
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 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)) |
View Scala Cats: import cats.syntax.cartesian._
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 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 |
View Scala Cats: import cats.syntax.either._
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 cats.syntax.either._ | |
val eitherRightValue: Either[Boolean, Int] = 35.asRight[Boolean] | |
val eitherLeftValue: Either[Int, Boolean] = 35.asLeft[Boolean] |
View Scala Cats: import cats.syntax.option._
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 cats.syntax.option._ | |
val optionValue: Option[Int] = 35.some | |
val noneValue: Option[Int] = none[Int] |
View Akka Persistence
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 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) |
View amps-config.xml
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
<SOW> | |
<Topic> | |
<Name>sow-topic</Name> | |
<FileName>sow/%n.sow</FileName> | |
<Expiration>enabled</Expiration> | |
<Key>/id</Key> | |
<MessageType>json</MessageType> | |
</Topic> | |
</SOW> |
View AMPS Subscriber
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 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") |
NewerOlder