Sha256: fcb12a9a1eb7666e400581d72f75d63aef398bb0b59fdf7958f4f5320bd386e5

Contents?: true

Size: 1.12 KB

Versions: 205

Compression:

Stored size: 1.12 KB

Contents

fun <T> List<T>.customAppend(list: List<T>): List<T> {
    val result = mutableListOf<T>()
    result.addAll(this)
    result.addAll(list)
    return result
}

fun <T> List<List<T>>.customConcat(): List<T> {
    val result = mutableListOf<T>()
    forEach { result.addAll(it) }
    return result
}

fun <T> List<T>.customFilter(predicate: (T) -> Boolean): List<T> {
    val result = mutableListOf<T>()
    forEach { if (predicate(it)) { result.add(it) } }
    return result
}

val List<Any>.customSize: Int
    get() = size

fun <T, U> List<T>.customMap(transform: (T) -> U): List<U> {
    val result = mutableListOf<U>()
    forEach { result.add(transform(it)) }
    return result
}

fun <T, U> List<T>.customFoldLeft(initial: U, f: (U, T) -> U): U {
    if (isEmpty()) return initial
    return drop(1).customFoldLeft(f(initial, first()), f)
}

fun <T, U> List<T>.customFoldRight(initial: U, f: (T, U) -> U): U {
    if (isEmpty()) return initial
    return f(first(), drop(1).customFoldRight(initial, f))
}

fun <T> List<T>.customReverse(): List<T> {
    val result = mutableListOf<T>()
    forEach { result.add(0, it) }
    return result
}

Version data entries

205 entries across 205 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.158 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.157 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.156 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.155 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.154 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.153 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.152 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.151 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.150 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.149 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.148 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.147 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.146 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.145 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.144 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.143 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.142 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.141 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt
trackler-2.2.1.140 tracks/kotlin/exercises/list-ops/.meta/src/reference/kotlin/CustomListExtensions.kt