Kristian Nedrevold
12/27/2022, 2:22 PMfun <A, B> memoize (f: (A) -> B) = { a: A ->
val cache = mutableMapOf<A, B>()
cache.computeIfAbsent(a) { f(a) }
}
reactormonk
12/29/2022, 2:00 PMjulian
01/05/2023, 6:14 PMBreaker ACT
02/01/2023, 3:00 AMPiotr Krzemiński
02/08/2023, 7:51 AMvar
or for
loops (mutability in general), with a way to opt out in certain cases. Think: a step towards more pure FP. I’m wondering if you’d be keen to use it and, if yes, what approach you’d suggest to implement it. I’m thinking about a detekt rule or a compiler plugin that would emit an error or a warning (configurable)Teimatini Marin
02/10/2023, 4:39 PMfun main() = runBlocking {
var lastline = ""
readHugeFile().collect { value ->
val lines = (lastline+value).lines()
lines.dropLast(1).forEach {
println(it)
}
lastline = lines.last()
}
println(lastline)
}
fun readHugeFile(): Flow<String> = flowOf(
"""line 1
|line 2
|li""".trimMargin(),
"""ne 3
|line 4
|lin""".trimMargin(),
"""e 5
|line 6
""".trimMargin()
)
dave08
02/13/2023, 4:50 PMdave08
02/14/2023, 12:15 PMclass Foo : IFoo
instead of fun Foo() = object : Foo
?dave08
02/16/2023, 12:08 PM?.
and ?:
be overridable operators for a non-null type... then it could avoid all the `bind()`s and `flatMap`s and hacks that Arrow is doing... did someone ever propose such a thing? (or maybe some similar operator if people might find it too confusing and think that they're dealing with nullables.)João Gabriel Zó
02/16/2023, 5:23 PMResult<Unit>
the best thing to do here or is there anything else in the std library?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 AM