Add intention for replacing explicit function literal parameter with 'it'
Kotlin's function literals have a shortcut for one-argument literals:
the single argument doesn't need to be explicitly named, but can be
referred via the 'it' contextual keyword.
For example, 'array(1, 2, 3).filter { x -> x % 2 == 0 }'
-> 'array(1, 2, 3).filter { it % 2 == 0 }'
Add an intention action for this transformation.
This commit is contained in:
committed by
Nikolay Krasko
parent
1dd57b5f6e
commit
c6d6a32314
+2
@@ -0,0 +1,2 @@
|
||||
fun foo(a: (Int) -> Int): Int = a(1)
|
||||
val x = foo { p -> foo { y -> <caret>p } }
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
fun foo(a: (Int) -> Int): Int = a(1)
|
||||
val x = foo { foo { y -> <caret>it } }
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
fun applyTwice<A>(f: (A) -> A, x: A) = f(f(x))
|
||||
val x = applyTwice({ <caret>x -> 1 + x }, 40)
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
fun applyTwice<A>(f: (A) -> A, x: A) = f(f(x))
|
||||
val x = applyTwice({ <caret>1 + it }, 40)
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
fun applyTwice<A>(f: (A) -> A, x: A) = f(f(x))
|
||||
val x = applyTwice({ x -> <caret>x + 1 }, 40)
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
fun applyTwice<A>(f: (A) -> A, x: A) = f(f(x))
|
||||
val x = applyTwice({ <caret>it + 1 }, 40)
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun foo(i: (Int) -> Unit) {}
|
||||
fun test() {
|
||||
foo { <caret>x ->
|
||||
array(1, 2, 3).filter { x -> x % 2 == 0 }
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun foo(i: (Int) -> Unit) {}
|
||||
fun test() {
|
||||
foo {
|
||||
<caret>array(1, 2, 3).filter { x -> x % 2 == 0 }
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
fun applyTwice<A>(f: (A) -> A, x: A) = f(f(x))
|
||||
val x = applyTwice({ i<caret>t + 1 }, 40)
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
fun call2(f: (Int, Int) -> Int, x: Int, y: Int) = f(x, y)
|
||||
val foo = call2({ <caret>x, y -> x + y }, 40, 2)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
val foo = { (x: Int) ->
|
||||
class Inner() {
|
||||
fun temp(<caret>y: Int) : Int { return x + y }
|
||||
}
|
||||
Inner()
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// IS_APPLICABLE: false
|
||||
val incr = { (<caret>x: Int) -> x + 1}
|
||||
Reference in New Issue
Block a user