Tuulbox
Toolbox of utilities/helpers for Kotlin development.
Coroutines
Utilities for Coroutines.
combine
val combined = combine(
flow1,
flow2,
// ...
flow9,
flow10,
) { value1, value2, /* ... */, value9, value10 ->
// ...
}
Logging
Simple multiplatform logging API.
Initialization
Logging can be initialized via install
:
Log.dispatcher.install(ConsoleLogger)
Custom loggers can be created by implementing the Logger
interface.
Log
Log message can be logged via:
Log.verbose { "Example" }
The following log level functions are available:
Optional tag
and throwable
may be provided. tag
defaults to an autogenerated value, but behavior can be customized via Log.tagGenerator
property.
Functional
Utilities for manipulating functions. For a full functional ecosystem, complete with Monad
and the like, prefer Arrow.
Temporal
Toolbox of utilities for dates and times, building on KotlinX DateTime.
Various interval Flow
s are provided, such as: instantFlow
, localDateTimeFlow
, and localDateFlow
. For example:
localDateTimeFlow().collect {
println("The time is now: $it")
}
Note: Because this is built on top of KotlinX DateTime, core library desugaring must be enabled for Android targets.
Test
Utilities for test suites.
runTest
Multiplatform test analogy to runBlocking
:
@Test
fun exampleUnitTest() = runTest {
// ...
}
assertContains
assertContains(
array = arrayOf(1, 2, 3),
value = 2,
)
assertContains(
range = 1..10,
value = 5,
)
assertSimilar
assertSimilar(
target = 5,
epsilon = 1,
value = 6,
)
Encoding
Utilities for working with binary data.
IntBitSet
val bitSet = 0.bits
bitSet[30] = true
bitSet.asPrimitive() // 1073741824
/* | Index | ... | 3 | 2 | 1 | 0 |
* |-------|-----|---|---|---|---|
* | Bit | ... | 1 | 0 | 1 | 0 |
*/
val bitSet = 10.bits
bitSet[0] // false
bitSet[1] // true
bitSet[2] // false
bitSet[3] // true
LongBitSet
/* | Index | ... | 3 | 2 | 1 | 0 |
* |-------|-----|---|---|---|---|
* | Bit | ... | 1 | 1 | 0 | 0 |
*/
val bitSet = 12L.bits
bitSet[0] // false
bitSet[1] // false
bitSet[2] // true
bitSet[3] // true
val bitSet = 0L.bits
bitSet[40] = true
bitSet.asPrimitive() // 1099511627776L
Setup
Gradle
Tuulbox can be configured via Gradle Kotlin DSL as follows:
Multiplatform
plugins {
id("com.android.application") // or id("com.android.library")
kotlin("multiplatform")
}
repositories {
mavenCentral()
}
kotlin {
jvm() // and/or android()
js().browser() // and/or js().node()
macosX64()
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.juul.tuulbox:coroutines:$version")
implementation("com.juul.tuulbox:logging:$version")
implementation("com.juul.tuulbox:functional:$version")
implementation("com.juul.tuulbox:temporal:$version")
implementation("com.juul.tuulbox:encoding:$version")
}
}
val commonTest by getting {
dependencies {
implementation("com.juul.tuulbox:test:$version")
}
}
}
}
Platform-specific
repositories {
mavenCentral()
}
dependencies {
implementation("com.juul.tuulbox:coroutines:$version")
implementation("com.juul.tuulbox:logging:$version")
implementation("com.juul.tuulbox:functional:$version")
implementation("com.juul.tuulbox:temporal:$version")
implementation("com.juul.tuulbox:encoding:$version")
testImplementation("com.juul.tuulbox:test:$version")
}
License
Copyright 2021 JUUL Labs, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.