Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/Data/Vector/NonEmpty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
--
-- This library attempts to provide support for all standard 'Vector' operations
-- in the API, with some slight variation in types and implementation. For example,
-- since 'head' and 'foldr' are always gauranteed to be over a non-empty 'Vector',
-- since 'head' and 'foldr' are always guaranteed to be over a non-empty 'Vector',
-- it is safe to make use of the 'unsafe-*' 'Vector' operations and semigroupal
-- folds available in the API in lieu of the standard implementations.
--
-- In contrast, some operations such as 'filter' may "break out" of a 'NonEmptyVector'
-- In contrast, some operations such as 'filter' may "break out" of a t'NonEmptyVector'
-- due to the fact that there are no guarantees that may be made on the types of
-- 'Bool'-valued functions passed in, hence one could write the following:
--
Expand All @@ -31,10 +31,10 @@
-- @
--
-- which always produces an empty vector. Thus, some operations must return either
-- a 'Maybe' containing a 'NonEmptyVector' or a 'Vector' whenever appropriate. Generally
-- a 'Maybe' containing a t'NonEmptyVector' or a 'Vector' whenever appropriate. Generally
-- The former is used in initialization and generation operations, and the latter
-- is used in iterative operations where the intent is not to create an instance
-- of 'NonEmptyVector'.
-- of t'NonEmptyVector'.
--
-- Credit to Roman Leshchinskiy for the original Vector library upon which this is based.
--
Expand Down Expand Up @@ -195,7 +195,7 @@

import qualified Data.Foldable as Foldable
import Data.Either (Either(..))
import Data.Functor hiding (unzip)

Check warning on line 198 in src/Data/Vector/NonEmpty.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 9.4)

Module ‘Data.Functor’ does not export ‘unzip’

Check warning on line 198 in src/Data/Vector/NonEmpty.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 9.4)

Module ‘Data.Functor’ does not export ‘unzip’

Check warning on line 198 in src/Data/Vector/NonEmpty.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 9.6)

Module ‘Data.Functor’ does not export ‘unzip’

Check warning on line 198 in src/Data/Vector/NonEmpty.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 9.6)

Module ‘Data.Functor’ does not export ‘unzip’
import Data.Int
import Data.List.NonEmpty (NonEmpty(..))
import qualified Data.List.NonEmpty as NonEmpty
Expand Down Expand Up @@ -232,8 +232,8 @@
length = V.length . _neVec
{-# INLINE length #-}

-- | /O(1)/ First element. Since head is gauranteed, bounds checks
-- are bypassed by deferring to 'unsafeHead'.
-- | /O(1)/ First element. Since head is guaranteed, bounds checks
-- are bypassed by deferring to 'Data.Vector.unsafeHead'.
--
--
-- >>> head $ unsafeFromList [1..10]
Expand All @@ -243,8 +243,8 @@
head = V.unsafeHead . _neVec
{-# INLINE head #-}

-- | /O(1)/ Last element. Since a last element is gauranteed, bounds checks
-- are bypassed by deferring to 'unsafeLast'.
-- | /O(1)/ Last element. Since a last element is guaranteed, bounds checks
-- are bypassed by deferring to 'Data.Vector.unsafeLast'.
--
--
-- >>> last $ unsafeFromList [1..10]
Expand Down Expand Up @@ -291,7 +291,7 @@
-- The monad allows operations to be strict in the non-empty vector when
-- necessary.
--
-- See 'V.indexM' for more details
-- See 'Data.Vector.indexM' for more details
--
--
-- >>> indexM @[] (unsafeFromList [1..10]) 3
Expand All @@ -303,10 +303,10 @@

-- | /O(1)/ First element of a non-empty vector in a monad.
--
-- See 'V.indexM' for an explanation of why this is useful.
-- See 'Data.Vector.indexM' for an explanation of why this is useful.
--
-- Note that this function defers to 'unsafeHeadM' since head is
-- gauranteed to be safe by construction.
-- Note that this function defers to 'Data.Vector.unsafeHeadM' since head is
-- guaranteed to be safe by construction.
--
--
-- >>> headM @[] (unsafeFromList [1..10])
Expand All @@ -316,11 +316,11 @@
headM (NonEmptyVector v) = V.unsafeHeadM v
{-# INLINE headM #-}

-- | /O(1)/ Last element of a non-empty vector in a monad. See 'V.indexM' for an
-- explanation of why this is useful.
-- | /O(1)/ Last element of a non-empty vector in a monad. See 'Data.Vector.indexM'
-- for an explanation of why this is useful.
--
-- Note that this function defers to 'unsafeHeadM' since a last element is
-- gauranteed.
-- Note that this function defers to 'Data.Vector.unsafeLastM' since a last element is
-- guaranteed.
--
--
-- >>> lastM @[] (unsafeFromList [1..10])
Expand Down Expand Up @@ -1735,7 +1735,7 @@
{-# INLINE izipWith6 #-}

-- | /O(min(n,m))/ Elementwise pairing of non-empty vector elements. This is a special case
-- of 'zipWith' where the function argument is '(,)'
-- of 'zipWith' where the function argument is @(,)@
--
zip :: NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector (a, b)
zip a b = NonEmptyVector (V.zip a' b')
Expand Down Expand Up @@ -2013,7 +2013,7 @@
--
-- If no elements satisfy the predicate, the resulting vector may be empty.
--
-- TODO: this should be a more efficient function in `vector`.
-- TODO: this should be a more efficient function in @vector@.
--
-- >>> ifilterM (\i a -> if a == 2 || i == 0 then Just False else Just True) (unsafeFromList [1..3])
-- Just [3]
Expand Down Expand Up @@ -2651,8 +2651,8 @@
iscanr' f b = NonEmptyVector . V.iscanr' f b . _neVec
{-# INLINE iscanr' #-}

-- | /O(n)/ The 'intersperse' function takes an element and a NonEmptyVector
-- and 'intersperses' that element between the elements of the NonEmptyVector.
-- | /O(n)/ The 'intersperse' function takes an element and a 'NonEmptyVector'
-- and "intersperses" that element between the elements of the 'NonEmptyVector'.
--
-- >>> intersperse 0 (unsafeFromList [1,2,3])
-- [1,0,2,0,3]
Expand Down
18 changes: 9 additions & 9 deletions src/Data/Vector/NonEmpty/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-- Portability : non-portable
--
-- Internal module exposing the constructors for
-- 'NonEmptyVector' and 'NonEmptyMVector'.
-- t'NonEmptyVector' and t'NonEmptyMVector'.
--
-- /Warning/: Since the constructors are exposed here, by using this
-- module, you take on the risks that you break the non-emptiness
Expand Down Expand Up @@ -54,13 +54,13 @@ import qualified Text.Read as Read
-- ---------------------------------------------------------------------- --
-- Non-empty immutable vectors

-- | 'NonEmptyVector' is a thin wrapper around 'Vector' that
-- | t'NonEmptyVector' is a thin wrapper around 'Data.Vector.Vector' that
-- witnesses an API requiring non-empty construction,
-- initialization, and generation of non-empty vectors by design.
--
-- A newtype wrapper was chosen so that no new pointer indirection
-- is introduced when working with 'Vector's, and all performance
-- characteristics inherited from the 'Vector' API still apply.
-- is introduced when working with 'Data.Vector.Vector's, and all performance
-- characteristics inherited from the "Data.Vector" API still apply.
--
-- @since 0.2.1.0
--
Expand Down Expand Up @@ -98,8 +98,8 @@ instance Foldable NonEmptyVector where
instance Foldable1 NonEmptyVector where
foldMap1 f (NonEmptyVector v) =
let
h = V.unsafeHead v -- gauranteed head (nonemptiness)
t = V.unsafeTail v -- gauranteed possibly empty tail
h = V.unsafeHead v -- guaranteed head (nonemptiness)
t = V.unsafeTail v -- guaranteed possibly empty tail
in go (f h) t -- therefore this is a sound call
where
go x xs
Expand All @@ -119,7 +119,7 @@ instance Traversable NonEmptyVector where
-- ---------------------------------------------------------------------- --
-- Non-empty mutable vectors

-- | 'NonEmptyMVector' is a thin wrapper around 'MVector' that
-- | t'NonEmptyMVector' is a thin wrapper around 'MVector' that
-- witnesses an API requiring non-empty construction,
-- initialization, and generation of non-empty vectors by design.
--
Expand All @@ -135,13 +135,13 @@ newtype NonEmptyMVector s a = NonEmptyMVector
deriving (Typeable)
#endif

-- | 'NonEmptyMVector' parametrized by 'PrimState'
-- | t'NonEmptyMVector' parametrized by 'Control.Monad.Primitive.PrimState' 'IO'.
--
-- @since 0.2.1.0
--
type NonEmptyIOVector = NonEmptyMVector RealWorld

-- | 'NonEmptyMVector' parametrized by 'ST'
-- | t'NonEmptyMVector' parametrized by @t'Control.Monad.Primitive.PrimState' ('ST' s)@.
--
-- @since 0.2.1.0
--
Expand Down