Sets API

Purely functional interface for the Sets API.

Set Commands usage

Once you have acquired a connection you can start using it:

import cats.effect.IO
import cats.syntax.all._

val testKey = "foos"

def putStrLn(str: String): IO[Unit] = IO(println(str))

val showResult: Set[String] => IO[Unit] = x => putStrLn(s"$testKey members: $x")

commandsApi.use { cmd => // SetCommands[IO, String, String]
  for {
    x <- cmd.sMembers(testKey)
    _ <- showResult(x)
    _ <- cmd.sAdd(testKey, "set value")
    y <- cmd.sMembers(testKey)
    _ <- showResult(y)
    _ <- cmd.sCard(testKey).flatMap(s => putStrLn(s"size: ${s.toString}"))
    _ <- cmd.sRem("non-existing", "random")
    w <- cmd.sMembers(testKey)
    _ <- showResult(w)
    _ <- cmd.sRem(testKey, "set value")
    z <- cmd.sMembers(testKey)
    _ <- showResult(z)
    _ <- cmd.sCard(testKey).flatMap(s => putStrLn(s"size: ${s.toString}"))
  } yield ()
}