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 Issues

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.

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.

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.

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.

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

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.

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.

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

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.

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)

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

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.

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.