uccessorBy, predecessorBy :: (a -> a
-> Ordering) -> a -> [a] -> a
successor, predecessor
:: Ord a
=> a -> [a] -> a
successor = successorBy
compare
successorBy cmp x = minimumBy cmp . filter (\y -> cmp x y
== LT)
predecessor = predecessorBy compare
predecessorBy cmp
= successorBy (flip cmp)
The reason these operations exist is to
pick neighbouring
elements in SortedCollections and SortedSets.
But they make
*sense* for any Enumerable. So there are
"generic"
definitions with orderrides for those two
classes.
A filter + a reduce .
Traditionally, a #select:thenFold:ifNone:
in order to
avoid building an intermediate collection. That much
I see how
to do with transducers. But you can't get the desired
override
for #successor:[sortBlock:][ifNone:] by overriding
#select:thenFold:ifNone: in SortedCollection or
SortedSet. So what
*should* one
do?