From 4b0d4747131988ce24df28dc4f7fe8f9bcec49b8 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Mon, 15 Aug 2022 09:55:38 -0700 Subject: [PATCH] Configured: define recoverWithOrCombine implicit --- .../shared/src/main/scala/metaconfig/ConfDecoder.scala | 2 +- .../shared/src/main/scala/metaconfig/ConfDecoderExT.scala | 4 +--- .../shared/src/main/scala/metaconfig/Configured.scala | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/ConfDecoder.scala b/metaconfig-core/shared/src/main/scala/metaconfig/ConfDecoder.scala index 094b107c..fe9e5e12 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/ConfDecoder.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/ConfDecoder.scala @@ -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)) } diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/ConfDecoderExT.scala b/metaconfig-core/shared/src/main/scala/metaconfig/ConfDecoderExT.scala index 5b27a934..dc0ac466 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/ConfDecoderExT.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/ConfDecoderExT.scala @@ -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 diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/Configured.scala b/metaconfig-core/shared/src/main/scala/metaconfig/Configured.scala index f3a8c43d..6a391d0f 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/Configured.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/Configured.scala @@ -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) } } }