-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Non-empty difference lists -- -- Difference lists are a list-like type supporting O(1) append. This is -- particularly useful for efficient logging and pretty printing (e.g. -- with the Writer monad), where list append quickly becomes too -- expensive. -- --
-- DList a ≅ [a] -> [a] -- NonEmptyDList a ≅ [a] -> NonEmpty a ---- -- For empty variant, DList, see dlist package. @package dlist-nonempty @version 0.1 -- | This module exports the internal representation of -- NonEmptyDList. -- -- Use with care. It's very easy to break the safe interface: -- --
-- >>> let nedl = NEDL ((1 :|) . map (+1)) -- -- >>> nedl <> nedl -- fromNonEmpty (1 :| [2]) --module Data.DList.NonEmpty.Unsafe -- | A difference list is a function that, given a list, returns the -- original contents of the difference list prepended to the given list. -- -- Implemented as a newtype over [a] -> NonEmpty a. newtype NonEmptyDList a NEDL :: ([a] -> NonEmpty a) -> NonEmptyDList a [unNEDL] :: NonEmptyDList a -> [a] -> NonEmpty a -- | Non-empty difference lists: a data structure for O(1) append on -- non-empty lists. module Data.DList.NonEmpty -- | A difference list is a function that, given a list, returns the -- original contents of the difference list prepended to the given list. -- -- Implemented as a newtype over [a] -> NonEmpty a. data NonEmptyDList a -- | Convert a dlist to a non-empty list toNonEmpty :: NonEmptyDList a -> NonEmpty a -- | Apply a dlist to a list to get the underlying non-empty list with an -- extension apply :: NonEmptyDList a -> [a] -> NonEmpty a -- | Convert a dlist to a list toList :: NonEmptyDList a -> [a] -- | Convert to DList. -- -- Note: dlist doesn't expose internals, so this have to -- go through list. toDList :: NonEmptyDList a -> DList a -- | Convert to representation of DList. toEndo :: NonEmptyDList a -> Endo [a] -- | Convert to representation of DList. toEndo' :: NonEmptyDList a -> [a] -> [a] -- | Convert a list to a dlist fromNonEmpty :: NonEmpty a -> NonEmptyDList a -- | Create dlist with a single element singleton :: a -> NonEmptyDList a -- | O(1). Prepend a single element to a dlist cons :: a -> NonEmptyDList a -> NonEmptyDList a infixr 9 `cons` -- | O(1). Append a single element to a dlist snoc :: NonEmptyDList a -> a -> NonEmptyDList a infixl 9 `snoc` -- | O(1). Append dlists append :: NonEmptyDList a -> NonEmptyDList a -> NonEmptyDList a -- | O(spine). Concatenate dlists concat1 :: NonEmpty (NonEmptyDList a) -> NonEmptyDList a -- | O(n). Create a dlist of the given number of elements. -- -- Always creates a list with at least one element. replicate :: Int -> a -> NonEmptyDList a -- | O(n). Return the head of the dlist head :: NonEmptyDList a -> a -- | O(n). Return the tail of the dlist tail :: NonEmptyDList a -> [a] -- | O(n). Unfoldr for dlists unfoldr :: (b -> (a, Maybe b)) -> b -> NonEmptyDList a -- | O(n). Map over difference lists. map :: (a -> b) -> NonEmptyDList a -> NonEmptyDList b