ModuleAgda-2.7.0.1Haskell2010
Agda.Utils.List1
Non-empty lists.
Better name List1 for non-empty lists, plus missing functionality.
Import: @
{-# LANGUAGE PatternSynonyms #-}
import Agda.Utils.List1 (List1, pattern (:|)) import qualified Agda.Utils.List1 as List1
@
- 3 types
- 1 class
- 98 values
- PackageAgda-2.7.0.1
- Exports103
- LanguageHaskell2010
- LicenceMIT
- SourceList1.hs
Like catMaybes.
Like zipWithM.
Like partitionEithers.
Like zipWithM.
Like union. Duplicates in the first list are not removed. O(nm).
Like mapMaybe.
Return the last element and the rest.
Like find.
Like lefts.
Build a list with one element.
More precise type for snoc.
Update the first element of a non-empty list. O(1).
Update the last element of a non-empty list. O(n).
Concatenate one or more non-empty lists.
Like unwords.
List Data.List.foldr but with a base case for the singleton list.
Like rights.
Last two elements (safe). O(n).
Breaks a list just after an element satisfying the predicate is found.
breakAfter even [1,3,5,2,4,7,8](1 :| [3,5,2],[4,7,8])
Checks if all the elements in the list are equal. Assumes that the Eq instance stands for an equivalence relation. O(n).
Non-efficient, monadic nub. O(n²).
Split a list into sublists. Generalisation of the prelude function
words.
Same as Data.List.Split.wordsBy and Data.List.Extra.wordsBy,
but with the non-emptyness guarantee on the chunks.
O(n).
words xs == wordsBy isSpace xsfromListSafe Safe version of fromList.
More precise type for Agda.Utils.List.groupBy'.
A variant of groupBy which applies the predicate to consecutive pairs. O(n).
Group consecutive items that share the same first component.
Group consecutive items that share the same first component.
Focus on the first element of a non-empty list. O(1).
Focus on the last element of a non-empty list. O(n).
The group function takes a stream and returns a list of streams such that flattening the resulting list is equal to the argument. Moreover, each stream in the resulting list contains only equal elements, and consecutive equal elements of the input end up in the same stream of the output list. For example, in list notation:
group "Mississippi"["M", "i", "ss", "i", "ss", "i", "pp", "i"]
xs !! n returns the element of the stream xs at index
n. Note that the head of the stream has index 0.
Beware: a negative or out-of-bounds index will cause an error.
The isPrefixOf function returns True if the first argument is a prefix of the second.
Non-empty (and non-strict) list type.
Constructors
a :| [a]infixr 5
Instances86Monad, Functor, MonadFix, IsString, Applicative, Foldable, …
Monad NonEmptyDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseFunctor NonEmptyDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseMonadFix NonEmptyDefined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.FixIsString String1Defined in Agda-2.7.0.1 · Agda.Utils.String · orphanApplicative NonEmptyDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseFoldable NonEmptyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableTraversable NonEmptyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.TraversableMonadZip NonEmptyDefined in base-4.20.2.0 · Control.Monad.ZipFoldable1 NonEmptyDefined in base-4.20.2.0 · Data.Foldable1Eq1 NonEmptyDefined in base-4.20.2.0 · Data.Functor.ClassesOrd1 NonEmptyDefined in base-4.20.2.0 · Data.Functor.ClassesRead1 NonEmptyDefined in base-4.20.2.0 · Data.Functor.ClassesShow1 NonEmptyDefined in base-4.20.2.0 · Data.Functor.ClassesNFData1 NonEmptyDefined in deepseq-1.5.0.0 · Control.DeepSeqHashable1 NonEmptyDefined in hashable-1.4.7.0 · Data.Hashable.ClassComonad NonEmptyDefined in comonad-5.0.9 · Control.ComonadComonadApply NonEmptyDefined in comonad-5.0.9 · Control.ComonadAlt NonEmptyDefined in semigroupoids-6.0.1 · Data.Functor.AltApply NonEmptyDefined in semigroupoids-6.0.1 · Data.Functor.Bind.ClassBind NonEmptyDefined in semigroupoids-6.0.1 · Data.Functor.Bind.ClassExtend NonEmptyDefined in semigroupoids-6.0.1 · Data.Functor.ExtendTraversable1 NonEmptyDefined in semigroupoids-6.0.1 · Data.Semigroup.Traversable.ClassSemialign NonEmptyDefined in semialign-1.3.1 · Data.Semialign.InternalRepeat NonEmptyDefined in semialign-1.3.1 · Data.Semialign.InternalUnzip NonEmptyDefined in semialign-1.3.1 · Data.Semialign.InternalZip NonEmptyDefined in semialign-1.3.1 · Data.Semialign.InternalFromJSON1 NonEmptyDefined in aeson-2.2.3.0 · Data.Aeson.Types.FromJSONToJSON1 NonEmptyDefined in aeson-2.2.3.0 · Data.Aeson.Types.ToJSONNumHoles NamePartsDefined in Agda-2.7.0.1 · Agda.Syntax.Concrete.NameGeneric1 NonEmptyDefined in ghc-internal-9.1003.0 · GHC.Internal.GenericsFoldableWithIndex Int NonEmptyDefined in indexed-traversable-0.1.4 · WithIndexFoldable1WithIndex Int NonEmptyDefined in indexed-traversable-0.1.4 · WithIndexFunctorWithIndex Int NonEmptyDefined in indexed-traversable-0.1.4 · WithIndexTraversableWithIndex Int NonEmptyDefined in indexed-traversable-0.1.4 · WithIndexRepeatWithIndex Int NonEmptyDefined in semialign-1.3.1 · Data.Semialign.InternalSemialignWithIndex Int NonEmptyDefined in semialign-1.3.1 · Data.Semialign.InternalZipWithIndex Int NonEmptyDefined in semialign-1.3.1 · Data.Semialign.InternalLift a => Lift (NonEmpty a)Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxSingleton a (NonEmpty a)Defined in Agda-2.7.0.1 · Agda.Utils.SingletonIsList (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.IsListEq a => Eq (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseData a => Data (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataOrd a => Ord (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseRead a => Read (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.ReadShow a => Show (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.ShowGeneric (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsSemigroup (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseNFData a => NFData (NonEmpty a)Defined in deepseq-1.5.0.0 · Control.DeepSeqBinary a => Binary (NonEmpty a)Defined in binary-0.8.9.3 · Data.Binary.ClassHashable a => Hashable (NonEmpty a)Defined in hashable-1.4.7.0 · Data.Hashable.ClassFromJSON a => FromJSON (NonEmpty a)Defined in aeson-2.2.3.0 · Data.Aeson.Types.FromJSONToJSON a => ToJSON (NonEmpty a)Defined in aeson-2.2.3.0 · Data.Aeson.Types.ToJSONToMarkup (NonEmpty Char)Defined in blaze-markup-0.8.3.0 · Text.BlazeToValue (NonEmpty Char)Defined in blaze-markup-0.8.3.0 · Text.BlazePretty a => Pretty (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.Common.PrettyPretty a => Pretties (List1 a)Defined in Agda-2.7.0.1 · Agda.Compiler.JS.PrettyHasRange a => HasRange (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.PositionPrecondition: The ranges of the list elements must point to the same file (or be empty).
ToConcrete a => ToConcrete (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.Translation.AbstractToConcreteHilite a => Hilite (List1 a)Defined in Agda-2.7.0.1 · Agda.Interaction.Highlighting.FromAbstractSubstExpr a => SubstExpr (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.AbstractKillRange a => KillRange (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.PositionSized (List1 a)Defined in Agda-2.7.0.1 · Agda.Utils.SizeBoundAndUsed a => BoundAndUsed (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.Abstract.UsedNamesDeclaredNames a => DeclaredNames (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.Abstract.ViewsExprLike a => ExprLike (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.Abstract.ViewsExprLike a => ExprLike (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.Concrete.GenericFoldDecl a => FoldDecl (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.Concrete.GenericTraverseDecl a => TraverseDecl (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.Concrete.GenericCPatternLike p => CPatternLike (List1 p)Defined in Agda-2.7.0.1 · Agda.Syntax.Concrete.PatternNamesIn a => NamesIn (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.Internal.NamesSetBindingSite a => SetBindingSite (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.Scope.BaseToAbstract c => ToAbstract (List1 c)Defined in Agda-2.7.0.1 · Agda.Syntax.Translation.ConcreteToAbstractBlankVars a => BlankVars (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.Translation.InternalToAbstractBinder a => Binder (List1 a)Defined in Agda-2.7.0.1 · Agda.Syntax.Translation.InternalToAbstractToAbstract (List1 (QNamed Clause))Defined in Agda-2.7.0.1 · Agda.Syntax.Translation.ReflectedToAbstractEmbPrj a => EmbPrj (List1 a)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Serialise.Instances.Common · orphanAddContext (List1 Name, Dom Type)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Monad.ContextAddContext (List1 (Arg Name), Type)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Monad.ContextAddContext (List1 (NamedArg Name), Type)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Monad.ContextAddContext (List1 (WithHiding Name), Dom Type)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Monad.Contexttype Rep (NonEmpty a) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"NonEmpty"
"GHC.Internal.Base"
"ghc-internal"
'False) (C1 ('MetaCons":|"
('InfixI 'RightAssociative5
) 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a])))type Rep1 NonEmpty = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"NonEmpty"
"GHC.Internal.Base"
"ghc-internal"
'False) (C1 ('MetaCons":|"
('InfixI 'RightAssociative5
) 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1 :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 [])))type Item (NonEmpty a) = aDefined in ghc-internal-9.1003.0 · GHC.Internal.IsListtype ConOfAbs (List1 a) = List1 (ConOfAbs a)Defined in Agda-2.7.0.1 · Agda.Syntax.Translation.AbstractToConcretetype AbsOfCon (List1 c) = List1 (AbsOfCon c)Defined in Agda-2.7.0.1 · Agda.Syntax.Translation.ConcreteToAbstracttype AbsOfRef (List1 (QNamed Clause)) = List1 ClauseDefined in Agda-2.7.0.1 · Agda.Syntax.Translation.ReflectedToAbstract
The partition function takes a predicate p and a stream
xs, and returns a pair of lists. The first list corresponds to the
elements of xs for which p holds; the second corresponds to the
elements of xs for which p does not hold.
'partition' p xs = ('filter' p xs, 'filter' (not . p) xs)Construct a NonEmpty list from a single element.
Prepend an element to the stream.
Map a function over a NonEmpty stream.
insert x xs inserts x into the last position in xs where it
is still less than or equal to the next element. In particular, if the
list is sorted beforehand, the result will also be sorted.
Sort a stream.
Sort a NonEmpty on a user-supplied projection of its elements. See sortOn for more detailed information.
Examples
sortOn fst $ (2, "world") :| [(4, "!"), (1, "Hello")](1,"Hello") :| [(2,"world"),(4,"!")]
sortOn length $ "jim" :| ["creed", "pam", "michael", "dwight", "kevin"]"jim" :| ["pam","creed","kevin","dwight","michael"]
Performance notes
This function minimises the projections performed, by materialising the projections in an intermediate list.
For trivial projections, you should prefer using sortBy with comparing, for example:
sortBy (comparing fst) $ (3, 1) :| [(2, 2), (1, 3)](1,3) :| [(2,2),(3,1)]
Or, for the exact same API as sortOn, you can use `sortBy . comparing`:
(sortBy . comparing) fst $ (3, 1) :| [(2, 2), (1, 3)](1,3) :| [(2,2),(3,1)]
sortWith is an alias for `sortBy . comparing`.
Extract the first element of the stream.
Number of elements in NonEmpty list.
filter p xs removes any elements from xs that do not satisfy p.
drop n xs drops the first n elements off the front of
the sequence xs.
splitAt n xs returns a pair consisting of the prefix of xs
of length n and the remaining stream immediately following this prefix.
'splitAt' n xs == ('take' n xs, 'drop' n xs)
xs == ys ++ zs where (ys, zs) = 'splitAt' n xscycle xs returns the infinite repetition of xs:
cycle (1 :| [2,3]) = 1 :| [2,3,1,2,3,...]Extract everything except the last element of the stream.
iterate f x produces the infinite sequence
of repeated applications of f to x.
iterate f x = x :| [f x, f (f x), ..]Extract the last element of the stream.
repeat x returns a constant stream, where all elements are
equal to x.
reverse a finite NonEmpty stream.
span p xs returns the longest prefix of xs that satisfies
p, together with the remainder of the stream.
'span' p xs == ('takeWhile' p xs, 'dropWhile' p xs)
xs == ys ++ zs where (ys, zs) = 'span' p xsExtract the possibly-empty tail of the stream.
take n xs returns the first n elements of xs.
takeWhile p xs returns the longest prefix of the stream
xs for which the predicate p holds.
Synonym for <|.
The zip function takes two streams and returns a stream of corresponding pairs.
'intersperse x xs' alternates elements of the list with copies of x.
intersperse 0 (1 :| [2,3]) == 1 :| [0,2,0,3]The permutations function returns the list of all permutations of the argument.
uncons produces the first element of the stream, and a stream of the remaining elements, if any.
Compute n-ary logic exclusive OR operation on NonEmpty list.
Attach a list at the end of a NonEmpty.
appendList (1 :| [2,3]) []1 :| [2,3]
appendList (1 :| [2,3]) [4,5]1 :| [2,3,4,5]
groupAllWith operates like groupWith, but sorts the list first so that each equivalence class has, at most, one list in the output
groupAllWith1 is to groupWith1 as groupAllWith is to groupWith
groupWith1 is to group1 as groupWith is to group
permutations1 operates like permutations, but uses the knowledge that its input is non-empty to produce output where every element is non-empty.
permutations1 = fmap fromList . permutations . toListAttach a list at the beginning of a NonEmpty.
prependList [] (1 :| [2,3])1 :| [2,3]
prependList [negate 1, 0] (1 :| [2, 3])-1 :| [0,1,2,3]
some1 x sequences x one or more times.
The IsList class and its methods are intended to be used in conjunction with the OverloadedLists extension.
Associated types
Methods
Instances32IsList, …
IsList ByteArrayDefined in base-4.20.2.0 · Data.Array.ByteIsList BuilderDefined in bytestring-0.12.2.0 · Data.ByteString.Builder.InternalIsList ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.TypeIsList ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Lazy.InternalIsList ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalIsList IntSetDefined in containers-0.7 · Data.IntSet.InternalIsList VersionDefined in ghc-internal-9.1003.0 · GHC.Internal.IsListIsList CallStackDefined in ghc-internal-9.1003.0 · GHC.Internal.IsListIsList TextDefined in text-2.1.3 · Data.Text · orphanPerforms replacement on invalid scalar values:
Example2 expressions :set -XOverloadedLists['\55555'] :: Text"\65533"
IsList TextDefined in text-2.1.3 · Data.Text.Lazy · orphanPerforms replacement on invalid scalar values:
Example2 expressions :set -XOverloadedLists['\55555'] :: Data.Text.Lazy.Text"\65533"
IsList ShortTextDefined in text-short-0.1.6 · Data.Text.Short.InternalNote: Surrogate pairs (
[U+D800 .. U+DFFF]) character literals are replaced by U+FFFD.Storable a => IsList (Vector a)Defined in vector-0.13.2.0 · Data.Vector.StorableIsList (List2 a)Defined in Agda-2.7.0.1 · Agda.Utils.List2fromList is unsafe.
IsList (KeyMap v)Defined in aeson-2.2.3.0 · Data.Aeson.KeyMapIsList (IntMap a)Defined in containers-0.7 · Data.IntMap.InternalIsList (Seq a)Defined in containers-0.7 · Data.Sequence.InternalIsList (DNonEmpty a)Defined in dlist-1.0 · Data.DList.DNonEmpty.InternalIsList (DList a)Defined in dlist-1.0 · Data.DList.InternalIsList (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.IsListIsList (ZipList a)Defined in ghc-internal-9.1003.0 · GHC.Internal.IsListIsList (Array a)Defined in primitive-0.9.1.0 · Data.Primitive.ArrayIsList (SmallArray a)Defined in primitive-0.9.1.0 · Data.Primitive.SmallArrayIsList (Vector a)Defined in vector-0.13.2.0 · Data.VectorIsList (Vector a)Defined in vector-0.13.2.0 · Data.Vector.StrictIsList [a]Defined in ghc-internal-9.1003.0 · GHC.Internal.IsListOrd a => IsList (Set a)Defined in containers-0.7 · Data.Set.InternalHashable a => IsList (HashSet a)Defined in unordered-containers-0.2.21 · Data.HashSet.InternalPrim a => IsList (PrimArray a)Defined in primitive-0.9.1.0 · Data.Primitive.PrimArrayPrim a => IsList (Vector a)Defined in vector-0.13.2.0 · Data.Vector.PrimitiveUnbox e => IsList (Vector e)Defined in vector-0.13.2.0 · Data.Vector.Unboxed · orphanOrd k => IsList (Map k v)Defined in containers-0.7 · Data.Map.InternalHashable k => IsList (HashMap k v)Defined in unordered-containers-0.2.21 · Data.HashMap.Internal
The Item type function returns the type of items of the structure
l.
Instances32Item, …
type Item ByteArray = Word8Defined in base-4.20.2.0 · Data.Array.Bytetype Item Builder = Word8Defined in bytestring-0.12.2.0 · Data.ByteString.Builder.Internaltype Item ByteString = Word8Defined in bytestring-0.12.2.0 · Data.ByteString.Internal.Typetype Item ByteString = Word8Defined in bytestring-0.12.2.0 · Data.ByteString.Lazy.Internaltype Item ShortByteString = Word8Defined in bytestring-0.12.2.0 · Data.ByteString.Short.Internaltype Item IntSet = KeyDefined in containers-0.7 · Data.IntSet.Internaltype Item Version = IntDefined in ghc-internal-9.1003.0 · GHC.Internal.IsListtype Item CallStack = (String, SrcLoc)Defined in ghc-internal-9.1003.0 · GHC.Internal.IsListtype Item Text = CharDefined in text-2.1.3 · Data.Text · orphantype Item Text = CharDefined in text-2.1.3 · Data.Text.Lazy · orphantype Item ShortText = CharDefined in text-short-0.1.6 · Data.Text.Short.Internaltype Item (List2 a) = aDefined in Agda-2.7.0.1 · Agda.Utils.List2type Item (KeyMap v) = (Key, v)Defined in aeson-2.2.3.0 · Data.Aeson.KeyMaptype Item (IntMap a) = (Key, a)Defined in containers-0.7 · Data.IntMap.Internaltype Item (Map k v) = (k, v)Defined in containers-0.7 · Data.Map.Internaltype Item (Seq a) = aDefined in containers-0.7 · Data.Sequence.Internaltype Item (Set a) = aDefined in containers-0.7 · Data.Set.Internaltype Item (DNonEmpty a) = aDefined in dlist-1.0 · Data.DList.DNonEmpty.Internaltype Item (DList a) = aDefined in dlist-1.0 · Data.DList.Internaltype Item (NonEmpty a) = aDefined in ghc-internal-9.1003.0 · GHC.Internal.IsListtype Item (ZipList a) = aDefined in ghc-internal-9.1003.0 · GHC.Internal.IsListtype Item (Array a) = aDefined in primitive-0.9.1.0 · Data.Primitive.Arraytype Item (PrimArray a) = aDefined in primitive-0.9.1.0 · Data.Primitive.PrimArraytype Item (SmallArray a) = aDefined in primitive-0.9.1.0 · Data.Primitive.SmallArraytype Item (HashMap k v) = (k, v)Defined in unordered-containers-0.2.21 · Data.HashMap.Internaltype Item (HashSet a) = aDefined in unordered-containers-0.2.21 · Data.HashSet.Internaltype Item (Vector a) = aDefined in vector-0.13.2.0 · Data.Vectortype Item (Vector a) = aDefined in vector-0.13.2.0 · Data.Vector.Primitivetype Item (Vector a) = aDefined in vector-0.13.2.0 · Data.Vector.Storabletype Item (Vector a) = aDefined in vector-0.13.2.0 · Data.Vector.Stricttype Item (Vector e) = eDefined in vector-0.13.2.0 · Data.Vector.Unboxed · orphantype Item [a] = aDefined in ghc-internal-9.1003.0 · GHC.Internal.IsList
Generalization of Data.List.unzip.
Examples
unzip (Just ("Hello", "World"))(Just "Hello",Just "World")
unzip [("I", "love"), ("really", "haskell")](["I","really"],["love","haskell"])