ktee

KTee is Tee for Kotlin code pipelines. If you love the unix command line tee, you know what we mean.

Лицензия

Лицензия

MIT
Группа

Группа

com.medly
Идентификатор

Идентификатор

ktee
Последняя версия

Последняя версия

1.0.0
Дата

Дата

Тип

Тип

pom.sha512
Описание

Описание

ktee
KTee is Tee for Kotlin code pipelines. If you love the unix command line tee, you know what we mean.
Ссылка на сайт

Ссылка на сайт

https://github.com/medly/ktee
Система контроля версий

Система контроля версий

https://github.com/medly/ktee

Скачать ktee

Имя Файла Размер
ktee-1.0.0.pom
ktee-1.0.0-sources.jar 910 bytes
ktee-1.0.0-javadoc.jar 6 KB
Обзор

Зависимости

runtime (2)

Идентификатор библиотеки Тип Версия
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.3.61
org.slf4j : slf4j-api jar 1.7.28

Модули Проекта

Данный проект не имеет модулей.

KTee

Build Maintainability Rating Security Rating

KTee is Tee for Kotlin code pipelines. If you love the unix command line tee, you know what we mean.

KTee

Why?

Often times we need to break a perfect computation pipeline just to be able to log the intermediate values. For example, lets take a look at this code:

(1..10)
    .filter { it % 2 == 0 }
    .map { it * 2 }
    .reduce(Int::plus)

If we want to print the result of filter or map we need to either capture the result into an intermediate val or add a .let { } with logging statements.

KTee simplifies printing intermediate values dramatically.

How?

Just .tee() it. Seriously! Try this:

(1..10)
    .filter { it % 2 == 0 }.tee()
    .map { it * 2 }.tee()
    .reduce(Int::plus).tee()

Which produces following output on the console:

[2, 4, 6, 8, 10]
[4, 8, 12, 16, 20]
60

Can I Customize the output?

We can customize the way tee prints using markers and lambda blocks to return custom log messages.

(1..10)
    .filter { it % 2 == 0 }.tee("even numbers: ")
    .map { it * 2 }.tee("doubles >>>>> ")
    .reduce(Int::plus).tee {"the result is $it"}

Produces:

even numbers: [2, 4, 6, 8, 10]
doubles >>>>> [4, 8, 12, 16, 20]
the result is 60

Can I tee to a logger?

We can also log to a custom logger instance (slf4j) instead of stdout

(1..10)
    .filter { it % 2 == 0 }.teeToDebug(logger)
    .map { it * 2 }.teeToTrace(logger)
    .reduce(Int::plus).teeToInfo(logger) { "the result is $it" }

Produces:

[main] DEBUG ktee.KTeeTest - [2, 4, 6, 8, 10]
[main] TRACE ktee.KTeeTest - [4, 8, 12, 16, 20]
[main] INFO ktee.KTeeTest - the result is 60

This output was produced using slf4j-simple binding. Your output pattern may look different depending on logger's configuration

How do I add it to my project?

Just add jitpack as the last repo in your repositories section of build.gradle and add com.medly:ktee:1.0.0 as a dependency:

repositories {		
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.medly:ktee:1.0.0'
}
com.medly

Medly

Medly Open Source

Версии библиотеки

Версия
1.0.0