Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.NonNull extends the concepts from
Data.List.NonEmpty to any MonoFoldable
.
NonNull
is a newtype wrapper for a container with 1 or more elements.
Synopsis
- data NonNull mono
- fromNullable :: MonoFoldable mono => mono -> Maybe (NonNull mono)
- impureNonNull :: MonoFoldable mono => mono -> NonNull mono
- nonNull :: MonoFoldable mono => mono -> NonNull mono
- toNullable :: NonNull mono -> mono
- fromNonEmpty :: IsSequence seq => NonEmpty (Element seq) -> NonNull seq
- toNonEmpty :: MonoFoldable mono => NonNull mono -> NonEmpty (Element mono)
- ncons :: SemiSequence seq => Element seq -> seq -> NonNull seq
- nuncons :: IsSequence seq => NonNull seq -> (Element seq, Maybe (NonNull seq))
- splitFirst :: IsSequence seq => NonNull seq -> (Element seq, seq)
- nfilter :: IsSequence seq => (Element seq -> Bool) -> NonNull seq -> seq
- nfilterM :: (Monad m, IsSequence seq) => (Element seq -> m Bool) -> NonNull seq -> m seq
- nReplicate :: IsSequence seq => Index seq -> Element seq -> NonNull seq
- head :: MonoFoldable mono => NonNull mono -> Element mono
- tail :: IsSequence seq => NonNull seq -> seq
- last :: MonoFoldable mono => NonNull mono -> Element mono
- init :: IsSequence seq => NonNull seq -> seq
- ofoldMap1 :: (MonoFoldable mono, Semigroup m) => (Element mono -> m) -> NonNull mono -> m
- ofold1 :: (MonoFoldable mono, Semigroup (Element mono)) => NonNull mono -> Element mono
- ofoldr1 :: MonoFoldable mono => (Element mono -> Element mono -> Element mono) -> NonNull mono -> Element mono
- ofoldl1' :: MonoFoldable mono => (Element mono -> Element mono -> Element mono) -> NonNull mono -> Element mono
- maximum :: (MonoFoldable mono, Ord (Element mono)) => NonNull mono -> Element mono
- maximumBy :: MonoFoldable mono => (Element mono -> Element mono -> Ordering) -> NonNull mono -> Element mono
- minimum :: (MonoFoldable mono, Ord (Element mono)) => NonNull mono -> Element mono
- minimumBy :: MonoFoldable mono => (Element mono -> Element mono -> Ordering) -> NonNull mono -> Element mono
- (<|) :: SemiSequence seq => Element seq -> NonNull seq -> NonNull seq
- toMinList :: NonEmpty a -> NonNull [a]
- mapNonNull :: (Functor f, MonoFoldable (f b)) => (a -> b) -> NonNull (f a) -> NonNull (f b)
- class MonoFoldable mono => GrowingAppend mono
Documentation
A monomorphic container that is not null.
Instances
Eq mono => Eq (NonNull mono) # | |
Data mono => Data (NonNull mono) # | |
Defined in Data.NonNull gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> NonNull mono -> c (NonNull mono) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (NonNull mono) # toConstr :: NonNull mono -> Constr # dataTypeOf :: NonNull mono -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (NonNull mono)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (NonNull mono)) # gmapT :: (forall b. Data b => b -> b) -> NonNull mono -> NonNull mono # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NonNull mono -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NonNull mono -> r # gmapQ :: (forall d. Data d => d -> u) -> NonNull mono -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> NonNull mono -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> NonNull mono -> m (NonNull mono) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> NonNull mono -> m (NonNull mono) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> NonNull mono -> m (NonNull mono) # | |
Ord mono => Ord (NonNull mono) # | |
Defined in Data.NonNull | |
Read mono => Read (NonNull mono) # | |
Show mono => Show (NonNull mono) # | |
(Semigroup mono, GrowingAppend mono) => Semigroup (NonNull mono) # | |
GrowingAppend mono => GrowingAppend (NonNull mono) # | |
Defined in Data.NonNull | |
IsSequence mono => MonoComonad (NonNull mono) # | |
MonoPointed mono => MonoPointed (NonNull mono) # | |
MonoTraversable mono => MonoTraversable (NonNull mono) # | |
MonoFoldable mono => MonoFoldable (NonNull mono) # | |
Defined in Data.NonNull ofoldMap :: Monoid m => (Element (NonNull mono) -> m) -> NonNull mono -> m # ofoldr :: (Element (NonNull mono) -> b -> b) -> b -> NonNull mono -> b # ofoldl' :: (a -> Element (NonNull mono) -> a) -> a -> NonNull mono -> a # otoList :: NonNull mono -> [Element (NonNull mono)] # oall :: (Element (NonNull mono) -> Bool) -> NonNull mono -> Bool # oany :: (Element (NonNull mono) -> Bool) -> NonNull mono -> Bool # onull :: NonNull mono -> Bool # olength :: NonNull mono -> Int # olength64 :: NonNull mono -> Int64 # ocompareLength :: Integral i => NonNull mono -> i -> Ordering # otraverse_ :: Applicative f => (Element (NonNull mono) -> f b) -> NonNull mono -> f () # ofor_ :: Applicative f => NonNull mono -> (Element (NonNull mono) -> f b) -> f () # omapM_ :: Applicative m => (Element (NonNull mono) -> m ()) -> NonNull mono -> m () # oforM_ :: Applicative m => NonNull mono -> (Element (NonNull mono) -> m ()) -> m () # ofoldlM :: Monad m => (a -> Element (NonNull mono) -> m a) -> a -> NonNull mono -> m a # ofoldMap1Ex :: Semigroup m => (Element (NonNull mono) -> m) -> NonNull mono -> m # ofoldr1Ex :: (Element (NonNull mono) -> Element (NonNull mono) -> Element (NonNull mono)) -> NonNull mono -> Element (NonNull mono) # ofoldl1Ex' :: (Element (NonNull mono) -> Element (NonNull mono) -> Element (NonNull mono)) -> NonNull mono -> Element (NonNull mono) # headEx :: NonNull mono -> Element (NonNull mono) # lastEx :: NonNull mono -> Element (NonNull mono) # unsafeHead :: NonNull mono -> Element (NonNull mono) # unsafeLast :: NonNull mono -> Element (NonNull mono) # maximumByEx :: (Element (NonNull mono) -> Element (NonNull mono) -> Ordering) -> NonNull mono -> Element (NonNull mono) # minimumByEx :: (Element (NonNull mono) -> Element (NonNull mono) -> Ordering) -> NonNull mono -> Element (NonNull mono) # oelem :: Element (NonNull mono) -> NonNull mono -> Bool # onotElem :: Element (NonNull mono) -> NonNull mono -> Bool # | |
MonoFunctor mono => MonoFunctor (NonNull mono) # | |
SemiSequence seq => SemiSequence (NonNull seq) # | |
Defined in Data.NonNull intersperse :: Element (NonNull seq) -> NonNull seq -> NonNull seq # reverse :: NonNull seq -> NonNull seq # find :: (Element (NonNull seq) -> Bool) -> NonNull seq -> Maybe (Element (NonNull seq)) # sortBy :: (Element (NonNull seq) -> Element (NonNull seq) -> Ordering) -> NonNull seq -> NonNull seq # cons :: Element (NonNull seq) -> NonNull seq -> NonNull seq # snoc :: NonNull seq -> Element (NonNull seq) -> NonNull seq # | |
type Element (NonNull mono) # | |
Defined in Data.NonNull | |
type Index (NonNull seq) # | |
Defined in Data.NonNull |
fromNullable :: MonoFoldable mono => mono -> Maybe (NonNull mono) #
Safely convert from an unsafe monomorphic container to a safe non-null monomorphic container.
impureNonNull :: MonoFoldable mono => mono -> NonNull mono #
Unsafely convert from an unsafe monomorphic container to a safe non-null monomorphic container.
Throws an exception if the monomorphic container is empty.
Since: 1.0.0
nonNull :: MonoFoldable mono => mono -> NonNull mono #
Deprecated: Please use the more explicit impureNonNull instead
Old synonym for impureNonNull
toNullable :: NonNull mono -> mono #
Safely convert from a non-null monomorphic container to a nullable monomorphic container.
fromNonEmpty :: IsSequence seq => NonEmpty (Element seq) -> NonNull seq #
Safely convert from a NonEmpty
list to a non-null monomorphic container.
toNonEmpty :: MonoFoldable mono => NonNull mono -> NonEmpty (Element mono) #
Safely convert from a NonNull
container to a NonEmpty
list.
Since: 1.0.15.0
ncons :: SemiSequence seq => Element seq -> seq -> NonNull seq #
Prepend an element to a SemiSequence
, creating a non-null SemiSequence
.
Generally this uses cons underneath. cons is not efficient for most data structures.
Alternatives:
- if you don't need to cons, use
fromNullable
ornonNull
if you can create your structure in one go. - if you need to cons, you might be able to start off with an efficient data structure such as a
NonEmpty
List.fronNonEmpty
will convert that to your data structure using the structure's fromList function.
nuncons :: IsSequence seq => NonNull seq -> (Element seq, Maybe (NonNull seq)) #
Extract the first element of a sequnce and the rest of the non-null sequence if it exists.
splitFirst :: IsSequence seq => NonNull seq -> (Element seq, seq) #
Same as nuncons
with no guarantee that the rest of the sequence is non-null.
nfilter :: IsSequence seq => (Element seq -> Bool) -> NonNull seq -> seq #
Equivalent to Data.Sequences.
,
but works on non-nullable sequences.filter
nfilterM :: (Monad m, IsSequence seq) => (Element seq -> m Bool) -> NonNull seq -> m seq #
Equivalent to Data.Sequences.
,
but works on non-nullable sequences.filterM
nReplicate :: IsSequence seq => Index seq -> Element seq -> NonNull seq #
head :: MonoFoldable mono => NonNull mono -> Element mono #
tail :: IsSequence seq => NonNull seq -> seq #
Safe version of tailEx
, only working on non-nullable sequences.
last :: MonoFoldable mono => NonNull mono -> Element mono #
init :: IsSequence seq => NonNull seq -> seq #
Safe version of initEx
, only working on non-nullable sequences.
ofoldMap1 :: (MonoFoldable mono, Semigroup m) => (Element mono -> m) -> NonNull mono -> m #
Map each element of a monomorphic container to a semigroup, and combine the results.
Safe version of ofoldMap1Ex
, only works on monomorphic containers wrapped in a
NonNull
.
Examples
ofoldr1 :: MonoFoldable mono => (Element mono -> Element mono -> Element mono) -> NonNull mono -> Element mono #
ofoldl1' :: MonoFoldable mono => (Element mono -> Element mono -> Element mono) -> NonNull mono -> Element mono #
maximumBy :: MonoFoldable mono => (Element mono -> Element mono -> Ordering) -> NonNull mono -> Element mono #
Get the maximum element of a monomorphic container, using a supplied element ordering function.
Safe version of maximumByEx
, only works on monomorphic containers wrapped in a
NonNull
.
minimumBy :: MonoFoldable mono => (Element mono -> Element mono -> Ordering) -> NonNull mono -> Element mono #
Get the minimum element of a monomorphic container, using a supplied element ordering function.
Safe version of minimumByEx
, only works on monomorphic containers wrapped in a
NonNull
.
(<|) :: SemiSequence seq => Element seq -> NonNull seq -> NonNull seq infixr 5 #
Prepend an element to a non-null SemiSequence
.
toMinList :: NonEmpty a -> NonNull [a] #
Specializes fromNonEmpty
to lists only.
mapNonNull :: (Functor f, MonoFoldable (f b)) => (a -> b) -> NonNull (f a) -> NonNull (f b) #
class MonoFoldable mono => GrowingAppend mono #
Containers which, when two values are combined, the combined length is no less than the larger of the two inputs. In code:
olength (x <> y) >= max (olength x) (olength y)
This class has no methods, and is simply used to assert that this law holds, in order to provide guarantees of correctness (see, for instance, Data.NonNull).
This should have a Semigroup
superclass constraint, however, due to
Semigroup
only recently moving to base, some packages do not provide
instances.