moizest89
04/26/2019, 3:49 PMAnton Lakotka [JB]
04/26/2019, 7:30 PMval todos = (0..1000000).map { payload -> someTaskBuilder(payload) }
// On runtime JVM will try to execute as much as it can at the same time.
val results = todos.map { task -> async { task() } }.awaitAll()
// But I want to confine total amount of running coroutines here.
// Something like this:
coroutineScope ( someContextWithCoroutinesLimit ) {
/* todos execution */
}
Maybe I want something strange.
The reason why I want that is an external system which does some work during task execution. And that external system has Connection Limit. I could fix that by using some Pool. But I was wondering is it possible to limit somehow coroutines amount in easy way.elect
04/26/2019, 7:46 PMMutableMap
till now, but it's quite ugly to extract the K given the V (I can loop on the whole entries
and get the first match).
Is there anything better for my case?Demetrious Robinson
04/26/2019, 9:59 PMdata class Person(val firstName: String ="Demetrious", val lastName:String = "Robinson")
val person1 = Person()
println(person1.component1()) // "Demetrious"
I don't see the use of that as it only returns the value and not the property name. Wouldn't it be simpler to just write
println(person1.firstName)
Andrew Gazelka
04/27/2019, 6:35 PM/**
* Infinite loop that reads this atomic variable and performs the specified [action] on its value.
*/
public inline fun <T> AtomicRef<T>.loop(action: (T) -> Unit): Nothing {
while (true) {
action(value)
}
}
ummm I am confused... why would anyone use this? Why not just AtomicRef#value
? (in regards to https://github.com/Kotlin/kotlinx.coroutines/blob/69c26dfbcefc24c66aadc586f9b5129894516bee/kotlinx-coroutines-core/common/src/sync/Mutex.kt#L146-L155)mvbrenes
04/28/2019, 4:03 AM@NotNull
public final List makeCachedVendorList(@Nullable Integer size) {
int var2 = size != null ? size : TestDataFactory.INSTANCE.randomInt(1, 15);
boolean var3 = false;
boolean var4 = false;
ArrayList var5 = new ArrayList(var2);
boolean var6 = false;
boolean var7 = false;
int var15 = 0;
for(int var8 = var2; var15 < var8; ++var15) {
boolean var10 = false;
int var12 = false;
CachedVendor var14 = makeCachedVendor$default(INSTANCE, 0, 1, (Object)null);
var5.add(var14);
}
return (List)var5;
}
crummy
04/28/2019, 9:49 AMMatthew Good
04/28/2019, 2:59 PMMatthew Good
04/28/2019, 3:08 PMcombinator(val).and(val).and(val).and(val) ...
as at this point the only thing i can think of is to implement it as a linked list but i already use the functions provided by the linked list implementation in combinator
val i = input("1234") // i.value is set to "1234"
val combinator = i.combinator("12")
if (
combinator.peek() // if "1234" starts with "12"
) {
combinator.pop() // i.value is now "34" from "1234"
}
this is my current attempt at making such https://pl.kotl.in/1p-y2OEJA (using a binary tree or similar) which currently fails with n4 it.value = 1
n4 it.value = 2
n5 it.value = 1
n5 it.value = 3
instead of n4 it.value = 1
n4 it.value = 2
n5 it.value = 1
n5 it.value = 2
n5 it.value = 3
for fun main() {
val tree = Tree()
val n1 = tree.Node(1)
val n2 = tree.Node(2)
val n3 = tree.Node(3)
val n4 = n1.append(n2)
val n5 = n4.append(n3)
n1.forEach { println("n1 it.value = ${it.value}") }
n2.forEach { println("n2 it.value = ${it.value}") }
n3.forEach { println("n3 it.value = ${it.value}") }
n4.forEach { println("n4 it.value = ${it.value}") }
n5.forEach { println("n5 it.value = ${it.value}") }
}
Andrew Gazelka
04/28/2019, 4:17 PMList
and expect the contents to be the same, I should create a copy, right? (since the List
might also be Immutable) ... is there any good way to only copy if it is mutable or would that be too much of a micro-optimization?Matthew Good
04/28/2019, 7:03 PMAny
Allan Wang
04/28/2019, 9:11 PMmax.denissov
04/29/2019, 5:40 AMYossi Saiada
04/29/2019, 8:02 AMval file = File("temp")
ObjectOutputStream(FileOutputStream(file)).use { it.writeObject(obj) }
return file.readBytes()
However, I really want to avoid using files. So, I'm wondering whether there is a better/shorter way to achieve the same result.
Thanks 🙂Matthew Good
04/29/2019, 1:16 PMand
and or
right? (not including combinations and association, eg A and B or C
> (A and B) or C
or A and (B or C)
)
fun peek(): Boolean = if (list.size != 0) peekMultiple() else peekSingle()
// private fun peekSingle omited
private fun peekMultiple(): Boolean {
val listTmp = cloneList(list).iterator()
if (list.all { it.type == operatorAnd }) {
var matches = 0
val max = list.size
while (listTmp.hasNext()) {
val stackTmp = listTmp.next().once!!
if (stackTmp.peek()) {
matches++
stackTmp.pop()
} else break
}
if (matches == max) return true
return false
} else if (list.all { it.type == operatorOr }) {
while (listTmp.hasNext()) if (listTmp.next().once!!.peek()) return true
return false
}
else return false // unsupported operator or combination of different operators
}
infix fun and(right: IsSequenceOnce): IsSequenceOnce {
val stackTmp = parent.clone().IsSequenceOnce(this.value)
if (this.list.size != 0) stackTmp.list.addAll(this.list) else stackTmp.list.add(Types().also { it.add(this, operatorAnd) })
if (right.list.size != 0) stackTmp.list.addAll(right.list) else stackTmp.list.add(Types().also { it.add(right, operatorAnd) })
return stackTmp
}
infix fun or(right: IsSequenceOnce): IsSequenceOnce {
val stackTmp = parent.clone().IsSequenceOnce(this.value)
if (this.list.size != 0) stackTmp.list.addAll(this.list) else stackTmp.list.add(Types().also { it.add(this, operatorOr) })
if (right.list.size != 0) stackTmp.list.addAll(right.list) else stackTmp.list.add(Types().also { it.add(right, operatorOr) })
return stackTmp
}
for example,
val E = parseStream.IsSequenceOnce("E")
val F = parseStream.IsSequenceOnce("F")
val FE = F or E
val EF = E and F
println(EF.peek())
println(FE.peek())
arekolek
04/29/2019, 2:06 PMdefault thread-safety mode LazyThreadSafetyMode.SYNCHRONIZED.
Locks are used to ensure that only a single thread can initialize the Lazy instance.
brian
04/29/2019, 2:53 PMMatthew Good
04/29/2019, 4:29 PMval x: Stack<String> = "a"
auto convert to return Stack("a")
via some function without needing to explicitly state val x = Stack<String>("a")
Slackbot
04/29/2019, 5:17 PMMatthew Good
04/29/2019, 5:31 PMinfix
functions in a chain? for example, true and not false
where and
and not
are infix
functionsStefan Peterson
04/29/2019, 6:08 PMself
or something equivalent in a constructor of a data class such that you could do something like:
abstract class A(abstract name: String?)
data class B(override val name: String? = self::class.simpleName): A()
val b = B()
print(b.name) // B
Matthew Good
04/29/2019, 6:19 PMDangelomjoyce
04/29/2019, 10:51 PMrook
04/29/2019, 11:14 PMinterface Foo{
fun createContext(action: MyObject.() -> Unit)
fun MyObject.makeChange()
}
myObject.makeChange() //this should be illegal
myFoo.createContext {
makeChange() //this should be legal
}
Is there a way to achieve what I’m attempting?Dangelomjoyce
04/29/2019, 11:29 PMDangelomjoyce
04/30/2019, 12:38 AMiex
04/30/2019, 12:37 PMiex
04/30/2019, 12:38 PMelect
04/30/2019, 12:54 PMN : Number
. If I have a comparison shall I cast if((v as Int) == (vCur as Int))
or I can leave it plain if(v == vCur)
?Rohit Mohta
04/30/2019, 1:40 PMRohit Mohta
04/30/2019, 1:40 PMgildor
05/02/2019, 1:45 AM