Package-level declarations

Types

Link copied to clipboard
sealed class CaseMatcher(val regex: Regex)

https://gist.github.com/SuppieRK/a6fb471cf600271230c8c7e532bdae4b

Link copied to clipboard

Supports the regex builder function.

Properties

Link copied to clipboard

replace with ·

Link copied to clipboard

replace with ·

Link copied to clipboard

replace · with

Link copied to clipboard

replace · with

Functions

Link copied to clipboard
fun <K : Any, T : Any> Map<K, Collection<T>>.allValues(): List<T>

shorthand for values.flatten().distinct()

Link copied to clipboard
inline fun <T> T.alsoIf(predicate: Boolean, body: (T) -> Unit): T

Conditionally applies the provided transformation function to the receiver object if the predicate is true and returns the result. If the predicate is false, the receiver object itself is returned.

Link copied to clipboard
inline fun <T> T.applyEach(vararg blocks: T.() -> Unit): T
inline fun <T> T.applyEach(blocks: Iterable<T.() -> Unit>): T

Applies the given blocks to the receiver object.

inline fun <T, E> T.applyEach(elements: Iterable<E>, block: T.(e: E) -> Unit): T

Applies the given block to each element in the iterable and returns the receiver object.

Link copied to clipboard
inline fun <T, E> T.applyEachIndexed(elements: Array<E>, block: T.(index: Int, e: E) -> Unit): T
inline fun <T, E> T.applyEachIndexed(elements: Iterable<E>, block: T.(index: Int, e: E) -> Unit): T

Applies the given block to each element in the iterable and returns the receiver object.

Link copied to clipboard
inline fun <T> T.applyIf(predicate: Boolean, body: T.() -> T): T

Conditionally applies the provided block to the receiver object if the predicate is true and returns the modified object.

Link copied to clipboard

shorthand for this as? Collection<E> ?: toList()

Link copied to clipboard
fun <E> Iterable<E>.asList(): List<E>

shorthand for this as? List<E> ?: toList()

Link copied to clipboard
fun <E> Iterable<E>.asSet(): Set<E>

shorthand for this as? Set<E> ?: toSet()

Link copied to clipboard

Replaces the deprecated Kotlin version, but hard-codes Locale.US

fun String.capitalize(locale: Locale = Locale.US): String

Capitalizes the first character of this String using the specified locale.

Link copied to clipboard
inline fun <T> Any.cast(): T
Link copied to clipboard
fun <E> Iterable<E>.chunkedBy(selector: (E) -> Boolean): List<List<E>>

This function iterates over the receiver iterable and adds each element to the current chunk. Whenever the selector function returns true for an element, that element concludes the current chunk and a new chunk is started.

Link copied to clipboard
Link copied to clipboard
fun File.createSafely(content: String? = null, overwrite: Boolean = true): File

Creates a new file if it doesn't already exist, creating parent directories if necessary. If the file already exists, its content will be overwritten. If content is provided, it will be written to the file.

Link copied to clipboard
fun String.decapitalize(locale: Locale = Locale.US): String

Decapitalizes the first character of this String using the specified locale.

Link copied to clipboard
operator fun File.div(child: String): File

Resolves the given child path against the receiver File.

Link copied to clipboard

Checks if the receiver File exists and returns it, or null if it does not exist.

Link copied to clipboard
inline fun <T> Iterable<T>.filterToSet(destination: MutableSet<T> = mutableSetOf(), predicate: (T) -> Boolean): Set<T>

Filters the receiver iterable and adds the matching elements to a set.

Link copied to clipboard

Reads the receiver File and finds the minimum indent in its content.

fun String.findMinimumIndent(absoluteMinimum: String = " "): String

Finds and returns the minimum indentation for this String, with an optional absoluteMinimum to be returned if the minimum indent is less than the absolute minimum.

Link copied to clipboard
inline fun <T, R> Iterable<T>.flatMapToSet(destination: MutableSet<R> = mutableSetOf(), transform: (T) -> Iterable<R>): Set<R>
inline fun <T, R> Sequence<T>.flatMapToSet(destination: MutableSet<R> = mutableSetOf(), transform: (T) -> Iterable<R>): Set<R>

Transforms each element of the receiver iterable to an iterable and flattens these iterables into a single set.

Link copied to clipboard
fun <T> Optional<T>.getOrNull(): T?

shorthand for takeIf { it.isPresent }?.get()

Link copied to clipboard
inline fun StringBuilder.indent(leadingIndent: String = " ", continuationIndent: String = leadingIndent, builder: StringBuilder.() -> Unit)

example:

Link copied to clipboard

A naive auto-indent which just counts brackets.

Link copied to clipboard
private fun String.indentWidth(): Int

Calculates and returns the width of the indentation for this String.

Link copied to clipboard
inline fun <E> Collection<E>.indicesOf(predicate: (E) -> Boolean): List<Int>

Finds the indices of all elements in the receiver collection that match the given predicate.

Link copied to clipboard
infix fun <T> Comparable<T>.isGreaterThan(other: T): Boolean
Link copied to clipboard
fun <E> Iterable<E>.joinToStringConcat(transform: (E) -> CharSequence? = null): String
fun <E> Sequence<E>.joinToStringConcat(transform: (E) -> CharSequence? = null): String

shorthand for joinToString("") { ... }

Link copied to clipboard
fun <T> Sequence<T>.joinToStringIndexed(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: (Int, T) -> CharSequence): String

Creates a string from all the elements separated using separator and using the given prefix and postfix if supplied.

Link copied to clipboard

Adjusts the indentation of each line in the string to match the indentation of the first non-blank line. The first non-blank line determines the target indentation level, and subsequent lines are adjusted accordingly.

Link copied to clipboard
inline fun <T> T.letIf(predicate: Boolean, transform: (T) -> T): T

Conditionally applies the provided transform function to the receiver object if the predicate is true, then returns the result of that transform. If the predicate is false, the receiver object itself is returned.

Link copied to clipboard
internal fun File.makeParentDir(): File

Creates the parent directory of the receiver File if it doesn't already exist.

Link copied to clipboard

performs transform on each line

Link copied to clipboard

performs transform on each line

Link copied to clipboard
inline fun <C : Collection<T>, T, R> C.mapToSet(destination: MutableSet<R> = mutableSetOf(), transform: (T) -> R): Set<R>

Transforms the elements of the receiver collection and adds the results to a set.

Link copied to clipboard
internal fun File.mkdirsInline(): File

Creates the directories represented by the receiver File if they don't already exist.

Link copied to clipboard

Removes

Link copied to clipboard

Converts all line separators in the receiver string to use \n.

Link copied to clipboard

all parents starting from the direct parent. Does not include the receiver file.

Link copied to clipboard
fun <E> Collection<E>.pluralString(empty: () -> String, single: (E) -> String, moreThanOne: (Iterable<E>) -> String): String

Returns a string representation of the collection based on its size.

Link copied to clipboard

Appends the specified prefix to this CharSequence and returns the resulting string.

Link copied to clipboard

Adds the specified prefix to this String if it does not already start with it.

Link copied to clipboard
fun CharSequence.prependContinuationIndent(continuationIndent: String, skipBlankLines: Boolean = true): String

Prepends continuationIndent to every line of the original string.

Link copied to clipboard

Adds line breaks and indents to the output of data class toString()s.

Link copied to clipboard
inline fun regex(builder: RegexBuilder.() -> Unit): Regex

Constructs a Regex instance by applying the provided builder function within the context of a RegexBuilderScope. This enables the creation of complex regular expressions in a more readable and maintainable way.

Link copied to clipboard
fun String.remove(vararg strings: String): String

Removes all occurrences of specified strings from the receiver string.

fun String.remove(vararg patterns: Regex): String

Removes all matches of specified regular expressions from the receiver string.

Link copied to clipboard
inline fun String.replaceDestructured(regex: Regex, crossinline transform: (group1: String) -> String): String
inline fun String.replaceDestructured(regex: Regex, crossinline transform: (group1: String, group2: String) -> String): String
inline fun String.replaceDestructured(regex: Regex, crossinline transform: (group1: String, group2: String, group3: String) -> String): String
inline fun String.replaceDestructured(regex: Regex, crossinline transform: (group1: String, group2: String, group3: String, group4: String) -> String): String
inline fun String.replaceDestructured(regex: Regex, crossinline transform: (group1: String, group2: String, group3: String, group4: String, group5: String) -> String): String
Link copied to clipboard
fun String.replaceRegex(regex: String, replacement: String): String

code golf for replace(regex.toRegex(), replacement)

Link copied to clipboard
inline fun <T : Any> T?.requireNotNull(): T
inline fun <T : Any> T?.requireNotNull(lazyMessage: () -> Any): T
Link copied to clipboard
fun File.resolve(vararg relative: String): File

vararg overload of kotlin.io.resolve

fun Path.resolve(vararg relative: String): Path

vararg overload of java.nio.file.Path.resolve

Link copied to clipboard
inline fun <T : Any> Any?.safeAs(): T?
Link copied to clipboard

Splits the receiver File's path into its individual segments.

Link copied to clipboard
fun <T> sequenceOfNotNull(vararg elements: T?): Sequence<T>

Creates a sequence of those elements which are not null

Link copied to clipboard
fun <T> T.singletonList(): List<T>

Wraps a given item in a list.

Link copied to clipboard
fun <T> T.singletonSet(): Set<T>

Wraps a given item in a set.

Link copied to clipboard
fun <T> Iterable<T>.sortedWith(vararg selectors: (T) -> Comparable<*>): List<T>
fun <T> Sequence<T>.sortedWith(vararg selectors: (T) -> Comparable<*>): Sequence<T>

Returns a list of all elements sorted according to the specified selectors.

Link copied to clipboard
fun <T> Iterable<T>.sortedWithDescending(vararg selectors: (T) -> Comparable<*>): List<T>

Returns a list of all elements sorted according to the specified selectors.

Link copied to clipboard
inline fun <T> String.splitAndMap(vararg delimiters: String, transform: (String) -> T): List<T>
inline fun <T> String.splitAndMap(vararg delimiters: Char, transform: (String) -> T): List<T>

shorthand for split(*delimiters).map { /* ... */ }

Link copied to clipboard
fun String.splitAndTrim(vararg delimiters: String): List<String>
fun String.splitAndTrim(vararg delimiters: Char): List<String>

shorthand for splitAndMap(*delimiters) { it.trim() }

Link copied to clipboard

Adds the specified suffix to this String if it does not already end with it.

Link copied to clipboard
inline fun <E> Iterable<E>.takeWhileInclusive(predicate: (E) -> Boolean): List<E>

Returns a list containing the elements from the receiver iterable up to and including the first element for which the given predicate returns false.

Link copied to clipboard

shorthand for toString().prettyToString(), which adds line breaks and indents to a string

Link copied to clipboard

Removes the indentation from every line in this string after the first line, and also removes any blank lines appearing before the first non-blank line.

Link copied to clipboard
fun String.trimSegments(delimiter: String = "."): String
Link copied to clipboard
fun CharSequence.wrapIn(prefix: String, suffix: String = prefix): String

"$prefix$this$suffix"