0

In the example below, if I try to turn val x into val (x,y) IDE complains vigorously.

If I try to make the return an explicit pair for the val (p,q) assignment it get the same errors.

I do not understand where the problem is.

    val x: Pair<List<Monogram>, List<Double>> = run {
        // Computed integrated percent sorted by descending percent.
        val tot = tcC.sumOf { it.count }
        val sortedByDescendingCount = tcC.sortedByDescending { it.count }

        sortedByDescendingCount to
                sortedByDescendingCount
                    .map { it.count }
                    .runningFold(0.0) { z, x -> z + x }
                    .map { it / tot }
    }

    val (p,q) = run {
        // Computed integrated percent sorted by descending percent.
        val tot = tcC.sumOf { it.count }
        val sortedByDescendingCount = tcC.sortedByDescending { it.count }

        val integral =
                sortedByDescendingCount
                    .map { it.count }
                    .runningFold(0.0) { z, x -> z + x }
                    .map { it / tot }
        Pair(sortedByDescendingCount,integral)
    }

The IDE is

Android Studio Otter | 2025.2.1 Patch 1
Build #AI-252.25557.131.2521.14432022, built on November 13, 2025
Runtime version: 21.0.8+-14196175-b1038.72 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.awt.X11.XToolkit
Linux 6.14.0-36-generic
Ubuntu 24.04.3 LTS; glibc: 2.39
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4096M
Cores: 24
Registry:
  debugger.watches.in.variables=false
  ide.experimental.ui=true
Non-Bundled Plugins:
  com.fwdekker.randomness (3.4.2)
  String Manipulation (9.16.0)
  com.github.marcopla99.cleancoderearranger (1.0.0)
Current Desktop: ubuntu:GNOME
2
  • 1
    Can you post a minimum, reproducible example?  (The question is currently missing some necessary parts, such as tcC — and also seems to include some unnecessary complications, such as the calculations.) Commented 8 hours ago
  • After guessing what Monogram and tcC could look like, I get your code to compile - but without any errors. So when you create the minimal reproducible example that @gidds asked for, please also make sure it actually exhibits the erroneous behavior. Also, make sure your code really contains the problematic val (x,y) (which is missing from your current example code). Commented 7 hours ago

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.