Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/shared/src/main/scala/monix/newtypes/HasBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ package monix.newtypes
*
* @see [[HasExtractor]] for deriving encoders.
*/
trait HasBuilder[Type] {
trait HasBuilder[Type, +Failure <: BuildFailure[Type]] {
type Source

def build(value: Source): Either[BuildFailure[Type], Type]
def build(value: Source): Either[Failure, Type]
}

object HasBuilder {
type Aux[T, S] = HasBuilder[T] { type Source = S }
type Aux[T, +F <: BuildFailure[T], S] = HasBuilder[T, F] { type Source = S }

def apply[T](implicit ev: HasBuilder[T]): ev.type = ev
def apply[T, F <: BuildFailure[T]](implicit ev: HasBuilder[T, F]): ev.type = ev
}

/**
Expand Down
4 changes: 2 additions & 2 deletions core/shared/src/main/scala/monix/newtypes/NewValidated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ private[newtypes] trait NewValidated[Src] { self: NewEncoding[Src] =>
final def unapply[A](a: A)(implicit ev: A =:= Type): Some[Src] =
Some(ev(a).value)

implicit final val builder: HasBuilder.Aux[Type, Src] =
new HasBuilder[Type] {
implicit final val builder: HasBuilder.Aux[Type, BuildFailure[Type], Src] =
new HasBuilder[Type, BuildFailure[Type]] {
type Source = Src
def build(value: Src): Either[BuildFailure[Type], Type] = apply(value)
}
Expand Down
4 changes: 2 additions & 2 deletions core/shared/src/main/scala/monix/newtypes/NewWrapped.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ private[newtypes] trait NewWrapped[Src] { self: NewEncoding[Src] =>
final def unapply[A](a: A)(implicit ev: A =:= Type): Some[Src] =
Some(value(ev(a)))

implicit final val builder: HasBuilder.Aux[Type, Src] =
new HasBuilder[Type] {
implicit final val builder: HasBuilder.Aux[Type, Nothing, Src] =
new HasBuilder[Type, Nothing] {
type Source = Src
def build(value: Src) = Right(apply(value))
}
Expand Down
4 changes: 2 additions & 2 deletions core/shared/src/main/scala/monix/newtypes/Newtype.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ package monix.newtypes
*
* // Recommended instance, but not required;
* // use Newtype.Validated to get rid of this boilerplate ;-)
* implicit val builder: HasBuilder.Aux[EmailAddress, String] =
* new HasBuilder[EmailAddress] {
* implicit val builder: HasBuilder.Aux[EmailAddress, String, BuildFailure[Type]] =
* new HasBuilder[EmailAddress, BuildFailure[Type]] {
* type Source = String
*
* def build(v: String): Either[BuildFailure[Type], Type] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ trait DerivedCirceCodec extends DerivedCirceEncoder with DerivedCirceDecoder
*/
trait DerivedCirceDecoder {
implicit def jsonDecoder[T, S](implicit
builder: HasBuilder.Aux[T, S],
builder: HasBuilder.Aux[T, BuildFailure[T], S],
dec: Decoder[S],
): Decoder[T] = {
jsonDecode(_)
}

protected def jsonDecode[T, S](c: HCursor)(implicit
builder: HasBuilder.Aux[T, S],
builder: HasBuilder.Aux[T, BuildFailure[T], S],
dec: Decoder[S],
): Decoder.Result[T] =
dec.apply(c).flatMap { value =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ object NewtypeKCirceCodecSuite {
def apply[A](first: A, rest: List[A]): Type[A] =
unsafeCoerce(first :: rest)

implicit final def builder[A: TypeInfo]: HasBuilder.Aux[Type[A], List[A]] =
new HasBuilder[Type[A]] {
implicit final def builder[A: TypeInfo]: HasBuilder.Aux[Type[A], BuildFailure[Type[A]], List[A]] =
new HasBuilder[Type[A], BuildFailure[Type[A]]] {
type Source = List[A]

override def build(value: List[A]): Either[BuildFailure[Type[A]], Type[A]] =
Expand All @@ -105,8 +105,8 @@ object NewtypeKCirceCodecSuite {
def apply[A](first: A, rest: List[A]): Type[A] =
unsafeCoerce(first :: rest)

implicit final def builder[A: TypeInfo]: HasBuilder.Aux[Type[A], List[A]] =
new HasBuilder[Type[A]] {
implicit final def builder[A: TypeInfo]: HasBuilder.Aux[Type[A], BuildFailure[Type[A]], List[A]] =
new HasBuilder[Type[A], BuildFailure[Type[A]]] {
type Source = List[A]

override def build(value: List[A]): Either[BuildFailure[Type[A]], Type[A]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ trait DerivedPureConfigConvert extends DerivedPureConfigReader with DerivedPureC
*/
trait DerivedPureConfigReader {
implicit def pureConfigReader[T, S](implicit
builder: HasBuilder.Aux[T, S],
builder: HasBuilder.Aux[T, BuildFailure[T], S],
reader: ConfigReader[S],
): ConfigReader[T] = {
reader.emap { value =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ object NewtypeKCirceCodecSuite {
def apply[A](first: A, rest: List[A]): Type[A] =
unsafeCoerce(first :: rest)

implicit final def builder[A: TypeInfo]: HasBuilder.Aux[Type[A], List[A]] =
new HasBuilder[Type[A]] {
implicit final def builder[A: TypeInfo]: HasBuilder.Aux[Type[A], BuildFailure[Type[A]], List[A]] =
new HasBuilder[Type[A], BuildFailure[Type[A]]] {
type Source = List[A]

override def build(value: List[A]): Either[BuildFailure[Type[A]], Type[A]] =
Expand All @@ -65,8 +65,8 @@ object NewtypeKCirceCodecSuite {
def apply[A](first: A, rest: List[A]): Type[A] =
unsafeCoerce(first :: rest)

implicit final def builder[A: TypeInfo]: HasBuilder.Aux[Type[A], List[A]] =
new HasBuilder[Type[A]] {
implicit final def builder[A: TypeInfo]: HasBuilder.Aux[Type[A], BuildFailure[Type[A]], List[A]] =
new HasBuilder[Type[A], BuildFailure[Type[A]]] {
type Source = List[A]

override def build(value: List[A]): Either[BuildFailure[Type[A]], Type[A]] =
Expand Down
2 changes: 1 addition & 1 deletion site/src/mdoc/docs/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ included):

```scala mdoc:silent
implicit def jsonDecoder[T, S](implicit
builder: HasBuilder.Aux[T, S],
builder: HasBuilder.Aux[T, BuildFailure[T], S],
dec: Decoder[S],
): Decoder[T] = (c: HCursor) => {
dec.apply(c).flatMap { value =>
Expand Down