kotlin-preconditions alternatives and similar libraries
Based on the "Misc" category.
Alternatively, view kotlin-preconditions alternatives based on common mentions on social networks and blogs.
-
jclasslib
jclasslib bytecode editor is a tool that visualizes all aspects of compiled Java class files and the contained bytecode. -
kotlin-logging
Lightweight Multiplatform logging framework for Kotlin. A convenient and performant logging facade. -
kotlinx-datetime
KotlinX multiplatform date/time library -
kotlin-telegram-bot
๐ค A wrapper for the Telegram Bot API written in Kotlin -
kotlinx.atomicfu
The idiomatic way to use atomic operations in Kotlin -
tinylog
tinylog is a lightweight logging framework for Java, Kotlin, Scala, and Android -
lingua
The most accurate natural language detection library for Java and the JVM, suitable for long and short text alike -
Kotlift
Kotlift is the first source-to-source language transpiler from Kotlin to Swift -
better-parse
A nice parser combinator library for Kotlin -
kotlinx.reflect.lite
Lightweight library allowing to introspect basic stuff about Kotlin symbols -
Humanizer.jvm
Humanizer.jvm meets all your jvm needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities. -
actions-on-google-kotlin
Unofficial Actions on Google SDK for Kotlin and Java -
klutter
A mix of random small libraries for Kotlin, the smallest reside here until big enough for their own repository. -
solr-undertow
Solr / SolrCloud running in high performance server - tiny, fast startup, simple to configure, easy deployment without an application server. -
kassava
This library provides some useful kotlin extension functions for implementing toString(), hashCode() and equals() without all of the boilerplate. -
SimpleDNN
SimpleDNN is a machine learning lightweight open-source library written in Kotlin designed to support relevant neural network architectures in natural language processing tasks -
units-of-measure
Type-safe dimensional analysis and unit conversion in Kotlin. -
kotlin-futures
A collections of extension functions to make the JVM Future, CompletableFuture, ListenableFuture API more functional and Kotlin like. -
TLSLibrary
Simple TlsLibrary written in Kotlin - Provides DSL for creating TLS connections -
scientist
A kotlin library for refactoring code. Port of GitHub's scientist. -
kasechange
๐ซ๐๐ข๐ ฟ Multiplatform Kotlin library to convert strings between various case formats including Camel Case, Snake Case, Pascal Case and Kebab Case -
kjob
A lightweight coroutine based persistent job/cron scheduler written in Kotlin -
KDispatcher
Simple and light-weight event dispatcher for Kotlin -
PrimeCalendar
PrimeCalendar provides all of the java.util.Calendar functionalities for Persian, Hijri, and ... dates. It is also possible to convert dates to each other. -
kotlin-pluralizer
:sunny: Kotlin extension to pluralize and singularize strings -
aleksa
Aleksa is a small framework for writing Alexa Skills in Kotlin -
kformula
Mathematical expression engine written in Kotlin, running on JVM.
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of kotlin-preconditions or a related project?
README
Kotlin Preconditions 
kotlin-preconditions will assist you in ensuring all of your invariants are met before an operation is executed.
Usage
kotlin-preconditions provides a powerful DSL for defining preconditions:
checkThat(1) { isLt(2) }
checkThat(listOf(1, 2)) { contains(1) }
requireThat(1) { isLt(2) }
requireThat(listOf(1, 2)) { contains(1) }
If any of the preconditions are not met then checkThat
will throw an
IllegalStateException
and requireThat
will throw an IllegalArgumentException
.
The exception message will be generated lazily, so your application does
not waste resources on evaluating objects that may not trigger an exception.
Compose your preconditions the way you like it:
val list = listOf(1, 2)
requireThat(list) { contains(3) or contains(1) and not(hasSize(3)) }
// nested preconditions
val text: String? = "hello"
requireThat(text) {
not(isNull()) and {
hasLength(6) or { startsWith("he") and endsWith("llo") }
}
}
API Overview
Aliases
Instead of checkThat
and requireThat
you can also use check
and require
.
val value = "hello"
check(value) { startsWith("he") and hasLength(5) and not(includes("io")) }
require(value) { startsWith("he") and hasLength(5) and not(includes("io")) }
String preconditions
val value = "hello"
requireThat(value) { startsWith("he") and hasLength(5) and not(includes("io")) }
requireThat(value) { includes("ll") }
requireThat(value) { matches("hello") }
requireThat(value) { endsWith("lo") }
requireThat(value) { hasLength(5) }
requireThat(value) { not(isBlank()) }
requireThat(value) { not(isEmpty()) }
requireThat(value) { hasLengthBetween(1, 5) }
Collection preconditions
val list = listOf(1, 2)
requireThat(list) { hasSize(2) }
requireThat(list) { contains(1) or contains(3) and not(hasSize(3)) }
requireThat(list) { containsAll(1, 2) }
requireThat(list) { containsAll(list) }
requireThat(list) { isSorted() }
Comparable preconditions
requireThat(1) { isLt(2) }
requireThat(1) { isLte(1) }
requireThat(1) { isGt(0) }
requireThat(1) { isGte(1) }
requireThat(1) { isBetween(0..2) }
Map preconditions
val map = mapOf(1 to "1")
requireThat(map) { hasKey(1) }
requireThat(map) { hasValue("1") }
requireThat(map) { contains(1, "1") }
Object preconditions
val result = Result(true)
requireThat(result) { not(isNull()) }
requireThat(result) { isEqualTo(result) }
requireThat(result) { isSameInstanceAs(result) }
Composed preconditions
val value = "hello"
requireThat(value) { startsWith("he") and hasLength(5) and not(includes("io")) }
Labels
val numbers = listOf(1, 2)
requireThat(numbers, "Numbers") { contains(3) or contains(1) and not(hasSize(3)) }
Custom matchers
Custom matchers can be added by using extension functions:
data class Car(val age: Int)
fun PreconditionBlock<Car>.hasAge(expected: Int) = object : Matcher<Car>() {
override fun test(condition: Condition<Car>) = condition.test {
withResult(value.age == expected) { "expected car to be $expected years old, but was ${value.age}" }
}
}
requireThat(Car(22)) { hasAge(22) }
Installation
Maven:
<dependency>
<groupId>com.github.spoptchev</groupId>
<artifactId>kotlin-preconditions</artifactId>
<version>6.1.0</version>
</dependency>
Gradle:
compile 'com.github.spoptchev:kotlin-preconditions:6.1.0'