dave08
02/20/2023, 10:43 AMRuntime.getRuntime().addShutdownHook(hook)
, is that only SIGINT? It seems like in your video it was clearly using SIGINT, but in my current version not...Mazhar Ibna Zahur
02/23/2023, 10:58 AMNorbi
02/25/2023, 9:16 AMNorbi
03/01/2023, 9:26 AMraise()
functionality and I try to find a library function similar to the following hypothetical orElse()
:
context(Raise<String>)
fun f1() = 1
context(Raise<String>)
fun f2(): Nothing = raise("error")
suspend inline fun <R, A> Effect<R, A>.orElse(noinline block: suspend (R) -> A) =
fold(
recover = block,
transform = ::identity
)
val v1 = effect { f1() }.orElse { 33 }
assertEquals(1, v1)
val v2 = effect { f2() }.orElse { 33 }
assertEquals(33, v2)
I use arrow 1.1.6-alpha.36.
Thanks.Kristian Nedrevold
03/07/2023, 9:18 PMdori
03/10/2023, 10:24 AMjean
03/17/2023, 11:26 AMdata class SomeData(val someValue: String) {
companion object {
fun someFunction() {}
}
}
// OR
data class SomeData(val someValue: String) {
companion object
}
fun SomeData.Companion.someFunction() {}
João Gabriel Zó
03/17/2023, 6:00 PMfunctionOne: Result<Something>
functionTwo: Result<Unit>
I’ll only call functionTwo if the first one returns a Success, and return a Result<Something>
in case both of them return a Success.
What’s the best way to do it using std lib? I thought the nested folds and maps and ifs turned out a bit uglyNorbi
05/19/2023, 7:58 AMNathan Bedell
06/27/2023, 4:19 PM(State, Action) -> State
, but my question was more about how to actually action this reducer to do stuff with the UI.
Currently we are taking in a Flow of Actions, an initial state, and updating that state (as a StateFlow) by launching a collect block on the action flow to update the state. The body of the collect statement on the flow is synchronized with a mutex so actions should (I was hoping anyway) get executed in order sequentially.
In practice, this seems to work. However, I've noticed in tests this sometimes fails, which makes me wonder if my setup of this is actually optimal. I was thinking maybe a channel of user actions might be more robust, but open to ideas!Uberto Barbini
10/08/2023, 12:21 AMreactormonk
11/22/2023, 6:31 PMreduce
where I can pass the initial acc
?reactormonk
11/22/2023, 6:34 PMS
of the result even come from? O.oYoussef Shoaib [MOD]
01/13/2024, 10:23 PMJun Sekine
01/15/2024, 5:49 AMThomas
01/17/2024, 2:46 AMfun <A, B, R> Collection<A>.combine(other: Collection<B>, transformation:(A, B)->R): List<R> =
ArrayList<R>(this.size * other.size).also{
for(a in this){
for(b in other){
it.add(transformation(a, b))
}
}
}
Example:
fun main(){
println(
listOf(1,2,3).combine(listOf("a", "b", "c")){a, b -> "$a-$b"}
)
}
Output:
[1-a, 1-b, 1-c, 2-a, 2-b, 2-c, 3-a, 3-b, 3-c]
Thomas
01/17/2024, 2:51 AMcartesianProduct
?Christopher Hübner
02/05/2024, 2:43 PMreactormonk
02/05/2024, 3:04 PMChristopher Hübner
02/15/2024, 8:41 AMKev
03/19/2024, 10:59 AMwith(..)
clause?Emre
04/24/2024, 4:37 PMreactormonk
05/25/2024, 6:47 PMYoussef Shoaib [MOD]
06/04/2024, 1:40 PMsuspend
and a Channel
to pass a value "backwards" in time, but I don't trust that it's actually "correct"reactormonk
06/19/2024, 7:28 AMwhen
on two items? Use a Pair
and deconstruct using to
?Pablichjenkov
06/27/2024, 10:51 PMalgebraic data types
?
What's the relationship with algebra?reactormonk
11/28/2024, 12:51 PMUlrich Schuster
12/25/2024, 1:36 PMf(x: X, (X) -> Y): Y
that takes some argument x: X
and a function (X) -> Y
. And I have a concrete function with receiver, say Int.makeY(x: X): Y
. I would like to partially apply makeY
to a given receiver and pass it to f
, like
val foo = 5
f(x) { foo::makeY }
However, this results in an ArgumentTypeMismatch compilation error, stating that Y
was expected instead of the provided function reference. Am I simply making a mistake in my declaration, or is it simply not possible to pass a partially applied function with receiver as reference?Youssef Shoaib [MOD]
05/26/2025, 5:10 PMSTRef
and the STScope
itself may both escape, but they're only usable exactly in the region they were gotten in!) (playground)
import kotlin.coroutines.Continuation
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.RestrictsSuspension
import kotlin.coroutines.intrinsics.startCoroutineUninterceptedOrReturn
class STRef<in R, S> internal constructor(internal var state: S)
@RestrictsSuspension
interface STScope<R> {
suspend fun <S> new(init: S): STRef<R, S> = STRef(init)
suspend fun <S> STRef<R, S>.get(): S = state
suspend fun <S> STRef<R, S>.set(value: S) {
state = value
}
suspend fun subregion(block: suspend SubSTScope<*, R>.() -> Unit)
}
// could use typealias instead, but bad IDE support
interface SubSTScope<R1 : R2, R2> : STScope<R1>
class STScopeImpl<R> : SubSTScope<R, R> {
// could even be inline!
override suspend fun subregion(block: suspend SubSTScope<*, R>.() -> Unit) = block()
}
fun <R> runST(block: suspend STScope<*>.() -> R): R =
block.startCoroutineUninterceptedOrReturn(STScopeImpl<Any?>(), Continuation(EmptyCoroutineContext) {}) as R
fun main() {
runST {
// need to use inner functions here because the compiler isn't smart enough about existential
// Outference might solve this problem!
suspend fun <R> STScope<R>.example() {
val ref = new(0)
ref.set(42)
println(ref.get()) // prints 42
//val escape = { ref.get() } // not allowed to escape
//val escape = runST { ref.get() } // still not allowed to escape
//runST { with(this@example) { ref.get() } } // even this doesn't work!
subregion {
suspend fun <R1: R> STScope<R1>.inside() {
val innerRef = new(0)
innerRef.set(100)
println(innerRef.get()) // prints 100
println(ref.get()) // prints 42
}
inside()
}
}
example()
}
}
I hence conjecture that @RestrictsSuspension
subsumes the concept of monadic regions, albeit while limiting some of Kotlin's magic (can't use general suspend
functions inside, can't extend them easily, etc).
In fact, I think Kotlin may have just enough features to enable general capability/resource tracking.oligarchokapi
06/14/2025, 10:53 PMval sortedFaces: List<Pair<Int, List<Int>>> get() {
return faces.mapIndexed { i, it ->
Pair(i, it)
}.sortedByDescending { indexedFace ->
indexedFace.second.minByOrNull {
vertices[it].z
}
}.also {
it.forEach {
println("${it.first}: ${it.second.map { vertices[it].z }.min() }")
}
println()
}
}
and prints something like this:
5: 0.535865025190621
3: -1.1402821230261972
0: -1.3581312119491156
2: -1.3581312119491156
4: -1.3581312119491156
1: -0.7537141141135403
how can it possibly print a wrongly sorted list here?