This file contains hidden or 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
module Main where | |
-- A MoreList is either a More value which contains a list of MoreList's, or | |
-- an Elem value, which contains a single value of type a | |
data MoreList a = More [MoreList a] | |
| Elem a | |
flatten :: MoreList a -> [a] | |
flatten (Elem a) = [a] |
This file contains hidden or 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
import itertools | |
# Utilities | |
# Using curried form | |
# Split an iterable at a point where some given predicate is met | |
split_at = lambda f: lambda l: \ | |
(itertools.takewhile(lambda e: not f(e), l), itertools.dropwhile(lambda e: not f(e), l)) | |
# Append an element to a list |