Separate the empty prefix from the prefixes beginning with the first element:
inits :: [a] -> [[a]]
inits [] = [[]]
inits (x:xs) = [] : map (x:) (inits xs)Every nonempty list prefix begins with
x and continues with a prefix of xs. Thus the recursive order is increasing prefix length, beginning with length zero. Lazy evaluation can also expose every finite prefix of a productive infinite input. Articles by others on the same topic
There are currently no matching articles.