Add an Append.Sequence instance for List, fixes #2107

This commit is contained in:
Pierre DAL-PRA 2015-07-18 00:57:01 +02:00
parent 5824ef6d7f
commit 10c71b3f8a
3 changed files with 34 additions and 3 deletions

View File

@ -23,6 +23,14 @@ object Append {
def appendValues(a: Seq[T], b: Seq[V]): Seq[T] = a ++ (b map { x => (x: T) }) def appendValues(a: Seq[T], b: Seq[V]): Seq[T] = a ++ (b map { x => (x: T) })
def appendValue(a: Seq[T], b: V): Seq[T] = a :+ (b: T) def appendValue(a: Seq[T], b: V): Seq[T] = a :+ (b: T)
} }
implicit def appendList[T, V <: T]: Sequence[List[T], List[V], V] = new Sequence[List[T], List[V], V] {
def appendValues(a: List[T], b: List[V]): List[T] = a ::: b
def appendValue(a: List[T], b: V): List[T] = a :+ b
}
implicit def appendListImplicit[T, V <% T]: Sequence[List[T], List[V], V] = new Sequence[List[T], List[V], V] {
def appendValues(a: List[T], b: List[V]): List[T] = a ::: (b map { x => (x: T) })
def appendValue(a: List[T], b: V): List[T] = a :+ (b: T)
}
implicit def appendString: Value[String, String] = new Value[String, String] { implicit def appendString: Value[String, String] = new Value[String, String] {
def appendValue(a: String, b: String) = a + b def appendValue(a: String, b: String) = a + b
} }
@ -47,4 +55,4 @@ object Append {
def appendValues(a: Map[A, B], b: Map[X, Y]): Map[A, B] = a ++ b def appendValues(a: Map[A, B], b: Map[X, Y]): Map[A, B] = a ++ b
def appendValue(a: Map[A, B], b: (X, Y)): Map[A, B] = a + b def appendValue(a: Map[A, B], b: (X, Y)): Map[A, B] = a + b
} }
} }

View File

@ -13,7 +13,7 @@ import complete.{ DefaultParsers, Parsers }
val x = task { set.value } val x = task { set.value }
val y = task { true } val y = task { true }
val z = task { if(y.value) x.value else plain.value } val z = task { if(y.value) x.value else plain.value }
val a = taskDyn { val a = taskDyn {
if(y.value) z else x if(y.value) z else x
} }
}*/ }*/
@ -38,6 +38,8 @@ object Assign {
val dummy3 = settingKey[complete.Parser[(String, Int)]]("dummy3") val dummy3 = settingKey[complete.Parser[(String, Int)]]("dummy3")
val tsk: complete.Parser[Task[String]] = ??? val tsk: complete.Parser[Task[String]] = ???
val itsk: Initialize[InputTask[Int]] = ??? val itsk: Initialize[InputTask[Int]] = ???
val seqSetting = settingKey[Seq[String]]("seqSetting")
val listSetting = settingKey[List[String]]("listSetting")
/* def azy = sk.value /* def azy = sk.value
@ -100,4 +102,14 @@ object Assign {
def forallIn[T](key: Initialize[T]): Initialize[Seq[T]] = Def.setting { def forallIn[T](key: Initialize[T]): Initialize[Seq[T]] = Def.setting {
key.value :: Nil key.value :: Nil
} }
}
// Test that Append.Sequence instances for Seq/List work and don't mess up with each other
seqSetting := Seq("test1")
seqSetting ++= Seq("test2")
seqSetting ++= List("test3")
seqSetting += "test4"
listSetting := List("test1")
listSetting ++= List("test2")
listSetting += "test4"
}

View File

@ -0,0 +1,11 @@
[@pdalpra]: http://github.com/pdalpra
[2107]: https://github.com/sbt/sbt/issues/2107
[2114]: https://github.com/sbt/sbt/pull/2114
### Fixes with compatibility implications
### Improvements
### Bug fixes
- Add an Append.Sequence instance for List, allow +=/++= on `developers` SettingKey [#2107][2107]/[#2114][2114] by [@pdalpra][@pdalpra]