Skip to content

Latest commit

 

History

History
51 lines (30 loc) · 2.19 KB

README.md

File metadata and controls

51 lines (30 loc) · 2.19 KB

gfc-id Maven Central Build Status Coverage Status

A library that contains typed Id and Guid classes. A fork and new home of the now unmaintained Gilt Foundation Classes (com.gilt.gfc), now called the GFC Collective, maintained by some of the original authors.

Getting gfc-id

The latest version is 1.0.0, released on 21/Jan/2020 and cross-built against Scala 2.12.x and 2.13.x.

If you're using SBT, add the following line to your build file:

libraryDependencies += "org.gfccollective" %% "gfc-id" % "1.0.0"

For Maven and other build tools, you can visit search.maven.org. (This search will also list other available libraries from the GFC Collective.)

Contents and Example Usage

Typed identifiers allow compile-time checking that an identifier that is passed into a function or object is of the correct type, which is not the case with "untyped" String, Long or UUID types.

org.gfccollective.id.Guid

Guid is a space/cpu efficient and type safe replacement for java.util.UUID

val userGuid: Guid[User] = Guid.randomGuid
val user: User = new User(userGuid, firstName, lastName)

org.gfccollective.id.Id

Id can be used for typed identifiers (e.g. rdbms auto-increment ids).

val userId: Id[User, Long] = Random.nextLong
val user: User = new User(userId, firstName, lastName)

Type aliases

Both Guid and Id can be used in conjunction with type aliases:

type UserGuid = Guid[User]
type UserId = Id[User, Long]
case class User(guid: UserGuid, id: UserId, firstName: String, lastName: String)

License

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0