Circular successor & predecessor for bounded enum types
import Data.Enum.Circular (csucc, cpred)
data Direction = N | E | S | W deriving (Show, Eq, Enum, Bounded)
show $ take 6 (iterate csucc N)
-- "[N,E,S,W,N,E]"
csucc
and cpred
are compatible with succ
and pred
, but they behave circular on the type boundaries. Requires Eq
, Enum
and Bounded
instances.
- Mirko Westermeier (@memowe)
Copyright (c) 2023 Mirko Westermeier (@memowe)
Released under the MIT license. See LICENSE for details.