This commit is contained in:
alexander.nutz
2024-03-25 09:19:27 +01:00
parent b3150fd948
commit 6e9300fac6
18 changed files with 418 additions and 364 deletions

35
gradlew vendored
View File

@@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,13 +80,11 @@ do
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -133,22 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \

1
gradlew.bat vendored
View File

@@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

View File

@@ -43,12 +43,12 @@ class Either<A, B> private constructor(
companion object {
fun <A, B> ofA(a: A): Either<A, B> =
Either(Obj(a), null)
Either(Obj.of(a), null)
fun <A, B> ofB(b: B): Either<A, B> =
Either(null, Obj(b))
Either(null, Obj.of(b))
}
}
fun <A, B, R> Either<A, B>.commonize(): R where A: R, B: R =
fun <A, B, R> Either<A, B>.flatten(): R where A: R, B: R =
getAOrNull() ?: getB()

View File

@@ -1,5 +1,7 @@
package blitz
import blitz.collections.contents
import blitz.collections.easyMappingSequence
import blitz.func.*
import blitz.func.io.*

View File

@@ -1,11 +1,39 @@
package blitz
data class Obj<T>(val v: T)
import blitz.async.Lock
interface Obj<T> {
val v: T
companion object {
fun <T> of(v: T): Obj<T> =
object : Obj<T> {
override val v: T = v
}
}
}
fun <I, O> Obj<I>?.mapNotNull(transform: (I) -> O): Obj<O>? =
this?.v?.let { Obj(transform(it)) }
this?.v?.let { Obj.of(transform(it)) }
fun <I, O> Obj<I>.map(transform: (I) -> O): Obj<O> =
Obj(transform(v))
Obj.of(transform(v))
data class MutObj<T>(var v: T)
interface MutObj<T> {
var v: T
companion object {
fun <T> of(v: T): MutObj<T> =
object : MutObj<T> {
override var v: T = v
}
fun <T> mutex(v: T): MutObj<T> =
object : MutObj<T> {
val lock = Lock()
override var v: T = v
get() = lock.use { field }
set(inp) = lock.use { field = inp }
}
}
}

View File

@@ -1,5 +1,7 @@
package blitz
import blitz.collections.selfInitializingSequence
class OperationChain<I, O> private constructor(
private val impl: Impl = Impl()
) {

View File

@@ -0,0 +1,11 @@
package blitz.async
@JvmInline
value class Lock private constructor(
private val impl: Any
) {
constructor(): this(Any())
fun <R> use(block: () -> R): R =
synchronized(impl, block)
}

View File

@@ -1,4 +1,4 @@
package blitz
package blitz.collections
import kotlin.math.max
import kotlin.math.min

View File

@@ -1,4 +1,4 @@
package blitz
package blitz.collections
fun ByteBatchSequence.stringify(batch: Int = 64): Sequence<String> {
val iter = iterator()

View File

@@ -1,4 +1,4 @@
package blitz
package blitz.collections
class Contents<T> internal constructor(
private val iterable: Iterable<T>
@@ -41,7 +41,6 @@ class Contents<T> internal constructor(
}
}
val <T> Iterable<T>.contents get() =
Contents(this)

View File

@@ -1,4 +1,4 @@
package blitz
package blitz.collections
fun <T> MutableList<T>.removeFirst(count: Int) {
repeat(count) {

View File

@@ -1,4 +1,4 @@
package blitz
package blitz.collections
interface IndexableSequence<T>: Sequence<T> {
operator fun get(index: Int): T

View File

@@ -1,5 +1,7 @@
package blitz
package blitz.collections
import blitz.Obj
import blitz.Provider
import kotlin.math.max
fun <T> lazySequence(vararg init: Pair<Int, T>, default: Obj<T>?, f: (Int, (Int) -> T) -> T): IndexableSequence<T> =
@@ -35,7 +37,7 @@ fun <T> lazySequence(vararg init: Pair<Int, T>, default: Obj<T>?, f: (Int, (Int)
}
fun <T> easySequence(vararg init: Pair<Int, T?>, f: (Int, (Int) -> T?) -> T?): Sequence<T?> =
lazySequence(*init, default = Obj(null)) { i, ff ->
lazySequence(*init, default = Obj.of(null)) { i, ff ->
f(i) { index ->
var indexC = index
var v: T? = null

View File

@@ -1,4 +1,4 @@
package blitz
package blitz.collections
fun <T> Sequence<T>.removeNull(): Sequence<T> =
mapNotNull { it }

View File

@@ -1,7 +1,7 @@
package blitz.func
import blitz.ByteBatchSequence
import blitz.stringify
import blitz.collections.ByteBatchSequence
import blitz.collections.stringify
fun <T> Monad<Sequence<Sequence<T>>>.flatten(): Monad<Sequence<T>> =
bind { it.flatten() }

View File

@@ -1,6 +1,6 @@
package blitz.func.io
import blitz.*
import blitz.collections.ByteBatchSequence
import blitz.func.*
import blitz.io.*

View File

@@ -1,6 +1,6 @@
package blitz.io
import blitz.ByteBatchSequence
import blitz.collections.ByteBatchSequence
import kotlinx.io.Buffer
import kotlinx.io.files.SystemFileSystem

View File

@@ -2,8 +2,8 @@ package blitz.io
import kotlinx.io.RawSource
import kotlinx.io.buffered
import blitz.ByteBatchIterator
import blitz.ByteBatchSequence
import blitz.collections.ByteBatchIterator
import blitz.collections.ByteBatchSequence
import blitz.Provider
fun Provider<RawSource>.readerSequence(): ByteBatchSequence =