refactor
This commit is contained in:
35
gradlew
vendored
35
gradlew
vendored
@@ -55,7 +55,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (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.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
@@ -80,13 +80,11 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
APP_NAME="Gradle"
|
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
@@ -133,22 +131,29 @@ location of your Java installation."
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD=java
|
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
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
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 ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
'' | soft) :;; #(
|
'' | 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" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
@@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
# double quotes to make sure that they get re-expanded; and
|
|
||||||
# * put everything else in single quotes, so that it's not re-expanded.
|
# 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 -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
1
gradlew.bat
vendored
1
gradlew.bat
vendored
@@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal
|
|||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%"=="" set DIRNAME=.
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@@ -43,12 +43,12 @@ class Either<A, B> private constructor(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun <A, B> ofA(a: A): Either<A, B> =
|
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> =
|
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()
|
getAOrNull() ?: getB()
|
@@ -1,5 +1,7 @@
|
|||||||
package blitz
|
package blitz
|
||||||
|
|
||||||
|
import blitz.collections.contents
|
||||||
|
import blitz.collections.easyMappingSequence
|
||||||
import blitz.func.*
|
import blitz.func.*
|
||||||
import blitz.func.io.*
|
import blitz.func.io.*
|
||||||
|
|
||||||
|
@@ -1,11 +1,39 @@
|
|||||||
package blitz
|
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>? =
|
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> =
|
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 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,7 @@
|
|||||||
package blitz
|
package blitz
|
||||||
|
|
||||||
|
import blitz.collections.selfInitializingSequence
|
||||||
|
|
||||||
class OperationChain<I, O> private constructor(
|
class OperationChain<I, O> private constructor(
|
||||||
private val impl: Impl = Impl()
|
private val impl: Impl = Impl()
|
||||||
) {
|
) {
|
||||||
|
11
src/main/kotlin/blitz/async/Lock.kt
Normal file
11
src/main/kotlin/blitz/async/Lock.kt
Normal 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)
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package blitz
|
package blitz.collections
|
||||||
|
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
@@ -1,4 +1,4 @@
|
|||||||
package blitz
|
package blitz.collections
|
||||||
|
|
||||||
fun ByteBatchSequence.stringify(batch: Int = 64): Sequence<String> {
|
fun ByteBatchSequence.stringify(batch: Int = 64): Sequence<String> {
|
||||||
val iter = iterator()
|
val iter = iterator()
|
@@ -1,4 +1,4 @@
|
|||||||
package blitz
|
package blitz.collections
|
||||||
|
|
||||||
class Contents<T> internal constructor(
|
class Contents<T> internal constructor(
|
||||||
private val iterable: Iterable<T>
|
private val iterable: Iterable<T>
|
||||||
@@ -41,7 +41,6 @@ class Contents<T> internal constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val <T> Iterable<T>.contents get() =
|
val <T> Iterable<T>.contents get() =
|
||||||
Contents(this)
|
Contents(this)
|
||||||
|
|
@@ -1,4 +1,4 @@
|
|||||||
package blitz
|
package blitz.collections
|
||||||
|
|
||||||
fun <T> MutableList<T>.removeFirst(count: Int) {
|
fun <T> MutableList<T>.removeFirst(count: Int) {
|
||||||
repeat(count) {
|
repeat(count) {
|
@@ -1,4 +1,4 @@
|
|||||||
package blitz
|
package blitz.collections
|
||||||
|
|
||||||
interface IndexableSequence<T>: Sequence<T> {
|
interface IndexableSequence<T>: Sequence<T> {
|
||||||
operator fun get(index: Int): T
|
operator fun get(index: Int): T
|
@@ -1,5 +1,7 @@
|
|||||||
package blitz
|
package blitz.collections
|
||||||
|
|
||||||
|
import blitz.Obj
|
||||||
|
import blitz.Provider
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
||||||
fun <T> lazySequence(vararg init: Pair<Int, T>, default: Obj<T>?, f: (Int, (Int) -> T) -> T): IndexableSequence<T> =
|
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?> =
|
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 ->
|
f(i) { index ->
|
||||||
var indexC = index
|
var indexC = index
|
||||||
var v: T? = null
|
var v: T? = null
|
@@ -1,4 +1,4 @@
|
|||||||
package blitz
|
package blitz.collections
|
||||||
|
|
||||||
fun <T> Sequence<T>.removeNull(): Sequence<T> =
|
fun <T> Sequence<T>.removeNull(): Sequence<T> =
|
||||||
mapNotNull { it }
|
mapNotNull { it }
|
@@ -1,7 +1,7 @@
|
|||||||
package blitz.func
|
package blitz.func
|
||||||
|
|
||||||
import blitz.ByteBatchSequence
|
import blitz.collections.ByteBatchSequence
|
||||||
import blitz.stringify
|
import blitz.collections.stringify
|
||||||
|
|
||||||
fun <T> Monad<Sequence<Sequence<T>>>.flatten(): Monad<Sequence<T>> =
|
fun <T> Monad<Sequence<Sequence<T>>>.flatten(): Monad<Sequence<T>> =
|
||||||
bind { it.flatten() }
|
bind { it.flatten() }
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
package blitz.func.io
|
package blitz.func.io
|
||||||
|
|
||||||
import blitz.*
|
import blitz.collections.ByteBatchSequence
|
||||||
import blitz.func.*
|
import blitz.func.*
|
||||||
import blitz.io.*
|
import blitz.io.*
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
package blitz.io
|
package blitz.io
|
||||||
|
|
||||||
import blitz.ByteBatchSequence
|
import blitz.collections.ByteBatchSequence
|
||||||
import kotlinx.io.Buffer
|
import kotlinx.io.Buffer
|
||||||
import kotlinx.io.files.SystemFileSystem
|
import kotlinx.io.files.SystemFileSystem
|
||||||
|
|
||||||
|
@@ -2,8 +2,8 @@ package blitz.io
|
|||||||
|
|
||||||
import kotlinx.io.RawSource
|
import kotlinx.io.RawSource
|
||||||
import kotlinx.io.buffered
|
import kotlinx.io.buffered
|
||||||
import blitz.ByteBatchIterator
|
import blitz.collections.ByteBatchIterator
|
||||||
import blitz.ByteBatchSequence
|
import blitz.collections.ByteBatchSequence
|
||||||
import blitz.Provider
|
import blitz.Provider
|
||||||
|
|
||||||
fun Provider<RawSource>.readerSequence(): ByteBatchSequence =
|
fun Provider<RawSource>.readerSequence(): ByteBatchSequence =
|
||||||
|
Reference in New Issue
Block a user