Skip to content

Commit 5147101

Browse files
committed
ConfOps.merge: filter out empty values
1 parent cd0a7bb commit 5147101

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

metaconfig-core/shared/src/main/scala/metaconfig/Conf.scala

+7-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ object Conf {
107107
object Obj {
108108
type Elem = (String, Conf)
109109
val empty: Obj = Obj(Nil)
110-
def apply(values: Elem*): Obj = Obj(values.toList)
110+
def apply(values: Elem*): Obj =
111+
if (values.isEmpty) empty else Obj(values.toList)
111112
}
112113

113114
def getEx[A](state: A, conf: Conf, path: Seq[String])(implicit
@@ -264,7 +265,11 @@ object ConfOps {
264265
Iterable.concat(elemsA, elemsB).foldLeft(List.empty[Obj.Elem]) {
265266
case (merged, elemB @ (key, valB)) => merged
266267
.collectFirst { case (`key`, valA) =>
267-
(key -> merge(valA, valB)) :: merged.filter(_._1 != key)
268+
val filtered = merged.filter(_._1 != key)
269+
merge(valA, valB) match {
270+
case Conf.Obj(Nil) => filtered
271+
case x => (key -> x) :: filtered
272+
}
268273
}.getOrElse(elemB :: merged)
269274
},
270275
)

metaconfig-tests/jvm/src/test/scala/metaconfig/PatchSuite.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class PatchSuite extends munit.FunSuite {
3333
test("patch with key and empty val: delete") {
3434
val initial = Conf.Obj("a" -> Conf.Num(0), "b" -> Conf.Str("1"))
3535
val patched = Conf.applyPatch(initial, Conf.Obj("a" -> Conf.Obj.empty))
36-
assertEquals(patched, Conf.Obj("a" -> Conf.Obj.empty, "b" -> Conf.Str("1")))
36+
assertEquals(patched, Conf.Obj("b" -> Conf.Str("1")))
3737
}
3838

3939
}

0 commit comments

Comments
 (0)