alexander.nutz b87c0755ad fix
2024-03-28 17:55:28 +01:00
2024-03-25 10:53:09 +01:00
fix
2024-03-28 17:55:28 +01:00
2024-02-28 21:35:08 +01:00
fix
2024-03-28 17:55:28 +01:00
2024-02-28 17:54:38 +01:00
2024-03-25 09:19:27 +01:00
2024-03-25 09:19:27 +01:00
fix
2024-03-28 17:55:28 +01:00
2024-03-25 11:25:05 +01:00

Blitz

Kotlin library which mainly focuses on functional programming.

Features:

  • Monads
  • Either
  • Caching delegated property (similar to lazy)
  • A lot of sequence utils
  • Streaming IO using kotlinx.io
  • ByteVec (alternative to ByteBuf)
  • BitVec (similar to bit sets in other languages)
  • "Lazy" sequences
  • A lot of generative sequence types
  • BitField

How to get

repositories {
    maven {
        name = "alex's repo"
        url = uri("http://207.180.202.42:8080/libs")
        isAllowInsecureProtocol = true
    }
}

dependencies {
    implementation("me.alex_s168:blitz:0.6")
}

Examples

Fibonacci sequence

val fib = lazySequence(0 to 1) { i, f ->
  f(i-1) + f(i-2)
}

println(fib[10])

Unix uniq

val inp = sequenceOf("AAA", "BBB", "AAA", "AAA", "AAA", "BBB")
val out = inp.easyMappingSequence { i, s, m ->
    if (s(i-1) == m(i)) null
    else m(i)
}
println(out.contents)

Reading files

val file = Path.of("test.txt")  // Path
    .getFile()                  // File

val text = file.read()          // ByteBatchSequence
    .stringify()                // Sequence<String>   // (NOT lines!!)
    .flatten()                  // String

Bit fields

class Flags: BitField() {
    var direction by bit(0)
    var moving by bit(1)
    var frontLight by bit(2)
}

val byte = getByteFromSomewhere()
val flags = Flags().decode(byte)
flags.direction = !flags.direction
putByteSomewhere(flags.encode())

Unix cat with monads (pure)

fun pureCat(args: Array<String>): Monad<Unit> =
    args
    .ifEmpty { arrayOf("-") }
    .map {
        if (it == "-") readIn()
        else unit(it)
            .asPath()
            .read()
            .stringify()
    }
    .rewrap()
    .flatten()
    .reduce { s -> print(s) }

Numbers to bytes

val num: Short = 5
val bytes = num.toBytes(Endian.LITTLE)

Caching delegate property

class Label {
    val font = "Arial 11"
    val fontWith by caching(::font) {
        someFunctionToCalculate(it)
    }
}

Contents

val a = listOf(1, 2, 3, 4)
val b = arrayOf(1, 2, 3, 4)
println(a.contents == b.contents) // true
println(b.contents) // [1, 2, 3, 4]

Either

No example yet

Description
Kotlin utility library
Readme 212 KiB
Languages
Kotlin 100%