| License | BSD-3-Clause |
|---|---|
| Maintainer | Preetham Gujjula <libraries@mail.preetham.io> |
| Stability | experimental |
| Safe Haskell | Safe-Inferred |
| Language | GHC2021 |
Data.List.ApplyMerge
Description
Synopsis
- applyMerge :: Ord c => (a -> b -> c) -> [a] -> [b] -> [c]
Documentation
applyMerge :: Ord c => (a -> b -> c) -> [a] -> [b] -> [c] Source #
If given a binary function f that is non-decreasing in both arguments,
and two (potentially infinite) ordered lists xs and ys, then
is a sorted list of all applyMerge f xs ysf x y, for each x in
xs and y in ys.
Producing \(n\) elements of takes \(O(n \log n)\)
time and \(O(\sqrt{n})\) auxiliary space, assuming that applyMerge f xs ysf and compare
take \(O(1)\) time.
For example, to generate the 3-smooth numbers (Wikipedia):
smooth3 :: [Integer] smooth3 = applyMerge (*) (iterate (*2) 1) (iterate (*3) 1)
For more examples, see README#examples.