avoid unnecessary verbose type parameters now the type inferencer is better

This commit is contained in:
James Strachan
2012-08-17 09:44:52 +01:00
parent a4e80c7d5d
commit ecbd4daefb
10 changed files with 14 additions and 32 deletions
+1 -1
View File
@@ -333,7 +333,7 @@ fun NodeList?.toXmlString(xmlDeclaration: Boolean = false): String {
/** Converts the collection of nodes to an XML String */
public fun nodesToXmlString(nodes: Iterable<Node>, xmlDeclaration: Boolean = false): String {
// TODO this should work...
// return this.map<Node,String>{it.toXmlString()}.makeString("")
// return this.map{it.toXmlString()}.makeString("")
val builder = StringBuilder()
for (n in nodes) {
builder.append(n.toXmlString(xmlDeclaration))
+1 -1
View File
@@ -110,7 +110,7 @@ get() = childNodes.outerHTML
* Returns the HTML representation of the nodes
*/
public val NodeList.outerHTML: String
get() = toList().map<Node, String> { it.innerHTML }.makeString("")
get() = toList().map { it.innerHTML }.makeString("")
/** Returns an [[Iterator]] of all the next [[Element]] siblings */
fun Node.nextElements(): Iterator<Element> = nextSiblings().filterIsInstance<Node, Element>(javaClass<Element>())
+3 -8
View File
@@ -132,7 +132,7 @@ class CollectionTest {
// lets concatenate some strings
expect("1234") {
val numbers = arrayList(1, 2, 3, 4)
numbers.map<Int, String>{it.toString()}.fold(""){ a, b -> a + b}
numbers.map{it.toString()}.fold(""){ a, b -> a + b}
}
}
@@ -146,7 +146,7 @@ class CollectionTest {
test fun foldRight() {
expect("1234") {
val numbers = arrayList(1, 2, 3, 4)
numbers.map<Int, String>{it.toString()}.foldRight(""){ a, b -> a + b}
numbers.map{it.toString()}.foldRight(""){ a, b -> a + b}
}
}
@@ -198,14 +198,9 @@ class CollectionTest {
assertEquals("a, b, c, *", text2)
}
/*
TODO compiler bug
we should be able to remove the explicit type <String,Int> on the map function
http://youtrack.jetbrains.net/issue/KT-1145
*/
test fun map() {
val data = arrayList("foo", "bar")
val lengths = data.map<String, Int>{ it.length }
val lengths = data.map{ it.length }
assertTrue {
lengths.all{it == 3}
}
+2 -12
View File
@@ -80,33 +80,23 @@ class MapTest {
assertEquals("beverage,beer,location,Mells,name,James", list.makeString(","))
}
/*
TODO compiler bug
we should be able to remove the explicit type <String,String,String> on the map function
http://youtrack.jetbrains.net/issue/KT-1145
*/
test fun map() {
val m1 = TreeMap<String, String>()
m1["beverage"] = "beer"
m1["location"] = "Mells"
val list = m1.map<String,String,String>{ it.value + " rocks" }
val list = m1.map{ it.value + " rocks" }
println("Got new list $list")
assertEquals(arrayList("beer rocks", "Mells rocks"), list)
}
/*
TODO compiler bug
we should be able to remove the explicit type <String,String,String> on the mapValues function
http://youtrack.jetbrains.net/issue/KT-1145
*/
test fun mapValues() {
val m1 = TreeMap<String, String>()
m1["beverage"] = "beer"
m1["location"] = "Mells"
val m2 = m1.mapValues<String,String,String>{ it.value + "2" }
val m2 = m1.mapValues{ it.value + "2" }
println("Got new map $m2")
assertEquals(arrayList("beer2", "Mells2"), m2.values().toList())
+1 -1
View File
@@ -54,7 +54,7 @@ class SetTest {
we should be able to remove the explicit type on the function
http://youtrack.jetbrains.net/issue/KT-849
*/
val lengths = data.map<String, Int>{(s: String) -> s.length}
val lengths = data.map{s -> s.length}
assertTrue {
lengths.all{it == 3}
}
+2 -2
View File
@@ -113,7 +113,7 @@ class MapJsTest {
m1["beverage"] = "beer"
m1["location"] = "Mells"
val list = m1.map<String,String,String>{ it.value + " rocks" }
val list = m1.map{ it.value + " rocks" }
println("Got new list $list")
assertEquals(arrayList("beer rocks", "Mells rocks"), list)
@@ -124,7 +124,7 @@ class MapJsTest {
m1["beverage"] = "beer"
m1["location"] = "Mells"
val m2 = m1.mapValues<String,String,String>{ it.value + "2" }
val m2 = m1.mapValues{ it.value + "2" }
println("Got new map $m2")
assertEquals(arrayList("beer2", "Mells2"), m2.values().toList())
@@ -17,7 +17,7 @@ fun customerTemplate(customer: Customer) = """
<body>
<h1>Hello ${customer.name}</h1>
<ul>
${customer.products.map<Product,String>{ productSnippet(it) }.makeString("\n")}
${customer.products.map{ productSnippet(it) }.makeString("\n")}
</ul>
<p>lets do some kool stuff</p>
</body>
@@ -105,11 +105,8 @@ class OptionTest: TestCase() {
*/
val name = request.getParameter("name")
val upper = name.map<String, String>{ it.trim() }.filter{ it.length != 0 }.map<String, String>{ it.toUpperCase() }
val upper = name.map{ it.trim() }.filter{ it.length != 0 }.map{ it.toUpperCase() }
return upper ?: ""
// TODO when http://youtrack.jetbrains.com/issue/KT-1145 is fixed
// we can get rid of the unnecessary <String, String> on map
}
assertEquals("", foo(Request(null)))
@@ -144,7 +144,7 @@ import js.noImpl
// TODO in java 7 its not easy with reflection to get the parameter argument name...
var counter = 0
val parameters = parameterTypes.map<Class<out Any?>?, String>{ "arg${++counter}: ${parameterTypeName(it)}" }.makeString(", ")
val parameters = parameterTypes.map{ "arg${++counter}: ${parameterTypeName(it)}" }.makeString(", ")
val returnType = simpleTypeName(method.getReturnType())
println(" public fun ${method.getName()}($parameters): $returnType = js.noImpl")
}
@@ -12,7 +12,7 @@ class Kt1617Test: TestCase() {
fun testMapFunction() {
val coll: Collection<String> = arrayList("foo", "bar")
val files = coll.map<String, File>{ File(it) }
val files = coll.map{ File(it) }
println("Found files: $files")
}