ninetynine-1.3.0: Ninety-Nine Haskell Problems
Copyright Copyright (C) 2021 Yoo Chung GPL-3.0-or-later dev@chungyc.org Safe-Inferred GHC2021

Problems.P07

Description

Part of Ninety-Nine Haskell Problems. Some solutions are in Solutions.P07.

Synopsis

# Documentation

flatten :: NestedList a -> [a] Source #

Transform a list, possibly holding lists as elements, into a "flat" list by replacing each list with its elements recursively.

### Examples

>>> flatten $Elem 5 [5]  >>> flatten$ List [Elem 1, List [Elem 2, List [Elem 3, Elem 4], Elem 5]]
[1,2,3,4,5]

>>> flatten \$ List []
[]


data NestedList a Source #

A list type with arbitrary nesting of lists.

Constructors

 Elem a A non-list element. List [NestedList a] Nested list.

#### Instances

Instances details
 Source # Instance detailsDefined in Problems.Lists Associated Typestype Rep (NestedList a) :: Type -> Type # Methodsfrom :: NestedList a -> Rep (NestedList a) x #to :: Rep (NestedList a) x -> NestedList a # Show a => Show (NestedList a) Source # Instance detailsDefined in Problems.Lists MethodsshowsPrec :: Int -> NestedList a -> ShowS #show :: NestedList a -> String #showList :: [NestedList a] -> ShowS # Eq a => Eq (NestedList a) Source # Instance detailsDefined in Problems.Lists Methods(==) :: NestedList a -> NestedList a -> Bool #(/=) :: NestedList a -> NestedList a -> Bool # type Rep (NestedList a) Source # Instance detailsDefined in Problems.Lists type Rep (NestedList a) = D1 ('MetaData "NestedList" "Problems.Lists" "ninetynine-1.3.0-4Xxr3hBGtJH9Ff8qb2Invo" 'False) (C1 ('MetaCons "Elem" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: C1 ('MetaCons "List" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [NestedList a])))