KBox
KBox is a very small but useful utility library for Kotlin (JVM, Android and JS).
Current extension functions:
-
Array/List/Iterable/Sequence.appendtoStringBuilder
with the ability to define a different separator for the last separation => handy if you want to form sentences likea, b and c
-
CharSequence.blankToNull
returns the sameCharSequence
if not blank,null
otherwise -
forEachIn(Array/Iterable/Sequence<E>, Array/Iterable/Sequence<E>, ..., action: (E) -> Unit)
applies the given action to each entry in the givenIterable
s. -
<E> forElementAndEachIn(E, Array/Iterable/Sequence<E>, action: (E) -> Unit)
applies the given action tothis
and each entry in Iterable -
Iterable<T>.forEachRemaining()
shortcut forwhile(hasNext()) yourLambda(next())
-
Array/List.ifWithinBound shortcut for
if(index < size){ thenBlock() } else { elseBlock() }
-
Array/List/Iterable/Sequence.joinToString
with the ability to define a different separator for the last separation => handy if you want to form sentences likea, b and c
-
Map<T, T>.mapParents
maps child-parent relations. -
Iterator<T>.mapRemaining/mapRemainingWithCounter
maps remaining entries with the help of a transform function (wheremapRemainingWithCounter
passes a counter variable to the transform function). -
Iterator.toPeekingIterator()
which allows to have a look what the next element is without consuming it. -
varargsToList/glue
creates aList
out of a singleE
and anArray<E>
.
Moreover, the following function might come in handy for you as well:
Installation
KBox is pusblished to maven central, jcenter and bintray. Following an example if you use gradle and jcenter:
repositories { jcenter() }
dependencies {
implementation 'ch.tutteli.kbox:kbox:0.16.0-SNAPSHOT'
}
Accordingly, you can use kbox-js
or kbox-common
as artifactId instead of kbox
.
License
KBox is licensed under Apache 2.0.