diff --git a/main-settings/src/main/scala/sbt/Remove.scala b/main-settings/src/main/scala/sbt/Remove.scala index e09555f5b..6ab53e42b 100644 --- a/main-settings/src/main/scala/sbt/Remove.scala +++ b/main-settings/src/main/scala/sbt/Remove.scala @@ -34,4 +34,14 @@ object Remove { def removeValue(a: Seq[T], b: Option[T]): Seq[T] = b.fold(a)(a filterNot _.==) def removeValues(a: Seq[T], b: Option[T]): Seq[T] = b.fold(a)(a filterNot _.==) } + implicit def removeSet[T, V <: T]: Sequence[Set[T], Set[V], V] = + new Sequence[Set[T], Set[V], V] { + def removeValue(a: Set[T], b: V): Set[T] = a - b + def removeValues(a: Set[T], b: Set[V]): Set[T] = a diff (b.toSeq: Seq[T]).toSet + } + implicit def removeMap[A, B, X <: A]: Sequence[Map[A, B], Seq[X], X] = + new Sequence[Map[A, B], Seq[X], X] { + def removeValue(a: Map[A, B], b: X): Map[A, B] = a - b + def removeValues(a: Map[A, B], b: Seq[X]): Map[A, B] = a -- b + } } diff --git a/sbt-app/src/sbt-test/project/remove/build.sbt b/sbt-app/src/sbt-test/project/remove/build.sbt index d3ae2985d..5a16e59d8 100644 --- a/sbt-app/src/sbt-test/project/remove/build.sbt +++ b/sbt-app/src/sbt-test/project/remove/build.sbt @@ -1,6 +1,8 @@ val intsTask = taskKey[Seq[Int]]("A seq of ints task") val intsSetting = settingKey[Seq[Int]]("A seq of ints setting") val intsFromScalaV = settingKey[Seq[Int]]("a seq of ints from scalaVersion") +val intsSetSetting = settingKey[Set[Int]]("A set of ints setting") +val stringIntMapSetting = settingKey[Map[String, Int]]("A map of string to int setting") scalaVersion := "2.11.6" @@ -22,9 +24,19 @@ intsFromScalaV --= { if (scalaVersion.value == "2.11.6") Seq(1, 2) else Seq(4) } intsFromScalaV -= { if (scalaVersion.value == "2.11.6") Option(6) else None } intsFromScalaV --= { if (scalaVersion.value == "2.11.6") Option(7) else None } +intsSetSetting := Set(1, 2, 3, 4, 5, 6, 7) +intsSetSetting -= 3 +intsSetSetting --= Set(1, 2) + +stringIntMapSetting := Map("a" -> 1, "b" -> 2 , "c" -> 3, "d" -> 4, "e" -> 5) +stringIntMapSetting -= "c" +stringIntMapSetting --= Seq("a", "b") + val check = taskKey[Unit]("Runs the check") check := { assert(intsTask.value == Seq(4, 5), s"intsTask should be Seq(4, 5) but is ${intsTask.value}") assert(intsSetting.value == Seq(4, 5), s"intsSetting should be Seq(4, 5) but is ${intsSetting.value}") assert(intsFromScalaV.value == Seq(4, 5), s"intsFromScalaV should be Seq(4, 5) but is ${intsFromScalaV.value}") + assert(intsSetSetting.value == Set(4, 5, 6, 7), s"intsSetSetting should be Set(4, 5, 6, 7) but is ${intsSetSetting.value}") + assert(stringIntMapSetting.value == Map("d" -> 4, "e" -> 5), s"stringIntMapSetting should be Map(d -> 4, e -> 5) but is ${stringIntMapSetting.value}") }