Last active
October 6, 2016 16:25
-
-
Save ravinggenius/825e9a1a69916058e147 to your computer and use it in GitHub Desktop.
System.List.flatten
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
System.List = class<T> { | |
flatten = => { | |
-> (list<System.List>) { | |
switch (list.count) { | |
case (0) { list } | |
case (1) { [ self(list.head) ] } | |
else { [ ...self(list.head), ...self(list.tail) ] } | |
} | |
} | |
-> (object<System.Object>) { object } | |
} | |
@.flatten = -> { | |
@.type.flatten(@) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment