unique Build Status Maven Central

This is a shared library for creating and managing unique values in a referentially transparent way.

Creation of a unique value must always happen within an effect.

Let’s start with some imports.

import io.chrisdavenport.unique.Unique
import cats.implicits._
import cats.effect._

Then we can display that only values created by the same effect are equal.

val equal = for {
  unique <- Unique.newUnique[IO]
} yield unique === unique
// equal: cats.effect.IO[Boolean] = <function1>

equal.unsafeRunSync // For Display
// res0: Boolean = true

val notEqual = for {
  unique1 <- Unique.newUnique[IO]
  unique2 <- Unique.newUnique[IO]
} yield unique1 === unique2
// notEqual: cats.effect.IO[Boolean] = IO$1938911849

notEqual.unsafeRunSync // For Display
// res1: Boolean = false