Skip to content

mtavkhelidze/fuda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

札 Fuda

Type-safe opaque UUID identity system for Scala 3

Installation

libraryDependencies += "io.github.mtavkhelidze" %% "fuda" % "0.1.0"

Usage

Define your opaque type:

import fuda.Fuda

opaque type UserId <: Fuda.Id = Fuda.Id

Generate and parse IDs:

import cats.effect.IO

// Generate
val newId: IO[UserId] = Fuda[UserId].make[IO].run(())

// Parse from string
val parsed: IO[UserId] = Fuda[UserId]
  .read[IO]
  .run("22124234-196c-4d0d-af5c-1a8da7486259")

Different opaque types are incompatible at compile time:

opaque type UserId <: Fuda.Id = Fuda.Id
opaque type ProductId <: Fuda.Id = Fuda.Id

// Does not compile — UserId and ProductId are distinct types
val x: UserId = someProductId

The Kanji

(ふだ) is a Japanese word for label or tag.

About

札: Type-safe opaque UUID identity system for Scala 3

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages