Skip to content

API idea: name-based-destructuring #1819

@Jolanrensen

Description

@Jolanrensen

Background:
https://kotlinlang.org/docs/whatsnew2320.html#name-based-destructuring
Kotlin/KEEP#438
https://github.com/Kotlin/KEEP/blob/main/proposals/KEEP-0438-name-based-destructuring.md
https://youtrack.jetbrains.com/issue/KT-19627

We could think about adding these to the API for DataFrames, columns, and rows.

For instance:

Position based:

val [value1, value2, value3] = myColumn
[val value1, val value2, val value3] = myColumn

// if added, though, better alternatives already exist
df.select { cols { [firstVal] -> firstVal == 0 } }
val [value1, value2, value3] = myRow
[val value1, val value2, val value3] = myRow

// we already have better alternatives here too
df.filter { [value1, value2] -> value1 == 0 || value2 == 0  }
val [row1, row2, row3] = myDf
[val row1, val row2, val row3] = myDf

Name based (more useful!):

val (colA, colB) = myRow
(val name = colA, val colB) = myRow

// inline and partial renaming of column value names is now possible!
df.filter { (val name = colA, val colB) -> name == "" || colB == 0 }
val (colA, colB) = myDf
(val nameCol = colA, val colB) = myDf

It's already possible to experiment with this, though the implementation in Kotlin is not final yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIIf it touches our API

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions