Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #20 from travisbrown/topic/clean-up
Miscellaneous additions and a lot of clean-up
  • Loading branch information
travisbrown committed Aug 9, 2015
2 parents 388d094 + b08228d commit 764afc2
Show file tree
Hide file tree
Showing 52 changed files with 1,812 additions and 1,488 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -6,4 +6,5 @@ target/
.cache
.settings
.project
.classpath
.classpath
tmp/
38 changes: 18 additions & 20 deletions README.md
Expand Up @@ -16,7 +16,7 @@ The name stands for "JSON for [cats][cats]" and is a working title that
Type `sbt console` to start a REPL in the root project, and then paste the following:

```scala
scala> import io.jfc._, io.jfc.auto._, io.jfc.jawn._, io.jfc.syntax._
scala> import io.jfc._, io.jfc.generic.auto._, io.jfc.jawn._, io.jfc.syntax._
import io.jfc._
import io.jfc.auto._
import io.jfc.jawn._
Expand Down Expand Up @@ -56,9 +56,9 @@ jfc depends on [cats][cats] instead of [Scalaz][scalaz], and cats is the only de
`core` project.

Other subprojects bring in dependencies on [Jawn][jawn] (for parsing in the [`jawn`][jfc-jawn]
subproject), [Shapeless][shapeless] (for automatic codec derivation in [`auto`][jfc-auto]), and
[Twitter Util][util] (for tools for asynchronous parsing in `async`), but it would be possible to
replace the functionality provided by these subprojects with alternative implementations that use
subproject), [Shapeless][shapeless] (for automatic codec derivation in [`generic`][jfc-generic]),
and [Twitter Util][util] (for tools for asynchronous parsing in `async`), but it would be possible
to replace the functionality provided by these subprojects with alternative implementations that use
other libraries.

### Parsing
Expand All @@ -79,15 +79,13 @@ gets ported to cats.

jfc does not use macros or provide any kind of automatic derivation in the `core` project. Instead
of Argonaut's limited macro-based derivation (which does not support sealed trait hierarchies, for
example), jfc includes a subproject (`auto`) that provides generic codec derivation using
example), jfc includes a subproject (`generic`) that provides generic codec derivation using
[Shapeless][shapeless].

[This subproject][jfc-auto] is currently a simplified port of
[argonaut-shapeless][argonaut-shapeless] that provides fully-automatic derivation of instances for
tuples, case classes, and sealed trait hierarchies. It also includes derivation of "incomplete" case classes (see my recent [blog post][incompletes] for details).

We may eventually include an additional subproject with less automatic, more
customizable codec derivation.
[This subproject][jfc-generic] is currently a simplified port of
[argonaut-shapeless][argonaut-shapeless] that provides fully automatic derivation of instances for
tuples, case classes, and sealed trait hierarchies. It also includes derivation of "incomplete" case
classes (see my recent [blog post][incompletes] for details).

### Aliases

Expand Down Expand Up @@ -182,19 +180,19 @@ This section needs a lot of expanding.

### Encoding and decoding

jfc uses `Encode` and `Decode` type classes for encoding and decoding. An `Encode[A]` instance
provides a function that will convert any `A` to a `JSON`, and a `Decode[A]` takes a `Json` value to
either an exception or an `A`. jfc provides implicit instances of these type classes for many types
from the Scala standard library, including `Int`, `String`, and [others][encode]. It also provides
instances for `List[A]`, `Option[A]`, and other generic types, but only if `A` has an `Encode`
instance.
jfc uses `Encoder` and `Decoder` type classes for encoding and decoding. An `Encoder[A]` instance
provides a function that will convert any `A` to a `JSON`, and a `Decoder[A]` takes a `Json` value
to either an exception or an `A`. jfc provides implicit instances of these type classes for many
types from the Scala standard library, including `Int`, `String`, and [others][encoder]. It also
provides instances for `List[A]`, `Option[A]`, and other generic types, but only if `A` has an
`Encoder` instance.

### Transforming JSON

Suppose we have the following JSON document:

```scala
import io.jfc._, io.jfc.auto._, io.jfc.jawn._, io.jfc.syntax._
import io.jfc._, io.jfc.generic.auto._, io.jfc.jawn._, io.jfc.syntax._
import cats.data.Xor

val json: String = """
Expand Down Expand Up @@ -263,12 +261,12 @@ limitations under the License.
[benchmarks]: https://github.com/travisbrown/circe/blob/topic/plugins/benchmark/src/main/scala/io/jfc/benchmark/Benchmark.scala
[cats]: https://github.com/non/cats
[discipline]: https://github.com/typelevel/discipline
[encode]: https://travisbrown.github.io/circe/api/#io.jfc.Encode$
[encoder]: https://travisbrown.github.io/circe/api/#io.jfc.Encoder$
[finch]: https://github.com/finagle/finch
[generic-cursor]: https://travisbrown.github.io/circe/api/#io.jfc.GenericCursor
[incompletes]: https://meta.plasm.us/posts/2015/06/21/deriving-incomplete-type-class-instances/
[jawn]: https://github.com/non/jawn
[jfc-auto]: https://travisbrown.github.io/circe/api/#io.jfc.auto.package
[jfc-generic]: https://travisbrown.github.io/circe/api/#io.jfc.generic.auto$
[jfc-jawn]: https://travisbrown.github.io/circe/api/#io.jfc.jawn.package
[markhibberd]: https://github.com/markhibberd
[monocle]: https://github.com/julien-truffaut/Monocle
Expand Down
31 changes: 0 additions & 31 deletions auto/src/main/scala/io/jfc/auto/ArrayDecode.scala

This file was deleted.

21 changes: 0 additions & 21 deletions auto/src/main/scala/io/jfc/auto/ArrayEncode.scala

This file was deleted.

46 changes: 0 additions & 46 deletions auto/src/main/scala/io/jfc/auto/GenericDecode.scala

This file was deleted.

41 changes: 0 additions & 41 deletions auto/src/main/scala/io/jfc/auto/GenericEncode.scala

This file was deleted.

35 changes: 0 additions & 35 deletions auto/src/main/scala/io/jfc/auto/package.scala

This file was deleted.

82 changes: 0 additions & 82 deletions auto/src/test/scala/io/jfc/auto/GenericCodecTests.scala

This file was deleted.

6 changes: 3 additions & 3 deletions benchmark/src/main/scala/io/jfc/benchmark/Benchmark.scala
@@ -1,8 +1,8 @@
package io.jfc.benchmark

import argonaut.{ Json => JsonA, _ }, Argonaut._
import io.jfc.{ Json => JsonJ, Encode }
import io.jfc.auto._
import io.jfc.{ Json => JsonJ, Encoder }
import io.jfc.generic.auto._
import io.jfc.jawn._
import java.util.concurrent.TimeUnit
import org.openjdk.jmh.annotations._
Expand All @@ -21,7 +21,7 @@ class ExampleData {
}.toMap

@inline def encodeA[A](a: A)(implicit encode: EncodeJson[A]): JsonA = encode(a)
@inline def encodeJ[A](a: A)(implicit encode: Encode[A]): JsonJ = encode(a)
@inline def encodeJ[A](a: A)(implicit encode: Encoder[A]): JsonJ = encode(a)

val intsJ: JsonJ = encodeJ(ints)
val intsA: JsonA = encodeA(ints)
Expand Down

0 comments on commit 764afc2

Please sign in to comment.