GithubHelp home page GithubHelp logo

davenverse / fuuid Goto Github PK

View Code? Open in Web Editor NEW
145.0 3.0 37.0 1.8 MB

Functional UUID's for Scala

Home Page: https://davenverse.github.io/fuuid

License: MIT License

Scala 100.00%
scala uuid cats doobie http4s cats-effect

fuuid's Introduction

GitHub Actions Maven Central Code of Conduct Mergify Status Scala Steward badge

fuuid - Functional UUID

Head on over to the microsite

Impatient Quickstart

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

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

And for integrations:

libraryDependencies ++= Seq(
    "io.chrisdavenport" %% "fuuid-circe"  % "<version>", // Circe integration
    "io.chrisdavenport" %% "fuuid-http4s" % "<version>", // Http4s integration
    "io.chrisdavenport" %% "fuuid-doobie" % "<version>"  // Doobie integration
)

For more info visit the microsite

Versions

fuuid Scala 2.12 Scala 2.13 Scala 3 Cats CE http4s Doobie Circe
0.8.x Yes Yes Pending 2.x 3.x 0.23.x 1.0.x 1.0.x
0.7.x Yes Yes Pending 2.x 2.x 0.22.x 0.13.x 0.14.x
0.6.x Yes Yes Pending 2.x 2.x 0.21.x 0.13.x 0.13.x

fuuid's People

Contributors

alejandrohdezma avatar anthony2025 avatar brbrown25 avatar christopherdavenport avatar d1skort avatar gabro avatar isomarcte avatar jesusmtnez avatar kubukoz avatar laurentgir avatar lorandszakacs avatar lukajcb avatar matthughes avatar mergify[bot] avatar ml10 avatar morgen-peschke avatar mpilquist avatar pdalpra avatar scala-steward avatar sideeffffect avatar yawolf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fuuid's Issues

add support for UUID v5 construction

This functionality is also not available from java.util.UUID, but it is incredibly useful and is fairly straightforward to implement. If this seems like a good home for this, I'm glad to make a PR.

declare FUUID java.io.Serializable?

Regardless of the lameness of java serialization, there some frameworks and libraries that rely on it. (My current example is using FUUID in Apache Beam.)

It would be useful if FUUID declared itself java.io.Serializable, and likely delegated its serialization to the underlying UUID. I realize the implementation of this would be Unsafe, but that's mostly the nature of java serialization anyway I suppose.

Doobie Postgres Meta - Get/Put

Doobie currently provides utilities to write and read values as UUID's in postgres. As Doobie is an important tool in functional programming community. We can provide a module which provides the Meta - Get/Put instances. So people can easily read and write these values.

FuuidMeta causes StackOverflowError

The code

import doobie.postgres.implicits._
import io.chrisdavenport.fuuid.doobie.implicits._

io.chrisdavenport.fuuid.doobie.implicits.FuuidMeta

causes

java.lang.StackOverflowError
  at io.chrisdavenport.fuuid.doobie.implicits$.FuuidMeta(implicits.scala:19)

Http4s Extractor

Http4s is a critical functional component and often people match on a path segment that is a UUID and would like to directly extract. We should provide such an extractor.

Numberformatexception can escape your `fromString` function

scala> :paste
// Entering paste mode (ctrl-D to finish)

import java.util.UUID
UUID.fromString("2630147c-4a18-4866-9bbd-b2d89acef83z")

// Exiting paste mode, now interpreting.

java.lang.NumberFormatException: For input string: "b2d89acef83z"
  at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
  at java.lang.Long.parseLong(Long.java:589)
  at java.lang.Long.valueOf(Long.java:776)
  at java.lang.Long.decode(Long.java:928)
  at java.util.UUID.fromString(UUID.java:206)
  ... 44 elided

this makes the fromEither function impure

QueryParamDecoder instance for http4s

FUUIDVar from fuuid-http4s provides support for extracting path params, but there's no support for extracting query params.

It would essentially be something like

implicit val fuuidQueryParamDecoder: QueryParamDecoder[FUUID] =
  QueryParamDecoder.fromUnsafeCast(v => FUUID.fromString(v.value).right.get)("FUUID")

and use

object UserIdQueryParamMatcher extends QueryParamDecoderMatcher[FUUID]("userId")

val routes: HttpRoutes[F] = HttpRoutes.of[F]({
  case req @ GET -> Root / "get" :? UserIdQueryParamMatcher(userId) =>
    for {
      result <- controller.get(userId)
      res <- result.map(Ok(_)).getOrElse(NotFound())
    } yield res
})

@ChristopherDavenport if you agree this is useful, I can send a PR.

Move FUUIDVar#unapply into FUUID?

FUUIDVar from the http4s module simply defines an unapply method, which is "standard" and not specific to http4s in any way.

Could it make sense to move that unapply into the core FUUID object so that one would get path extractors out of the box without the extra dependency?

import io.chrisdavenport.fuuid.FUUID

Path("/v1/16a30838-5e02-4e68-a1bc-585e42594430") match {
  case Root / "v1" / FUUID(uuid) => // do something with uuid
  case _ => // nope
}

I understand that conceptually the unapply method is there to support http4s extractors, but it could technically be useful in any other match clause regardless of https.
This is a result of the cool design of http4s' DSL, and it would be interesting to exploit it :)

The http4s module is still useful for http4s-specific things like #69

Release 0.1.0

In response to how many changes have been introduced releasing a release candidate first with an expected release date at the beginning of next week assuming no problems are found.

Adopt Scala Code of Conduct

I believe that these projects should offer a friendly and safe space for working together. I am in the process of adding this to most of my libraries.

If you have comments to this regard, I would like to hear them and this issue will be a good place to field such discussions.

Change Signature of fromString

Currently Either[IllegalArgumentException, FUUID] I think that do to a level of distrusting java's checked exception this should be broadened to Either[Throwable, FUUID]

I appreciate thoughts on this.

StackOverflowError on .show method

Hi! It's seems like .show method is broken:

object FUUID {
  implicit val instancesFUUID: Hash[FUUID] with Order[FUUID] with Show[FUUID] = 
    new Hash[FUUID] with Order[FUUID] with Show[FUUID]{
      override def show(t: FUUID): String = t.show
...

it will fall to infinite recursion and end up with StackOverFlowError

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.