Tree from nesting levels: Difference between revisions

Content added Content deleted
m (→‎{{header|Haskell}}: return -> pure)
Line 60: Line 60:
uncurry (:) $
uncurry (:) $
bimap (Node v . go) go (span ((n <) . fst) xs)
bimap (Node v . go) go (span ((n <) . fst) xs)


--------------------- TEST AND DISPLAY -------------------
--------------------- TEST AND DISPLAY -------------------
Line 84: Line 83:
display = drawTree . Node "Nothing" . fmap (fmap show)
display = drawTree . Node "Nothing" . fmap (fmap show)


----------- MAPPING TO A STRICTER DATA STRUCTURE ---------
----------- MAPPING TO A STRICTER DATA STRUCTURE ---------


Line 94: Line 92:
go xs@((1, mb) : _) = xs
go xs@((1, mb) : _) = xs
go xs@((n, mb) : _) =
go xs@((n, mb) : _) =
fmap
fmap (,Nothing) [1 .. pred n] <> xs
(,Nothing)
[1 .. pred n]
<> xs


-- Representation of implicit nodes.
-- Representation of implicit nodes.