play.kotlinlang.org Open in urlscan Pro
3.164.143.110  Public Scan

URL: https://play.kotlinlang.org/?short=We6Pcq1Y_
Submission: On May 03 via api from JP — Scanned from JP

Form analysis 0 forms found in the DOM

Text Content

Take the 5-minute survey so we can improve the Kotlin Playground for you. →
 * Solutions
   * Multiplatform
   * Server-side
   * Data science
   * Android
 * Docs
 * Community
 * Teach
 * Play
   * Playground
   * Examples
   * Koans

SNIPPETS
My code snippet
EXAMPLES
Simple code
Asynchronous
Object-oriented
Functional
Ideal for tests
1.8.21

JVM


Copy linkShare code
Run
fun main() { var orders = listOf<Order>( Order("Cli1", "Cli1_Acc1"),
Order("Cli1", "Cli1_Acc1"), Order("Cli1", "Cli1_Acc1"), Order("Cli1",
"Cli1_Acc1"), Order("", "Cli1_Acc1"), Order("Cli1", "Cli1_Acc2"), Order("Cli2",
"Cli2_Acc1"), Order("Cli1", "Cli1_Acc1"), Order("Cli1", "") ) var orderAccounts
= orders .filter { !it.client.isNullOrEmpty() && !it.account.isNullOrEmpty() }
.distinctBy { it.client + it.account } .map { var fetchedAccount = it.client +
it.account // Fetch account here using client + account println("Fetching:
${it.client} + ${it.account}") Triple(it.client, it.account, fetchedAccount) }
println("Fetched Accounts: $orderAccounts") orders.forEach { order ->
doSomething(order, orderAccounts .firstOrNull() { order.client ==
it.component1() && order.account == it.component2() }?.component3()) } } fun
doSomething(order: Order, account: String?) { println("Updating order: $order,
using account: $account") } class Order(client: String, account: String) { val
client = client val account = account override fun toString(): String =
"($client,$account)" }

xxxxxxxxxx



 

fun main() {

​

    var orders = listOf<Order>(

        Order("Cli1", "Cli1_Acc1"),

        Order("Cli1", "Cli1_Acc1"),

        Order("Cli1", "Cli1_Acc1"),

        Order("Cli1", "Cli1_Acc1"),

        Order("", "Cli1_Acc1"),

        Order("Cli1", "Cli1_Acc2"),

        Order("Cli2", "Cli2_Acc1"),

        Order("Cli1", "Cli1_Acc1"),

        Order("Cli1", "")

    )

    

    var orderAccounts = orders

        .filter { !it.client.isNullOrEmpty() && !it.account.isNullOrEmpty() }

        .distinctBy { it.client + it.account }

        .map {

            var fetchedAccount = it.client + it.account // Fetch account here using client + account

            println("Fetching: ${it.client} + ${it.account}")

            Triple(it.client, it.account, fetchedAccount)

        }

    

    println("Fetched Accounts: $orderAccounts")

    

    orders.forEach { order ->

        doSomething(order, orderAccounts

                .firstOrNull() {

                    order.client == it.component1() && order.account == it.component2()  

                }?.component3())

    }

}

​

fun doSomething(order: Order, account: String?) {

    println("Updating order: $order, using account: $account")

}

​

class Order(client: String, account: String) {

    val client = client

    val account = account

    

    override fun toString(): String = "($client,$account)"

}




Target: JVMRunning on v.1.8.21



Our website uses some cookies and records your IP address for the purposes of
accessibility, security, and managing your access to the telecommunication
network. You can disable data collection and cookies by changing your browser
settings, but it may affect how this website functions. Learn more.

With your consent, JetBrains may also use cookies and your IP address to collect
individual statistics and provide you with personalized offers and ads subject
to the Privacy Policy and the Terms of Use. JetBrains may use third-party
services for this purpose. You can adjust or withdraw your consent at any time
by visiting the Opt-Out page.

[A]ccept All[M]anage Settings