Cleanup: apply "Convert lambda to reference"

This commit is contained in:
Mikhail Glukhikh
2017-02-22 16:12:01 +03:00
parent b121bf8802
commit 045a23ae10
82 changed files with 117 additions and 135 deletions
@@ -126,7 +126,7 @@ internal fun File.toComponents(): FilePathComponents {
val rootLength = path.getRootLength()
val rootName = path.substring(0, rootLength)
val subPath = path.substring(rootLength)
val list = if (subPath.isEmpty()) listOf() else subPath.split(File.separatorChar).map { File(it) }
val list = if (subPath.isEmpty()) listOf() else subPath.split(File.separatorChar).map(::File)
return FilePathComponents(File(rootName), list)
}
@@ -95,7 +95,7 @@ public fun File.relativeTo(base: File): File = File(this.toRelativeString(base))
* @return File with relative path from [base] to this, or `this` if this and base paths have different roots.
*/
public fun File.relativeToOrSelf(base: File): File
= toRelativeStringOrNull(base)?.let { File(it) } ?: this
= toRelativeStringOrNull(base)?.let(::File) ?: this
/**
* Calculates the relative path for this file from [base] file.
@@ -105,7 +105,7 @@ public fun File.relativeToOrSelf(base: File): File
* @return File with relative path from [base] to this, or `null` if this and base paths have different roots.
*/
public fun File.relativeToOrNull(base: File): File?
= toRelativeStringOrNull(base)?.let { File(it) }
= toRelativeStringOrNull(base)?.let(::File)
private fun File.toRelativeStringOrNull(base: File): String? {
+2 -2
View File
@@ -74,8 +74,8 @@ public fun String.replaceIndent(newIndent: String = ""): String {
val lines = lines()
val minCommonIndent = lines
.filter { it.isNotBlank() }
.map { it.indentWidth() }
.filter(String::isNotBlank)
.map(String::indentWidth)
.min() ?: 0
return lines.reindent(length + newIndent.length * lines.size, getIndentFunction(newIndent), { line -> line.drop(minCommonIndent) })
+3 -3
View File
@@ -125,7 +125,7 @@ public fun String.trimEnd(vararg chars: Char): String = trimEnd { it in chars }
/**
* Returns a sub sequence of this char sequence having leading and trailing whitespace trimmed.
*/
public fun CharSequence.trim(): CharSequence = trim { it.isWhitespace() }
public fun CharSequence.trim(): CharSequence = trim(Char::isWhitespace)
/**
* Returns a string with leading and trailing whitespace trimmed.
@@ -136,7 +136,7 @@ public inline fun String.trim(): String = (this as CharSequence).trim().toString
/**
* Returns a sub sequence of this char sequence having leading whitespace removed.
*/
public fun CharSequence.trimStart(): CharSequence = trimStart { it.isWhitespace() }
public fun CharSequence.trimStart(): CharSequence = trimStart(Char::isWhitespace)
/**
* Returns a string with leading whitespace removed.
@@ -147,7 +147,7 @@ public inline fun String.trimStart(): String = (this as CharSequence).trimStart(
/**
* Returns a sub sequence of this char sequence having trailing whitespace removed.
*/
public fun CharSequence.trimEnd(): CharSequence = trimEnd { it.isWhitespace() }
public fun CharSequence.trimEnd(): CharSequence = trimEnd(Char::isWhitespace)
/**
* Returns a string with trailing whitespace removed.
@@ -132,7 +132,7 @@ internal constructor(private val nativePattern: Pattern) {
/**
* Returns a sequence of all occurrences of a regular expression within the [input] string, beginning at the specified [startIndex].
*/
public fun findAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult> = generateSequence({ find(input, startIndex) }, { match -> match.next() })
public fun findAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult> = generateSequence({ find(input, startIndex) }, MatchResult::next)
/**
* Attempts to match the entire [input] CharSequence against the pattern.