https://kotlinlang.org logo
#announcements
Title
# announcements
e

egorand

07/20/2019, 2:55 AM
It’s just an iterable of iterables of
T
which gets flattened into a list of
T
. Here’s an example:
Copy code
[[1, 2, 3], [4], [5, 6]] -> flatten -> [1, 2, 3, 4, 5, 6]
i

Ifvwm

07/20/2019, 3:16 AM
I thought it was like a recursive type, it seems I was wrong, so I wonder can we do that MapTree on kotlin? data Tree a = Leaf a | Node (Tree a) (Tree a) deriving (Show)
s

Shawn

07/20/2019, 3:38 AM
It is indeed a recursive generic type but you’re not going to be able to do anything particularly Haskell-ey with them
i

Ifvwm

07/20/2019, 3:44 AM
@Shawn aha, why?
d

Dico

07/20/2019, 7:47 AM
You can do @Ifvwm
Copy code
sealed class Tree<T> {
    class Leaf<T>(val value: T) : Tree<T>() 
    class Node<T>(val left: Tree<T>, val right: Tree<T>) : Tree<T>()
}
4 Views