I have released a library called kotlin-tree that allows for declarative handling of multi-way tree data in Kotlin. 🎉
Our API lets you define and perform operations on tree data just like Kotlin’s Collection APIs (map, filter, fold, etc.).
Example usage:
Copy code
val treeNode: TreeNode<Int> = nodeOf(
1,
listOf(
nodeOf(11, listOf(leafOf(111), leafOf(112))),
leafOf(12)
)
)
treeNode.map { ele -> ele * 2 }
Beyond node content operation, kotlin-tree supports conversion between different tree data representations like Adjacency Models and Path Enumeration Models.
If you are interested, feel free to explore our repository at:
https://github.com/YuitoSato/kotlin-tree
👍 1
➕ 1
👏🏾 1
👏 5
j
Javier
07/29/2023, 3:00 AM
Do you think you would add a DSL for trees and transform it into a multiplatform library?
Something like:
@Javier
That’s a good idea. Thank you.
I think I’ll give DSL-style implementation as the next development theme.
Which platform in particular would you like to use for multiple platforms other than jvm? Android?
Don’t worry 😉 I have a custom stdlib in which I added a tree some months ago which I could stop maintain if there is something there to replace it.
As it is a common data structure, it should support all platforms IMO
y
Yuito Sato
07/29/2023, 1:00 PM
Thank you. I seems to be hard to support multi platforms, but I’ll try it.
j
Javier
07/29/2023, 1:12 PM
Same setup with less code indeed, the only thing you have to remember is to publish from a Mac machine, as it is the only which is able to build all targets