1-----------------------------------------------------------------------------
2-- |
3-- Module      :  Distribution.Compat.SnocList
4-- License     :  BSD3
5--
6-- Maintainer  :  cabal-dev@haskell.org
7-- Stability   :  experimental
8-- Portability :  portable
9--
10-- A very reversed list. Has efficient `snoc`
11module Distribution.Compat.SnocList (
12    SnocList,
13    runSnocList,
14    snoc,
15) where
16
17import Prelude ()
18import Distribution.Compat.Prelude
19
20newtype SnocList a = SnocList [a]
21
22snoc :: SnocList a -> a -> SnocList a
23snoc (SnocList xs) x = SnocList (x : xs)
24
25runSnocList :: SnocList a -> [a]
26runSnocList (SnocList xs) = reverse xs
27
28instance Semigroup (SnocList a) where
29    SnocList xs <> SnocList ys = SnocList (ys <> xs)
30
31instance Monoid (SnocList a) where
32    mempty = SnocList []
33    mappend = (<>)
34