Skip to content

Commit

Permalink
Configured: define recoverWithOrCombine implicit
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Aug 16, 2022
1 parent 97160f7 commit 4b0d474
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ object ConfDecoder {
CanBuildFromDecoder.list[C, A]

def orElse[A](a: ConfDecoder[A], b: ConfDecoder[A]): ConfDecoder[A] =
conf => a.read(conf).recoverWith(x => b.read(conf).recoverWith(x.combine))
conf => a.read(conf).recoverWithOrCombine(b.read(conf))

}
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ object ConfDecoderExT {

def orElse(other: ConfDecoderExT[S, A]): ConfDecoderExT[S, A] =
(state, conf) =>
self.read(state, conf).recoverWith { x =>
other.read(state, conf).recoverWith(x.combine)
}
self.read(state, conf).recoverWithOrCombine(other.read(state, conf))

def noTypos(implicit settings: generic.Settings[A]): ConfDecoderExT[S, A] =
if (self.isInstanceOf[NoTyposDecoderEx[_, _]]) self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ object Configured extends ConfiguredLowPriorityImplicits {
def foreach(fa: ConfError => Unit)(fb: A => Unit): Unit =
fold(fa)(fb)

def recoverWithOrCombine[B >: A](f: => Configured[B]): Configured[B] =
value.recoverWith { x => f.recoverWith(x.combine) }
}

}

0 comments on commit 4b0d474

Please sign in to comment.