Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iravid/play-json-cats
cats typeclass instances for play-json
https://github.com/iravid/play-json-cats
cats functional-programming json play-json scala
Last synced: 3 months ago
JSON representation
cats typeclass instances for play-json
- Host: GitHub
- URL: https://github.com/iravid/play-json-cats
- Owner: iravid
- License: apache-2.0
- Created: 2017-01-23T18:54:30.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-03-11T22:12:05.000Z (almost 5 years ago)
- Last Synced: 2024-04-01T01:50:19.166Z (10 months ago)
- Topics: cats, functional-programming, json, play-json, scala
- Language: Scala
- Homepage:
- Size: 37.1 KB
- Stars: 6
- Watchers: 2
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/iravid/play-json-cats.svg?branch=master)](https://travis-ci.org/iravid/play-json-cats)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.iravid/play-json-cats_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.iravid/play-json-cats_2.12)# play-json-cats
`cats` typeclass instances for the `play-json` library.
## Adding as a dependency to your project
```scala
libraryDependencies += "com.iravid" %% "play-json-cats" % 1.1.0
````play-json-cats` is cross-published for Scala 2.11 and 2.12.
## Usage
```scala
import cats.implicits._
import com.iravid.playjsoncats.implicits._
import play.api.libs.json._case class Person(name: String, i: Int)
val rn: Reads[String] = Reads(j => (j \ "name").validate[String])
val ri: Reads[Int] = Reads(j => (j \ "i").validate[Int])
val rp: Reads[Person] = (rn, rp).mapN(Person)val res: JsResult[Person] = rp.reads(Json.parse("""
{ "name": "iravid", "i": 42 }
"""))
```## Provided instances
| `play-json` type | provided instances |
|------------------|-----------------------------------------------|
| `Reads[A]` | `Functor`, `Applicative`, `Monad` |
| `Writes[A]` | `Contravariant` |
| `Format[A]` | `Invariant` |
| `JsResult[A]` | `Functor`, `Applicative`, `ApplicativeError` |
| | `Monad`, `MonadError`, `Traverse`, |
| | `Monoid` (for `A: Monoid`) |