diff --git a/gradlew b/gradlew
index a69d9cb..1aa94a4 100755
--- a/gradlew
+++ b/gradlew
@@ -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" \
diff --git a/gradlew.bat b/gradlew.bat
index 53a6b23..6689b85 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -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%
diff --git a/src/main/kotlin/blitz/Either.kt b/src/main/kotlin/blitz/Either.kt
index 6ac1760..023e5ce 100644
--- a/src/main/kotlin/blitz/Either.kt
+++ b/src/main/kotlin/blitz/Either.kt
@@ -43,12 +43,12 @@ class Either private constructor(
companion object {
fun ofA(a: A): Either =
- Either(Obj(a), null)
+ Either(Obj.of(a), null)
fun ofB(b: B): Either =
- Either(null, Obj(b))
+ Either(null, Obj.of(b))
}
}
-fun Either.commonize(): R where A: R, B: R =
+fun Either.flatten(): R where A: R, B: R =
getAOrNull() ?: getB()
\ No newline at end of file
diff --git a/src/main/kotlin/blitz/Fnp.kt b/src/main/kotlin/blitz/Fnp.kt
index 34fad06..ba2713c 100644
--- a/src/main/kotlin/blitz/Fnp.kt
+++ b/src/main/kotlin/blitz/Fnp.kt
@@ -1,5 +1,7 @@
package blitz
+import blitz.collections.contents
+import blitz.collections.easyMappingSequence
import blitz.func.*
import blitz.func.io.*
diff --git a/src/main/kotlin/blitz/Obj.kt b/src/main/kotlin/blitz/Obj.kt
index 2b11455..346c85f 100644
--- a/src/main/kotlin/blitz/Obj.kt
+++ b/src/main/kotlin/blitz/Obj.kt
@@ -1,11 +1,39 @@
package blitz
-data class Obj(val v: T)
+import blitz.async.Lock
+
+interface Obj {
+ val v: T
+
+ companion object {
+ fun of(v: T): Obj =
+ object : Obj {
+ override val v: T = v
+ }
+ }
+}
fun Obj?.mapNotNull(transform: (I) -> O): Obj? =
- this?.v?.let { Obj(transform(it)) }
+ this?.v?.let { Obj.of(transform(it)) }
fun Obj.map(transform: (I) -> O): Obj =
- Obj(transform(v))
+ Obj.of(transform(v))
-data class MutObj(var v: T)
\ No newline at end of file
+interface MutObj {
+ var v: T
+
+ companion object {
+ fun of(v: T): MutObj =
+ object : MutObj {
+ override var v: T = v
+ }
+
+ fun mutex(v: T): MutObj =
+ object : MutObj {
+ val lock = Lock()
+ override var v: T = v
+ get() = lock.use { field }
+ set(inp) = lock.use { field = inp }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/blitz/OperationChain.kt b/src/main/kotlin/blitz/OperationChain.kt
index 584a300..f92342d 100644
--- a/src/main/kotlin/blitz/OperationChain.kt
+++ b/src/main/kotlin/blitz/OperationChain.kt
@@ -1,5 +1,7 @@
package blitz
+import blitz.collections.selfInitializingSequence
+
class OperationChain private constructor(
private val impl: Impl = Impl()
) {
diff --git a/src/main/kotlin/blitz/async/Lock.kt b/src/main/kotlin/blitz/async/Lock.kt
new file mode 100644
index 0000000..9385298
--- /dev/null
+++ b/src/main/kotlin/blitz/async/Lock.kt
@@ -0,0 +1,11 @@
+package blitz.async
+
+@JvmInline
+value class Lock private constructor(
+ private val impl: Any
+) {
+ constructor(): this(Any())
+
+ fun use(block: () -> R): R =
+ synchronized(impl, block)
+}
\ No newline at end of file
diff --git a/src/main/kotlin/blitz/Batched.kt b/src/main/kotlin/blitz/collections/Batched.kt
similarity index 96%
rename from src/main/kotlin/blitz/Batched.kt
rename to src/main/kotlin/blitz/collections/Batched.kt
index 882b0d5..c9f30b6 100644
--- a/src/main/kotlin/blitz/Batched.kt
+++ b/src/main/kotlin/blitz/collections/Batched.kt
@@ -1,128 +1,128 @@
-package blitz
-
-import kotlin.math.max
-import kotlin.math.min
-
-interface BatchIterator: Iterator {
- fun next(limit: Int): List
- fun next(dest: Array): Int
- fun next(dest: MutableList, limit: Int)
-}
-
-interface ByteBatchIterator: BatchIterator {
- fun nextBytes(limit: Int): ByteArray
-
- fun nextBytes(dest: ByteArray): Int
-}
-
-interface BatchSequence: Sequence {
- override fun iterator(): BatchIterator
-}
-
-interface ByteBatchSequence: BatchSequence {
- override fun iterator(): ByteBatchIterator
-}
-
-/**
- * Batches all get operations on the sequence.
- */
-fun BatchSequence.batched(count: Int): BatchSequence =
- object : BatchSequence {
- inner class Iter: BatchIterator {
- val parent = this@batched.iterator()
-
- var batch = mutableListOf()
-
- override fun next(limit: Int): List {
- if (!hasNext())
- throw Exception("no next")
-
- val c = min(limit, batch.size)
- val ret = batch.take(c)
- batch.removeFirst(c)
- return ret
- }
-
- override fun next(dest: MutableList, limit: Int) {
- if (!hasNext())
- throw Exception("no next")
-
- val c = min(limit, batch.size)
- dest.addAll(batch.subList(0, max(0, c-1)))
- batch.removeFirst(c)
- return
- }
-
- override fun next(dest: Array): Int {
- if (!hasNext())
- throw Exception("no next")
-
- val c = min(dest.size, batch.size)
- batch.subList(0, max(0, c-1)).forEachIndexed { i, t ->
- dest[i] = t
- }
- batch.removeFirst(c)
- return c
- }
-
- override fun next(): T {
- if (!hasNext())
- throw Exception("no next")
- val v = batch.first()
- batch.removeFirst()
- return v
- }
-
- override fun hasNext(): Boolean {
- while (batch.isEmpty()) {
- if (!parent.hasNext())
- return false
- parent.next(batch, count)
- }
- return true
- }
- }
-
- override fun iterator(): BatchIterator =
- Iter()
- }
-
-fun Sequence.asBatch(): BatchSequence =
- object : BatchSequence {
- inner class Iter: BatchIterator {
- var iter = this@asBatch.iterator()
-
- override fun next(limit: Int): List =
- mutableListOf()
- .also { next(it, limit) }
-
- override fun next(dest: MutableList, limit: Int) {
- for (i in 0..): Int {
- var i = 0
- while (i < dest.size) {
- if (!iter.hasNext())
- break
- dest[i ++] = iter.next()
- }
- return i
- }
-
- override fun next(): T {
- return iter.next()
- }
-
- override fun hasNext(): Boolean {
- return iter.hasNext()
- }
- }
-
- override fun iterator(): BatchIterator =
- Iter()
+package blitz.collections
+
+import kotlin.math.max
+import kotlin.math.min
+
+interface BatchIterator: Iterator {
+ fun next(limit: Int): List
+ fun next(dest: Array): Int
+ fun next(dest: MutableList, limit: Int)
+}
+
+interface ByteBatchIterator: BatchIterator {
+ fun nextBytes(limit: Int): ByteArray
+
+ fun nextBytes(dest: ByteArray): Int
+}
+
+interface BatchSequence: Sequence {
+ override fun iterator(): BatchIterator
+}
+
+interface ByteBatchSequence: BatchSequence {
+ override fun iterator(): ByteBatchIterator
+}
+
+/**
+ * Batches all get operations on the sequence.
+ */
+fun BatchSequence.batched(count: Int): BatchSequence =
+ object : BatchSequence {
+ inner class Iter: BatchIterator {
+ val parent = this@batched.iterator()
+
+ var batch = mutableListOf()
+
+ override fun next(limit: Int): List {
+ if (!hasNext())
+ throw Exception("no next")
+
+ val c = min(limit, batch.size)
+ val ret = batch.take(c)
+ batch.removeFirst(c)
+ return ret
+ }
+
+ override fun next(dest: MutableList, limit: Int) {
+ if (!hasNext())
+ throw Exception("no next")
+
+ val c = min(limit, batch.size)
+ dest.addAll(batch.subList(0, max(0, c-1)))
+ batch.removeFirst(c)
+ return
+ }
+
+ override fun next(dest: Array): Int {
+ if (!hasNext())
+ throw Exception("no next")
+
+ val c = min(dest.size, batch.size)
+ batch.subList(0, max(0, c-1)).forEachIndexed { i, t ->
+ dest[i] = t
+ }
+ batch.removeFirst(c)
+ return c
+ }
+
+ override fun next(): T {
+ if (!hasNext())
+ throw Exception("no next")
+ val v = batch.first()
+ batch.removeFirst()
+ return v
+ }
+
+ override fun hasNext(): Boolean {
+ while (batch.isEmpty()) {
+ if (!parent.hasNext())
+ return false
+ parent.next(batch, count)
+ }
+ return true
+ }
+ }
+
+ override fun iterator(): BatchIterator =
+ Iter()
+ }
+
+fun Sequence.asBatch(): BatchSequence =
+ object : BatchSequence {
+ inner class Iter: BatchIterator {
+ var iter = this@asBatch.iterator()
+
+ override fun next(limit: Int): List =
+ mutableListOf()
+ .also { next(it, limit) }
+
+ override fun next(dest: MutableList, limit: Int) {
+ for (i in 0..): Int {
+ var i = 0
+ while (i < dest.size) {
+ if (!iter.hasNext())
+ break
+ dest[i ++] = iter.next()
+ }
+ return i
+ }
+
+ override fun next(): T {
+ return iter.next()
+ }
+
+ override fun hasNext(): Boolean {
+ return iter.hasNext()
+ }
+ }
+
+ override fun iterator(): BatchIterator =
+ Iter()
}
\ No newline at end of file
diff --git a/src/main/kotlin/blitz/BatchedUtils.kt b/src/main/kotlin/blitz/collections/BatchedUtils.kt
similarity index 89%
rename from src/main/kotlin/blitz/BatchedUtils.kt
rename to src/main/kotlin/blitz/collections/BatchedUtils.kt
index f6e2f61..f337239 100644
--- a/src/main/kotlin/blitz/BatchedUtils.kt
+++ b/src/main/kotlin/blitz/collections/BatchedUtils.kt
@@ -1,10 +1,10 @@
-package blitz
-
-fun ByteBatchSequence.stringify(batch: Int = 64): Sequence {
- val iter = iterator()
- return generateSequence {
- if (iter.hasNext())
- iter.nextBytes(batch).decodeToString()
- else null
- }
+package blitz.collections
+
+fun ByteBatchSequence.stringify(batch: Int = 64): Sequence {
+ val iter = iterator()
+ return generateSequence {
+ if (iter.hasNext())
+ iter.nextBytes(batch).decodeToString()
+ else null
+ }
}
\ No newline at end of file
diff --git a/src/main/kotlin/blitz/Contents.kt b/src/main/kotlin/blitz/collections/Contents.kt
similarity index 94%
rename from src/main/kotlin/blitz/Contents.kt
rename to src/main/kotlin/blitz/collections/Contents.kt
index 9b91d54..2151f22 100644
--- a/src/main/kotlin/blitz/Contents.kt
+++ b/src/main/kotlin/blitz/collections/Contents.kt
@@ -1,52 +1,51 @@
-package blitz
-
-class Contents internal constructor(
- private val iterable: Iterable
-): Iterable {
- override fun iterator(): Iterator =
- iterable.iterator()
-
- override fun equals(other: Any?): Boolean {
- if (other !is Contents<*>)
- return false
-
- val it1 = this.iterable.iterator()
- val it2 = other.iterable.iterator()
-
- while (true) {
- val hasNext1 = it1.hasNext()
- val hasNext2 = it2.hasNext()
-
- if ((hasNext1 && !hasNext2) || (hasNext2 && !hasNext1))
- return false
-
- if (!hasNext1)
- return true
-
- if (it1.next() != it2.next())
- return false
- }
- }
-
- override fun hashCode(): Int =
- iterable.hashCode()
-
- override fun toString(): String =
- joinToString(
- separator = ", ",
- prefix = "[",
- postfix = "]"
- ) {
- it.toString()
- }
-}
-
-
-val Iterable.contents get() =
- Contents(this)
-
-val Sequence.contents get() =
- Contents(this.asIterable())
-
-val Array.contents get() =
+package blitz.collections
+
+class Contents internal constructor(
+ private val iterable: Iterable
+): Iterable {
+ override fun iterator(): Iterator =
+ iterable.iterator()
+
+ override fun equals(other: Any?): Boolean {
+ if (other !is Contents<*>)
+ return false
+
+ val it1 = this.iterable.iterator()
+ val it2 = other.iterable.iterator()
+
+ while (true) {
+ val hasNext1 = it1.hasNext()
+ val hasNext2 = it2.hasNext()
+
+ if ((hasNext1 && !hasNext2) || (hasNext2 && !hasNext1))
+ return false
+
+ if (!hasNext1)
+ return true
+
+ if (it1.next() != it2.next())
+ return false
+ }
+ }
+
+ override fun hashCode(): Int =
+ iterable.hashCode()
+
+ override fun toString(): String =
+ joinToString(
+ separator = ", ",
+ prefix = "[",
+ postfix = "]"
+ ) {
+ it.toString()
+ }
+}
+
+val Iterable.contents get() =
+ Contents(this)
+
+val Sequence.contents get() =
+ Contents(this.asIterable())
+
+val Array.contents get() =
Contents(this.asIterable())
\ No newline at end of file
diff --git a/src/main/kotlin/blitz/ListOps.kt b/src/main/kotlin/blitz/collections/ListOps.kt
similarity index 88%
rename from src/main/kotlin/blitz/ListOps.kt
rename to src/main/kotlin/blitz/collections/ListOps.kt
index 598cbd0..dda896f 100644
--- a/src/main/kotlin/blitz/ListOps.kt
+++ b/src/main/kotlin/blitz/collections/ListOps.kt
@@ -1,13 +1,13 @@
-package blitz
-
-fun MutableList.removeFirst(count: Int) {
- repeat(count) {
- removeFirst()
- }
-}
-
-fun MutableList.removeLast(count: Int) {
- repeat(count) {
- removeLast()
- }
+package blitz.collections
+
+fun MutableList.removeFirst(count: Int) {
+ repeat(count) {
+ removeFirst()
+ }
+}
+
+fun MutableList.removeLast(count: Int) {
+ repeat(count) {
+ removeLast()
+ }
}
\ No newline at end of file
diff --git a/src/main/kotlin/blitz/SequenceBase.kt b/src/main/kotlin/blitz/collections/SequenceBase.kt
similarity index 95%
rename from src/main/kotlin/blitz/SequenceBase.kt
rename to src/main/kotlin/blitz/collections/SequenceBase.kt
index c8899df..031bde1 100644
--- a/src/main/kotlin/blitz/SequenceBase.kt
+++ b/src/main/kotlin/blitz/collections/SequenceBase.kt
@@ -1,42 +1,42 @@
-package blitz
-
-interface IndexableSequence: Sequence {
- operator fun get(index: Int): T
-}
-
-fun IndexableSequence.modifier(mod: (Sequence) -> Sequence) =
- object : IndexableSequence {
- val other = mod(this@modifier)
-
- override fun iterator(): Iterator =
- other.iterator()
-
- override fun get(index: Int): T =
- this@modifier[index]
- }
-
-fun Sequence.asIndexable(): IndexableSequence =
- object : IndexableSequence {
- val iter = this@asIndexable.iterator()
- val values = mutableListOf()
-
- override fun get(index: Int): T {
- if (index >= values.size) {
- repeat(index + 1 - values.size) {
- values.add(iter.next())
- }
- }
- return values[index]
- }
-
- override fun iterator(): Iterator =
- object : Iterator {
- var i = 0
-
- override fun hasNext(): Boolean =
- i < values.size || iter.hasNext()
-
- override fun next(): T =
- get(i ++)
- }
+package blitz.collections
+
+interface IndexableSequence: Sequence {
+ operator fun get(index: Int): T
+}
+
+fun IndexableSequence.modifier(mod: (Sequence) -> Sequence) =
+ object : IndexableSequence {
+ val other = mod(this@modifier)
+
+ override fun iterator(): Iterator =
+ other.iterator()
+
+ override fun get(index: Int): T =
+ this@modifier[index]
+ }
+
+fun Sequence.asIndexable(): IndexableSequence =
+ object : IndexableSequence {
+ val iter = this@asIndexable.iterator()
+ val values = mutableListOf()
+
+ override fun get(index: Int): T {
+ if (index >= values.size) {
+ repeat(index + 1 - values.size) {
+ values.add(iter.next())
+ }
+ }
+ return values[index]
+ }
+
+ override fun iterator(): Iterator =
+ object : Iterator {
+ var i = 0
+
+ override fun hasNext(): Boolean =
+ i < values.size || iter.hasNext()
+
+ override fun next(): T =
+ get(i ++)
+ }
}
\ No newline at end of file
diff --git a/src/main/kotlin/blitz/SequenceCreators.kt b/src/main/kotlin/blitz/collections/SequenceCreators.kt
similarity index 93%
rename from src/main/kotlin/blitz/SequenceCreators.kt
rename to src/main/kotlin/blitz/collections/SequenceCreators.kt
index 958fafa..ff330b2 100644
--- a/src/main/kotlin/blitz/SequenceCreators.kt
+++ b/src/main/kotlin/blitz/collections/SequenceCreators.kt
@@ -1,75 +1,77 @@
-package blitz
-
-import kotlin.math.max
-
-fun lazySequence(vararg init: Pair, default: Obj?, f: (Int, (Int) -> T) -> T): IndexableSequence =
- object : IndexableSequence {
- val map = mutableMapOf(*init)
-
- var current: Int? = null
-
- fun comp(iIn: Int): T {
- val i = max(0, iIn)
- if (current == i)
- return (default ?: throw Exception("recursion detected")).v
- return map[i] ?: let {
- current = i
- val res = f(i, ::comp)
- map[i] = res
- current = null
- res
- }
- }
-
- override fun get(index: Int) = comp(index)
-
- override fun iterator(): Iterator =
- object : Iterator {
- override fun hasNext() = true
-
- private var i = 0
-
- override fun next(): T =
- comp(i ++)
- }
- }
-
-fun easySequence(vararg init: Pair, f: (Int, (Int) -> T?) -> T?): Sequence =
- lazySequence(*init, default = Obj(null)) { i, ff ->
- f(i) { index ->
- var indexC = index
- var v: T? = null
- while (indexC > 0 && v == null)
- v = ff(indexC --)
- v
- }
- }
-
-fun Sequence.easyMappingSequence(
- vararg init: Pair,
- f: (Int, (Int) -> T?, (Int) -> I) -> T?
-): Sequence {
- val indexable = this.asIndexable()
- return easySequence(*init) { i, ff ->
- f(i, ff, indexable::get)
- }.limitBy(indexable)
- .removeNull()
-}
-
-fun selfInitializingSequence(block: Provider>): Sequence =
- object : Sequence {
- val seq by lazy(block)
-
- inner class Iter : Iterator {
- val iter = seq.iterator()
-
- override fun hasNext(): Boolean =
- iter.hasNext()
-
- override fun next(): T =
- iter.next()
- }
-
- override fun iterator(): Iterator =
- Iter()
+package blitz.collections
+
+import blitz.Obj
+import blitz.Provider
+import kotlin.math.max
+
+fun lazySequence(vararg init: Pair, default: Obj?, f: (Int, (Int) -> T) -> T): IndexableSequence =
+ object : IndexableSequence {
+ val map = mutableMapOf(*init)
+
+ var current: Int? = null
+
+ fun comp(iIn: Int): T {
+ val i = max(0, iIn)
+ if (current == i)
+ return (default ?: throw Exception("recursion detected")).v
+ return map[i] ?: let {
+ current = i
+ val res = f(i, ::comp)
+ map[i] = res
+ current = null
+ res
+ }
+ }
+
+ override fun get(index: Int) = comp(index)
+
+ override fun iterator(): Iterator =
+ object : Iterator {
+ override fun hasNext() = true
+
+ private var i = 0
+
+ override fun next(): T =
+ comp(i ++)
+ }
+ }
+
+fun easySequence(vararg init: Pair, f: (Int, (Int) -> T?) -> T?): Sequence =
+ lazySequence(*init, default = Obj.of(null)) { i, ff ->
+ f(i) { index ->
+ var indexC = index
+ var v: T? = null
+ while (indexC > 0 && v == null)
+ v = ff(indexC --)
+ v
+ }
+ }
+
+fun Sequence.easyMappingSequence(
+ vararg init: Pair,
+ f: (Int, (Int) -> T?, (Int) -> I) -> T?
+): Sequence {
+ val indexable = this.asIndexable()
+ return easySequence(*init) { i, ff ->
+ f(i, ff, indexable::get)
+ }.limitBy(indexable)
+ .removeNull()
+}
+
+fun selfInitializingSequence(block: Provider>): Sequence =
+ object : Sequence {
+ val seq by lazy(block)
+
+ inner class Iter : Iterator {
+ val iter = seq.iterator()
+
+ override fun hasNext(): Boolean =
+ iter.hasNext()
+
+ override fun next(): T =
+ iter.next()
+ }
+
+ override fun iterator(): Iterator =
+ Iter()
}
\ No newline at end of file
diff --git a/src/main/kotlin/blitz/SequenceOps.kt b/src/main/kotlin/blitz/collections/SequenceOps.kt
similarity index 95%
rename from src/main/kotlin/blitz/SequenceOps.kt
rename to src/main/kotlin/blitz/collections/SequenceOps.kt
index e747cb7..2282b13 100644
--- a/src/main/kotlin/blitz/SequenceOps.kt
+++ b/src/main/kotlin/blitz/collections/SequenceOps.kt
@@ -1,25 +1,25 @@
-package blitz
-
-fun Sequence.removeNull(): Sequence =
- mapNotNull { it }
-
-fun IndexableSequence.removeNull(): IndexableSequence =
- modifier { it.removeNull() }
-
-fun Sequence.limitBy(other: Sequence): Sequence =
- object : Sequence {
- override fun iterator(): Iterator =
- object : Iterator {
- val s = this@limitBy.iterator()
- val o = other.iterator()
-
- override fun hasNext(): Boolean =
- o.hasNext() && s.hasNext()
-
- override fun next(): A =
- s.next().also { o.next() }
- }
- }
-
-fun IndexableSequence.limitBy(other: Sequence): IndexableSequence =
+package blitz.collections
+
+fun Sequence.removeNull(): Sequence =
+ mapNotNull { it }
+
+fun IndexableSequence.removeNull(): IndexableSequence =
+ modifier { it.removeNull() }
+
+fun Sequence.limitBy(other: Sequence): Sequence =
+ object : Sequence {
+ override fun iterator(): Iterator =
+ object : Iterator {
+ val s = this@limitBy.iterator()
+ val o = other.iterator()
+
+ override fun hasNext(): Boolean =
+ o.hasNext() && s.hasNext()
+
+ override fun next(): A =
+ s.next().also { o.next() }
+ }
+ }
+
+fun IndexableSequence.limitBy(other: Sequence): IndexableSequence =
modifier { it.limitBy(other) }
\ No newline at end of file
diff --git a/src/main/kotlin/blitz/func/Utils.kt b/src/main/kotlin/blitz/func/Utils.kt
index 529ba40..e8a8a5b 100644
--- a/src/main/kotlin/blitz/func/Utils.kt
+++ b/src/main/kotlin/blitz/func/Utils.kt
@@ -1,7 +1,7 @@
package blitz.func
-import blitz.ByteBatchSequence
-import blitz.stringify
+import blitz.collections.ByteBatchSequence
+import blitz.collections.stringify
fun Monad>>.flatten(): Monad> =
bind { it.flatten() }
diff --git a/src/main/kotlin/blitz/func/io/File.kt b/src/main/kotlin/blitz/func/io/File.kt
index 69c8d02..d1d4f28 100644
--- a/src/main/kotlin/blitz/func/io/File.kt
+++ b/src/main/kotlin/blitz/func/io/File.kt
@@ -1,6 +1,6 @@
package blitz.func.io
-import blitz.*
+import blitz.collections.ByteBatchSequence
import blitz.func.*
import blitz.io.*
diff --git a/src/main/kotlin/blitz/io/File.kt b/src/main/kotlin/blitz/io/File.kt
index dfbddd8..26471a7 100644
--- a/src/main/kotlin/blitz/io/File.kt
+++ b/src/main/kotlin/blitz/io/File.kt
@@ -1,6 +1,6 @@
package blitz.io
-import blitz.ByteBatchSequence
+import blitz.collections.ByteBatchSequence
import kotlinx.io.Buffer
import kotlinx.io.files.SystemFileSystem
diff --git a/src/main/kotlin/blitz/io/Raw.kt b/src/main/kotlin/blitz/io/Raw.kt
index 7ee063a..8d09840 100644
--- a/src/main/kotlin/blitz/io/Raw.kt
+++ b/src/main/kotlin/blitz/io/Raw.kt
@@ -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.readerSequence(): ByteBatchSequence =