-- 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.
--   
--   <pre>
--   DList a         ≅ [a] -&gt; [a]
--   NonEmptyDList a ≅ [a] -&gt; NonEmpty a
--   </pre>
--   
--   For empty variant, <tt>DList</tt>, see <a>dlist package</a>.
@package dlist-nonempty
@version 0.1.1


-- | Non-empty difference lists: a data structure for <i>O(1)</i> 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 <tt>[a] -&gt; <a>NonEmpty</a> a</tt>.
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 <tt>DList</tt>.
--   
--   <i>Note:</i> <tt>dlist</tt> doesn't expose internals, so this have to
--   go through list.
toDList :: NonEmptyDList a -> DList a

-- | Convert to representation of <tt>DList</tt>.
toEndo :: NonEmptyDList a -> Endo [a]

-- | Convert to representation of <tt>DList</tt>.
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

-- | <i>O(1)</i>. Prepend a single element to a dlist
cons :: a -> NonEmptyDList a -> NonEmptyDList a
infixr 9 `cons`

-- | <i>O(1)</i>. Append a single element to a dlist
snoc :: NonEmptyDList a -> a -> NonEmptyDList a
infixl 9 `snoc`

-- | <i>O(1)</i>. Append dlists
append :: NonEmptyDList a -> NonEmptyDList a -> NonEmptyDList a

-- | <i>O(spine)</i>. Concatenate dlists
concat1 :: NonEmpty (NonEmptyDList a) -> NonEmptyDList a

-- | <i>O(n)</i>. Create a dlist of the given number of elements.
--   
--   Always creates a list with at least one element.
replicate :: Int -> a -> NonEmptyDList a

-- | <i>O(n)</i>. Return the head of the dlist
head :: NonEmptyDList a -> a

-- | <i>O(n)</i>. Return the tail of the dlist
tail :: NonEmptyDList a -> [a]

-- | <i>O(n)</i>. Unfoldr for dlists
unfoldr :: (b -> (a, Maybe b)) -> b -> NonEmptyDList a

-- | <i>O(n)</i>. Map over difference lists.
map :: (a -> b) -> NonEmptyDList a -> NonEmptyDList b


-- | This module exports the internal representation of
--   <a>NonEmptyDList</a>.
--   
--   Use with care. It's very easy to break the safe interface:
--   
--   <pre>
--   &gt;&gt;&gt; let nedl = NEDL ((1 :|) . map (+1))
--   
--   &gt;&gt;&gt; nedl &lt;&gt; nedl
--   fromNonEmpty (1 :| [2])
--   </pre>
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 <tt>[a] -&gt; <a>NonEmpty</a> a</tt>.
newtype NonEmptyDList a
NEDL :: ([a] -> NonEmpty a) -> NonEmptyDList a
[unNEDL] :: NonEmptyDList a -> [a] -> NonEmpty a
