Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Reads and Writes for NonEmptyList #7

Open
Billzabob opened this issue Mar 11, 2020 · 0 comments
Open

Add Reads and Writes for NonEmptyList #7

Billzabob opened this issue Mar 11, 2020 · 0 comments

Comments

@Billzabob
Copy link

It seems like this project is all about adding cats type classes to play json types. Would it make sense to also add Reads and Writes to cats data types in here? For example, NonEmptyList?
For example:

implicit def nonEmptyListReads[A: Reads]: Reads[NonEmptyList[A]] = Reads {
    case JsArray(values) =>
      values.toList match {
        case head :: tail => NonEmptyList(head, tail).traverse(_.validate[A])
        case Nil => JsError("Expected a NonEmptyList but got an empty list")
      }
    case other =>
      JsError(s"expected an array but got $other")
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant