Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ml10/fuuid

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fuuid - Functional UUID Build Status Maven Central

Java UUID's aren't exceptionally safe. Operations throw and are not referentially transparent. We can fix that.

Currently this is the minimal implementation that keeps me content.

Quick Start

To use fuuid in an existing SBT project with Scala 2.11 or a later version, add the following dependency to your build.sbt:

libraryDependencies += "io.chrisdavenport" %% "fuuid" % "<version>"

Examples

import io.chrisdavenport.fuuid.FUUID
import cats.effect.IO

// We place it in IO because this requires a Sync constraint
val create: IO[FUUID] = FUUID.randomFUUID[IO]

val fromString : Either[IllegalArgumentException, FUUID] = FUUID.fromString("d6faceab-4193-4508-86ca-e1561d38fea6")

val failsReferentiallyTransparently : Either[IllegalArgumentException, FUUID] = FUUID.fromString("Not a UUID")
// Will be a Left

// For some syntax improvements
import cats.implicits._

// Uses cats Eq
val equalToItself : IO[Boolean] = for {
  fuuid <- FUUID.randomFUUID[IO]
} yield fuuid === fuiid

equalToItself.unsafeRunSync
// true

// Uses cats Order
val laterGreaterThanEarlier : IO[Boolean] = for {
  fuuid1 <- FUUID.randomFUUID[IO]
  fuuid2 <- FUUID.randomFUUID[IO]
} yield fuuid2 > fuuid1
// true

About

Functional UUID's for Scala

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 100.0%