Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #104 from sbuzzard/make_optional_codec_implicit
Browse files Browse the repository at this point in the history
Added an implicit function from Codec[A] to Option[Codec[A]] - I left…
  • Loading branch information
stew committed Apr 1, 2016
2 parents 2dc8b8f + cdf5ba8 commit 1166700
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/src/main/scala/codecs/codecs.scala
Expand Up @@ -86,9 +86,11 @@ package object codecs extends lowerprioritycodecs {

private def empty: Codec[Unit] = C.provide(())

def optional[A](target: Codec[A]): Codec[Option[A]] =
either(empty, target).
xmap[Option[A]](_.toOption, _.toRightDisjunction(()))
@deprecated("Use the implicit `Option[A]` resolution provided by this package instead.", "1.4.3")
def optional[A](target: Codec[A]): Codec[Option[A]] = option(Lazy(target))

implicit def option[A](implicit LCA: Lazy[Codec[A]]): Codec[Option[A]] =
either(empty, LCA.value).xmap[Option[A]](_.toOption, _.toRightDisjunction(()))

implicit def list[A](implicit LCA: Lazy[Codec[A]]): Codec[List[A]] =
indexedSeq[A].xmap[List[A]](
Expand Down

0 comments on commit 1166700

Please sign in to comment.