kommon

A commons library for Kotlin

License

License

GroupId

GroupId

com.github.andrewoma.kommon
ArtifactId

ArtifactId

kommon
Last Version

Last Version

0.14
Release Date

Release Date

Type

Type

jar
Description

Description

kommon
A commons library for Kotlin
Project URL

Project URL

https://github.com/andrewoma/kommon
Source Code Management

Source Code Management

https://github.com/andrewoma/kommon

Download kommon

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.andrewoma.kommon/kommon/ -->
<dependency>
    <groupId>com.github.andrewoma.kommon</groupId>
    <artifactId>kommon</artifactId>
    <version>0.14</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.andrewoma.kommon/kommon/
implementation 'com.github.andrewoma.kommon:kommon:0.14'
// https://jarcasting.com/artifacts/com.github.andrewoma.kommon/kommon/
implementation ("com.github.andrewoma.kommon:kommon:0.14")
'com.github.andrewoma.kommon:kommon:jar:0.14'
<dependency org="com.github.andrewoma.kommon" name="kommon" rev="0.14">
  <artifact name="kommon" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.andrewoma.kommon', module='kommon', version='0.14')
)
libraryDependencies += "com.github.andrewoma.kommon" % "kommon" % "0.14"
[com.github.andrewoma.kommon/kommon "0.14"]

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib jar 1.1.3-2

test (2)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-test-junit jar 1.1.3-2
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Kommon Overview

Kommon is a "commons" library for Kotlin.

It fills in a few gaps in Kotlin's current standard library and will hopefully cease to exist as the standard library matures.

Status

Unstable, but probably works.

Releases are available in Maven Central here.

The current release (0.13) is compatible with 1.1.0.

Older releases are available for historical Kotlin versions.

Features

Shell

The shell package contains some convenience functions for executing external processes. e.g.

val out = shell("ls -lah").out
val out = shell("echo \$HELLO \$WORLD", environment = mapOf("HELLO" to "foo", "WORLD" to "bar")).out
Collections

The collections package contains extension functions for collections. e.g.

// Process a sequence in chunks. e.g. insert records in batches of 10
val records: Sequence<Record> ...
for (batch in records.chunked(10)) {
    insert(batch)
}

// Process a sequence using a window to look ahead and/or behind
val lines: Sequence<String> ...
for ((prev, current, next) in lines.window(before = 1, after = 1).asIterable) {
    ...
}
Strings
// Truncate, keeping the end of a string
assertEquals("llo", "hello".truncateRight(3))
Language
// Helper to generate equals with a type safe function
class Foo(val bar: String, val baz: Int, val quz: String?) {
    override fun equals(other: Any?) = equals(this, other) { o1, o2 ->
        return o1.bar == o2.bar && o1.baz == o2.baz && o1.quz == o2.quz
    }
}

// Helper to generate equals with a list of properties
class Bar(val foo: String, val baz: Int, val quz: String?) {
    override fun equals(other: Any?) = equals(this, other, Bar::foo, Bar::baz, Bar::quz)
}
Misc
// A stop watch for basic timings
val sw = StopWatch()
sw.start()
...
sw.stop()
println(sw.toString(TimeUnit.SECONDS))

See the tests for more examples.

License

This project is licensed under a MIT license.

Build Status

Versions

Version
0.14
0.13
0.12
0.11
0.10
0.9
0.7
0.6
0.5
0.4
0.3
0.2
0.1