Copyright | Copyright (C) 2021 Yoo Chung |
---|---|
License | GPL-3.0-or-later |
Maintainer | dev@chungyc.org |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
Part of Ninety-Nine Haskell Problems. Some solutions are in Solutions.P61.
Documentation
leaves :: Tree a -> [a] Source #
Collect the leaves of a binary tree in a list. A leaf is a node with no successors.
Examples
>>>
sort $ leaves tree4
[2,4]
Notes
The original problem also included implementing a function which counts leaves.
Instead, the internals
function was moved from problem 62 to this one
because it seemed a more natural grouping.
The examples sort the results to avoid order sensitivity.
It is less of an issue for leaves
, which has a sort of obvious natural order,
but there is no single natural order for internals
.