KBox
KBox is a very small but useful utility library for Kotlin (JVM, Android and JS).
Current extension functions:
-
Array/List/Iterable/Sequence.appendtoStringBuilderwith the ability to define a different separator for the last separation => handy if you want to form sentences likea, b and c -
CharSequence.blankToNullreturns the sameCharSequenceif not blank,nullotherwise -
forEachIn(Array/Iterable/Sequence<E>, Array/Iterable/Sequence<E>, ..., action: (E) -> Unit)applies the given action to each entry in the givenIterables. -
<E> forElementAndEachIn(E, Array/Iterable/Sequence<E>, action: (E) -> Unit)applies the given action tothisand 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.joinToStringwith 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>.mapParentsmaps child-parent relations. -
Iterator<T>.mapRemaining/mapRemainingWithCountermaps remaining entries with the help of a transform function (wheremapRemainingWithCounterpasses a counter variable to the transform function). -
Iterator.toPeekingIterator()which allows to have a look what the next element is without consuming it. -
varargsToList/gluecreates aListout of a singleEand 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.