//map源碼
fun <T, R> List<T>.map1(transform: (T) -> R): List<R> {
val result = arrayListOf<R>()
for (item in this)
result.add(transform(item))
return result
}
//演示list
var ints = asList(1, 10, 20, 30)
val doubledList = ints.map { it -> it * 2 }
println("double list:"+doubledList);
// index =0 item[0]=1 1*2=2 2. 20 .40 60 double list:[2, 20, 40, 60]
//高級一點的
val fruits = listOf("banana", "avocado", "apple", "kiwi","bbaaaa")
fruits
.sortedBy {it }
.filter { it.startsWith("a") }//只需要a開頭的
.map { it.toUpperCase() }//all upper//并轉(zhuǎn)換為大寫
.forEach { println("current ${it}") }//after print
//上面的高階順序基本上不可以調(diào)整否則語法報錯