Safe Haskell | None |
---|---|
Language | Haskell2010 |
promoted list functions
Synopsis
- data p :+ q
- data p +: q
- data p ++ q
- data Singleton p
- data EmptyT (t :: Type -> Type) p
- data EmptyList (t :: Type)
- data EmptyList' t
- data Uncons
- data Unsnoc
- data Head p
- data Tail p
- data Init p
- data Last p
- data SortBy p q
- data SortOn p q
- data SortOnDesc p q
- data Unzip
- data Unzip3
- data ZipL l p q
- data ZipR r p q
- data Zip p q
- data ZipWith p q r
- data Partition p q
- data PartitionBy t p q
- data GroupBy p q
- data Filter p q
- data Break p q
- data Span p q
- data Intercalate p q
- data Len
- data Length p
- data Elem p q
- data Inits
- data Tails
- data Ones p
- data PadL n p q
- data PadR n p q
- data SplitAts ns p
- data SplitAt n p
- data ChunksOf n p
- data Rotate n p
- data Take n p
- data Drop n p
- data Remove p q
- data Keep p q
- data Reverse
- data ReverseL
- data Sum
- data Product
- data Min
- data Max
constructors
similar to cons
>>>
pz @(Fst Id :+ Snd Id) (99,[1,2,3,4])
PresentT [99,1,2,3,4]
>>>
pz @(Snd Id :+ Fst Id) ([],5)
PresentT [5]
>>>
pz @(123 :+ EmptyList _) "somestuff"
PresentT [123]
>>>
pl @(FlipT (:+) (Fst Id) (Snd Id)) ([1..5],99)
Present [99,1,2,3,4,5] ((:+) [99,1,2,3,4,5] | p=99 | q=[1,2,3,4,5]) PresentT [99,1,2,3,4,5]
>>>
pl @(Fst Id :+ Snd Id) (99,[1..5])
Present [99,1,2,3,4,5] ((:+) [99,1,2,3,4,5] | p=99 | q=[1,2,3,4,5]) PresentT [99,1,2,3,4,5]
>>>
pl @(4 :+ '[1,2,3]) ()
Present [4,1,2,3] ((:+) [4,1,2,3] | p=4 | q=[1,2,3]) PresentT [4,1,2,3]
>>>
pl @(Fst Id :+ Snd Id) (4,[1,2,3])
Present [4,1,2,3] ((:+) [4,1,2,3] | p=4 | q=[1,2,3]) PresentT [4,1,2,3]
>>>
pl @(FlipT (:+) '[1,2,3] 5) ()
Present [5,1,2,3] ((:+) [5,1,2,3] | p=5 | q=[1,2,3]) PresentT [5,1,2,3]
similar to snoc
>>>
pz @(Snd Id +: Fst Id) (99,[1,2,3,4])
PresentT [1,2,3,4,99]
>>>
pz @(Fst Id +: Snd Id) ([],5)
PresentT [5]
>>>
pz @(EmptyT [] Id +: 5) 5
PresentT [5]
>>>
pl @('[1,2,3] +: 4) ()
Present [1,2,3,4] ((+:) [1,2,3,4] | p=[1,2,3] | q=4) PresentT [1,2,3,4]
>>>
pl @(Snd Id +: Fst Id) (4,[1,2,3])
Present [1,2,3,4] ((+:) [1,2,3,4] | p=[1,2,3] | q=4) PresentT [1,2,3,4]
>>>
pl @("abc" +: Char1 "x") ()
Present "abcx" ((+:) "abcx" | p="abc" | q='x') PresentT "abcx"
>>>
pl @(Fst Id +: Snd Id) ("abc" :: T.Text,'x')
Present "abcx" ((+:) "abcx" | p="abc" | q='x') PresentT "abcx"
similar to (++)
>>>
pz @(Fst Id ++ Snd Id) ([9,10,11],[1,2,3,4])
PresentT [9,10,11,1,2,3,4]
>>>
pz @(Snd Id ++ Fst Id) ([],[5])
PresentT [5]
>>>
pz @(Char1 "xyz" :+ W "ab" ++ W "cdefg") ()
PresentT "xabcdefg"
>>>
pz @([1,2,3] ++ EmptyList _) "somestuff"
PresentT [1,2,3]
creates a singleton from a value
>>>
pz @(Singleton (Char1 "aBc")) ()
PresentT "a"
>>>
pz @(Singleton Id) False
PresentT [False]
>>>
pz @(Singleton (Snd Id)) (False,"hello")
PresentT ["hello"]
data EmptyT (t :: Type -> Type) p Source #
similar to empty
>>>
pz @(EmptyT Maybe Id) ()
PresentT Nothing
>>>
pz @(EmptyT [] Id) ()
PresentT []
>>>
pz @(EmptyT [] (Char1 "x")) (13,True)
PresentT ""
>>>
pz @(EmptyT (Either String) (Fst Id)) (13,True)
PresentT (Left "")
data EmptyList (t :: Type) Source #
creates an empty list for the given type
>>>
pz @(Id :+ EmptyList _) 99
PresentT [99]
data EmptyList' t Source #
Instances
P (EmptyList' t :: Type) x Source # | |
Defined in Predicate.Data.List type PP (EmptyList' t) x :: Type Source # eval :: MonadEval m => proxy (EmptyList' t) -> POpts -> x -> m (TT (PP (EmptyList' t) x)) Source # | |
type PP (EmptyList' t :: Type) x Source # | |
Defined in Predicate.Data.List |
destructors
similar to uncons
>>>
pz @Uncons [1,2,3,4]
PresentT (Just (1,[2,3,4]))
>>>
pz @Uncons []
PresentT Nothing
>>>
pz @Uncons (Seq.fromList "abc")
PresentT (Just ('a',fromList "bc"))
>>>
pz @Uncons ("xyz" :: T.Text)
PresentT (Just ('x',"yz"))
>>>
pl @Uncons ("asfd" :: T.Text)
Present Just ('a',"sfd") (Uncons Just ('a',"sfd") | "asfd") PresentT (Just ('a',"sfd"))
>>>
pl @Uncons ("" :: T.Text)
Present Nothing (Uncons Nothing | "") PresentT Nothing
>>>
pl @Uncons [1..5] -- with Typeable would need to specify the type of [1..5]
Present Just (1,[2,3,4,5]) (Uncons Just (1,[2,3,4,5]) | [1,2,3,4,5]) PresentT (Just (1,[2,3,4,5]))
similar to unsnoc
>>>
pz @Unsnoc [1,2,3,4]
PresentT (Just ([1,2,3],4))
>>>
pz @Unsnoc []
PresentT Nothing
>>>
pz @Unsnoc ("xyz" :: T.Text)
PresentT (Just ("xy",'z'))
>>>
pl @Unsnoc ("asfd" :: T.Text)
Present Just ("asf",'d') (Unsnoc Just ("asf",'d') | "asfd") PresentT (Just ("asf",'d'))
>>>
pl @Unsnoc ("" :: T.Text)
Present Nothing (Unsnoc Nothing | "") PresentT Nothing
>>>
pl @Unsnoc [1..5]
Present Just ([1,2,3,4],5) (Unsnoc Just ([1,2,3,4],5) | [1,2,3,4,5]) PresentT (Just ([1,2,3,4],5))
takes the head of a list-like container: similar to head
>>>
pz @(Head Id) "abcd"
PresentT 'a'
>>>
pz @(Head Id) []
FailT "Head(empty)"
>>>
pl @(Head Id) ([] :: [Int])
Error Head(empty) FailT "Head(empty)"
>>>
pl @(Head Id) ([] :: [Double])
Error Head(empty) FailT "Head(empty)"
>>>
pl @(Head (Fst Id) >> Le 6) ([]::[Int], True)
Error Head(empty) ((>>) lhs failed) FailT "Head(empty)"
>>>
pl @(Head Id) [1,2,3]
Present 1 (Head 1 | [1,2,3]) PresentT 1
takes the tail of a list-like container: similar to tail
>>>
pz @(Tail Id) "abcd"
PresentT "bcd"
>>>
pl @(Tail Id) [1..5]
Present [2,3,4,5] (Tail [2,3,4,5] | [1,2,3,4,5]) PresentT [2,3,4,5]
>>>
pl @(Tail Id) ([] :: [()])
Error Tail(empty) FailT "Tail(empty)"
takes the init of a list-like container: similar to init
>>>
pz @(Init Id) "abcd"
PresentT "abc"
>>>
pz @(Init Id) (T.pack "abcd")
PresentT "abc"
>>>
pz @(Init Id) []
FailT "Init(empty)"
>>>
pl @(Init Id) [1..5]
Present [1,2,3,4] (Init [1,2,3,4] | [1,2,3,4,5]) PresentT [1,2,3,4]
>>>
pl @(Init Id) ([] :: [()])
Error Init(empty) FailT "Init(empty)"
takes the last of a list-like container: similar to last
>>>
pz @(Last Id) "abcd"
PresentT 'd'
>>>
pz @(Last Id) []
FailT "Last(empty)"
>>>
pl @(Last Id) [1,2,3]
Present 3 (Last 3 | [1,2,3]) PresentT 3
sort
sort a list
>>>
pz @(SortOn (Fst Id) Id) [(10,"abc"), (3,"def"), (4,"gg"), (10,"xyz"), (1,"z")]
PresentT [(1,"z"),(3,"def"),(4,"gg"),(10,"abc"),(10,"xyz")]
>>>
pz @(SortBy (OrdP (Snd Id) (Fst Id)) Id) [(10,"ab"),(4,"x"),(20,"bbb")]
PresentT [(20,"bbb"),(10,"ab"),(4,"x")]
>>>
pz @(SortBy 'LT Id) [1,5,2,4,7,0]
PresentT [1,5,2,4,7,0]
>>>
pz @(SortBy 'GT Id) [1,5,2,4,7,0]
PresentT [0,7,4,2,5,1]
>>>
pz @(SortBy ((Fst (Fst Id) ==! Fst (Snd Id)) <> (Snd (Fst Id) ==! Snd (Snd Id))) Id) [(10,"ab"),(4,"x"),(20,"bbb"),(4,"a"),(4,"y")]
PresentT [(4,"a"),(4,"x"),(4,"y"),(10,"ab"),(20,"bbb")]
>>>
pz @(SortBy ((Fst (Fst Id) ==! Fst (Snd Id)) <> (Snd (Snd Id) ==! Snd (Fst Id))) Id) [(10,"ab"),(4,"x"),(20,"bbb"),(4,"a"),(4,"y")]
PresentT [(4,"y"),(4,"x"),(4,"a"),(10,"ab"),(20,"bbb")]
>>>
pl @(SortBy (Swap >> OrdA (Fst Id)) (Snd Id)) ((),[('z',1),('a',10),('m',22)])
Present [('z',1),('m',22),('a',10)] (SortBy [('z',1),('m',22),('a',10)]) PresentT [('z',1),('m',22),('a',10)]
>>>
pl @(SortBy (OrdA Reverse) Id) ["az","by","cx","aa"]
Present ["aa","cx","by","az"] (SortBy ["aa","cx","by","az"]) PresentT ["aa","cx","by","az"]
>>>
pl @(SortBy (If (Fst Id==5 && Snd Id==3) (Failt _ (PrintT "pivot=%d value=%d" Id)) 'GT) (Snd Id)) ((), [5,7,3,1,6,2,1,3])
Error pivot=5 value=3(2) (SortBy) FailT "pivot=5 value=3(2)"
>>>
pl @(SortBy (If (Fst Id==50 && Snd Id==3) (Failt _ (PrintT "pivot=%d value=%d" Id)) (OrdA Id)) (Snd Id)) ((), [5,7,3,1,6,2,1,3])
Present [1,1,2,3,3,5,6,7] (SortBy [1,1,2,3,3,5,6,7]) PresentT [1,1,2,3,3,5,6,7]
similar to sortOn
>>>
pl @(SortOn Id Id) [10,4,2,12,14]
Present [2,4,10,12,14] (SortBy [2,4,10,12,14]) PresentT [2,4,10,12,14]
>>>
pl @(SortOn (Negate Id) Id) [10,4,2,12,14]
Present [14,12,10,4,2] (SortBy [14,12,10,4,2]) PresentT [14,12,10,4,2]
>>>
pl @(SortOn (Fst Id) Id) (zip "cabdaz" [10,4,2,12,14,1])
Present [('a',4),('a',14),('b',2),('c',10),('d',12),('z',1)] (SortBy [('a',4),('a',14),('b',2),('c',10),('d',12),('z',1)]) PresentT [('a',4),('a',14),('b',2),('c',10),('d',12),('z',1)]
>>>
pl @(SortOn (FailS "asdf") Id) [10,4,2,12,14]
Error asdf(4) (SortBy) FailT "asdf(4)"
>>>
pl @(SortOn (Snd Id) (Snd Id)) ((),[('z',14),('a',10),('m',22),('a',1)])
Present [('a',1),('a',10),('z',14),('m',22)] (SortBy [('a',1),('a',10),('z',14),('m',22)]) PresentT [('a',1),('a',10),('z',14),('m',22)]
>>>
pl @(SortOn (Fst Id) (Snd Id)) ((),[('z',1),('a',10),('m',22)])
Present [('a',10),('m',22),('z',1)] (SortBy [('a',10),('m',22),('z',1)]) PresentT [('a',10),('m',22),('z',1)]
>>>
pl @(SortOn (Fst Id) Id) [('z',1),('a',10),('m',22),('a',9),('m',10)]
Present [('a',10),('a',9),('m',22),('m',10),('z',1)] (SortBy [('a',10),('a',9),('m',22),('m',10),('z',1)]) PresentT [('a',10),('a',9),('m',22),('m',10),('z',1)]
>>>
pl @(SortOn Id Id) [('z',1),('a',10),('m',22),('a',9),('m',10)]
Present [('a',9),('a',10),('m',10),('m',22),('z',1)] (SortBy [('a',9),('a',10),('m',10),('m',22),('z',1)]) PresentT [('a',9),('a',10),('m',10),('m',22),('z',1)]
data SortOnDesc p q Source #
SortOn
but descending order
>>>
pl @(SortOnDesc Id Id) [10,4,2,12,14]
Present [14,12,10,4,2] (SortBy [14,12,10,4,2]) PresentT [14,12,10,4,2]
>>>
pl @(SortOnDesc (Fst Id) (Snd Id)) ((),[('z',1),('a',10),('m',22)])
Present [('z',1),('m',22),('a',10)] (SortBy [('z',1),('m',22),('a',10)]) PresentT [('z',1),('m',22),('a',10)]
Instances
P (SortOnDescT p q) x => P (SortOnDesc p q :: Type) x Source # | |
Defined in Predicate.Data.List type PP (SortOnDesc p q) x :: Type Source # eval :: MonadEval m => proxy (SortOnDesc p q) -> POpts -> x -> m (TT (PP (SortOnDesc p q) x)) Source # | |
type PP (SortOnDesc p q :: Type) x Source # | |
Defined in Predicate.Data.List |
zip related
unzip
equivalent
>>>
pz @Unzip (zip [1..5] "abcd")
PresentT ([1,2,3,4],"abcd")
unzip3
equivalent
>>>
pz @Unzip3 (zip3 [1..5] "abcd" (cycle [True,False]))
PresentT ([1,2,3,4],"abcd",[True,False,True,False])
zip two lists optionally padding the left hand side
>>>
pl @(ZipL 99 '[1,2,3] "abc") ()
Present [(1,'a'),(2,'b'),(3,'c')] (ZipL [(1,'a'),(2,'b'),(3,'c')] | p=[1,2,3] | q="abc") PresentT [(1,'a'),(2,'b'),(3,'c')]
>>>
pl @(ZipL 99 '[1,2] "abc") ()
Present [(1,'a'),(2,'b'),(99,'c')] (ZipL [(1,'a'),(2,'b'),(99,'c')] | p=[1,2] | q="abc") PresentT [(1,'a'),(2,'b'),(99,'c')]
>>>
pl @(ZipL 99 '[1] "abc") ()
Present [(1,'a'),(99,'b'),(99,'c')] (ZipL [(1,'a'),(99,'b'),(99,'c')] | p=[1] | q="abc") PresentT [(1,'a'),(99,'b'),(99,'c')]
>>>
pl @(ZipL 99 '[1,2,3] "ab") ()
Error ZipL(3,2) rhs would be truncated (p=[1,2,3] | q="ab") FailT "ZipL(3,2) rhs would be truncated"
>>>
pl @(ZipL 99 Id "abcdefg") [1..4]
Present [(1,'a'),(2,'b'),(3,'c'),(4,'d'),(99,'e'),(99,'f'),(99,'g')] (ZipL [(1,'a'),(2,'b'),(3,'c'),(4,'d'),(99,'e'),(99,'f'),(99,'g')] | p=[1,2,3,4] | q="abcdefg") PresentT [(1,'a'),(2,'b'),(3,'c'),(4,'d'),(99,'e'),(99,'f'),(99,'g')]
>>>
pl @(ZipL (99 % 4) '[1 % 1 , 2 % 1 , 3 % 1] Id) "abcde"
Present [(1 % 1,'a'),(2 % 1,'b'),(3 % 1,'c'),(99 % 4,'d'),(99 % 4,'e')] (ZipL [(1 % 1,'a'),(2 % 1,'b'),(3 % 1,'c'),(99 % 4,'d'),(99 % 4,'e')] | p=[1 % 1,2 % 1,3 % 1] | q="abcde") PresentT [(1 % 1,'a'),(2 % 1,'b'),(3 % 1,'c'),(99 % 4,'d'),(99 % 4,'e')]
>>>
pl @(ZipL "X" (EmptyT _ Id) Id) ("abcd" :: String)
Present [("X",'a'),("X",'b'),("X",'c'),("X",'d')] (ZipL [("X",'a'),("X",'b'),("X",'c'),("X",'d')] | p=[] | q="abcd") PresentT [("X",'a'),("X",'b'),("X",'c'),("X",'d')]
zip two lists optionally padding the right hand side
>>>
pl @(ZipR (Char1 "Z") '[1,2,3] "abc") ()
Present [(1,'a'),(2,'b'),(3,'c')] (ZipR [(1,'a'),(2,'b'),(3,'c')] | p=[1,2,3] | q="abc") PresentT [(1,'a'),(2,'b'),(3,'c')]
>>>
pl @(ZipR (Char1 "Z") '[1,2,3] "ab") ()
Present [(1,'a'),(2,'b'),(3,'Z')] (ZipR [(1,'a'),(2,'b'),(3,'Z')] | p=[1,2,3] | q="ab") PresentT [(1,'a'),(2,'b'),(3,'Z')]
>>>
pl @(ZipR (Char1 "Z") '[1,2,3] "a") ()
Present [(1,'a'),(2,'Z'),(3,'Z')] (ZipR [(1,'a'),(2,'Z'),(3,'Z')] | p=[1,2,3] | q="a") PresentT [(1,'a'),(2,'Z'),(3,'Z')]
>>>
pl @(ZipR (Char1 "Z") '[1,2] "abc") ()
Error ZipR(2,3) rhs would be truncated (p=[1,2] | q="abc") FailT "ZipR(2,3) rhs would be truncated"
>>>
pl @(ZipR (Char1 "Y") (EmptyT _ Id) Id) "abcd"
Error ZipR(0,4) rhs would be truncated (p=[] | q="abcd") FailT "ZipR(0,4) rhs would be truncated"
zip two lists with the same length
>>>
pl @(Zip '[1,2,3] "abc") ()
Present [(1,'a'),(2,'b'),(3,'c')] (Zip [(1,'a'),(2,'b'),(3,'c')] | p=[1,2,3] | q="abc") PresentT [(1,'a'),(2,'b'),(3,'c')]
>>>
pl @(Zip '[1,2,3] "ab") ()
Error Zip(3,2) length mismatch (p=[1,2,3] | q="ab") FailT "Zip(3,2) length mismatch"
>>>
pl @(Zip '[1,2] "abc") ()
Error Zip(2,3) length mismatch (p=[1,2] | q="abc") FailT "Zip(2,3) length mismatch"
>>>
pl @(Zip "abc" Id) [1..7]
Error Zip(3,7) length mismatch (p="abc" | q=[1,2,3,4,5,6,7]) FailT "Zip(3,7) length mismatch"
like zipWith
>>>
pz @(ZipWith Id (1...5) (Char1 "a" ... Char1 "e")) ()
PresentT [(1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e')]
>>>
pz @(ZipWith (ShowP (Fst Id) <> ShowP (Snd Id)) (1...5) (Char1 "a" ... Char1 "e")) ()
PresentT ["1'a'","2'b'","3'c'","4'd'","5'e'"]
>>>
pz @(ZipWith (MkThese (Fst Id) (Snd Id)) (1...6) (Char1 "a" ... Char1 "f")) ()
PresentT [These 1 'a',These 2 'b',These 3 'c',These 4 'd',These 5 'e',These 6 'f']
>>>
pz @(ZipWith (MkThese (Fst Id) (Snd Id)) '[] (Char1 "a" ... Char1 "f")) ()
FailT "ZipWith(0,6) length mismatch"
>>>
pz @(ZipWith (MkThese (Fst Id) (Snd Id)) (1...3) (Char1 "a" ... Char1 "f")) ()
FailT "ZipWith(3,6) length mismatch"
higher order methods
similar to partition
>>>
pz @(Partition (Ge 3) Id) [10,4,1,7,3,1,3,5]
PresentT ([10,4,7,3,3,5],[1,1])
>>>
pz @(Partition (Prime Id) Id) [10,4,1,7,3,1,3,5]
PresentT ([7,3,3,5],[10,4,1,1])
>>>
pz @(Partition (Ge 300) Id) [10,4,1,7,3,1,3,5]
PresentT ([],[10,4,1,7,3,1,3,5])
>>>
pz @(Partition (Id < 300) Id) [10,4,1,7,3,1,3,5]
PresentT ([10,4,1,7,3,1,3,5],[])
>>>
pl @(Partition (Lt 2) Id >> Id) [1,2,3,4,5]
Present ([1],[2,3,4,5]) ((>>) ([1],[2,3,4,5]) | {Id ([1],[2,3,4,5])}) PresentT ([1],[2,3,4,5])
>>>
pl @(Partition (Gt 3) Id) [1..10]
Present ([4,5,6,7,8,9,10],[1,2,3]) (Partition ([4,5,6,7,8,9,10],[1,2,3]) | s=[1,2,3,4,5,6,7,8,9,10]) PresentT ([4,5,6,7,8,9,10],[1,2,3])
>>>
pl @(Partition Even Id) [1..6]
Present ([2,4,6],[1,3,5]) (Partition ([2,4,6],[1,3,5]) | s=[1,2,3,4,5,6]) PresentT ([2,4,6],[1,3,5])
>>>
pl @(Partition Even Id >> Null *** (Len > 4) >> Fst Id == Snd Id) [1..6]
True ((>>) True | {False == False}) TrueT
>>>
pl @(Partition (ExitWhen "ExitWhen" (Gt 10) >> Gt 2) Id) [1..11]
Error ExitWhen (Partition(i=10, a=11) excnt=1) FailT "ExitWhen"
>>>
pl @(Partition (Prime Id) Id) [1..15]
Present ([2,3,5,7,11,13],[1,4,6,8,9,10,12,14,15]) (Partition ([2,3,5,7,11,13],[1,4,6,8,9,10,12,14,15]) | s=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]) PresentT ([2,3,5,7,11,13],[1,4,6,8,9,10,12,14,15])
data PartitionBy t p q Source #
partition values based on a function
>>>
pz @(PartitionBy Ordering (Case 'EQ '[Id < 0, Id > 0] '[ 'LT, 'GT] Id) Id) [-4,-2,5,6,7,0,-1,2,-3,4,0]
PresentT (fromList [(LT,[-3,-1,-2,-4]),(EQ,[0,0]),(GT,[4,2,7,6,5])])
>>>
pl @(PartitionBy Ordering (Case (Failt _ "asdf") '[Id < 2, Id == 2, Id > 2] '[ 'LT, 'EQ, 'GT] Id) Id) [-4,2,5,6,7,1,2,3,4]
Present fromList [(LT,[1,-4]),(EQ,[2,2]),(GT,[4,3,7,6,5])] (PartitionBy fromList [(LT,[1,-4]),(EQ,[2,2]),(GT,[4,3,7,6,5])] | s=[-4,2,5,6,7,1,2,3,4]) PresentT (fromList [(LT,[1,-4]),(EQ,[2,2]),(GT,[4,3,7,6,5])])
>>>
pl @(PartitionBy Ordering (Case (Failt _ "xyzxyzxyzzyyysyfsyfydf") '[Id < 2, Id == 2, Id > 3] '[ 'LT, 'EQ, 'GT] Id) Id) [-4,2,5,6,7,1,2,3,4]
Error xyzxyzxyzzyyysyfsyfydf (PartitionBy(i=7, a=3) excnt=1) FailT "xyzxyzxyzzyyysyfsyfydf"
Instances
(P p x, Ord t, Show x, Show t, PP q a ~ [x], PP p x ~ t, P q a) => P (PartitionBy t p q :: Type) a Source # | |
Defined in Predicate.Data.List type PP (PartitionBy t p q) a :: Type Source # eval :: MonadEval m => proxy (PartitionBy t p q) -> POpts -> a -> m (TT (PP (PartitionBy t p q) a)) Source # | |
type PP (PartitionBy t p q :: Type) a Source # | |
Defined in Predicate.Data.List |
similar to groupBy
>>>
pz @(GroupBy (Fst Id == Snd Id) Id) [1,3,4,5,1,5,5]
PresentT [[1],[3],[4],[5],[1],[5,5]]
>>>
pz @(GroupBy (Fst Id == Snd Id) Id) [1,1,1,3,4,5,1,5,5]
PresentT [[1,1,1],[3],[4],[5],[1],[5,5]]
>>>
pz @(GroupBy (Fst Id == Snd Id) Id) [5,5]
PresentT [[5,5]]
>>>
pz @(GroupBy (Fst Id == Snd Id) Id) [1,2]
PresentT [[1],[2]]
>>>
pz @(GroupBy (Fst Id == Snd Id) Id) [1]
PresentT [[1]]
>>>
pz @(GroupBy (Fst Id == Snd Id) Id) []
PresentT []
>>>
pz @(GroupBy (Fst Id < Snd Id) Id) [1,2,3,4,4,1,2]
PresentT [[1,2,3,4],[4],[1,2]]
>>>
pz @(GroupBy (Fst Id /= Snd Id) Id) [1,2,3,4,4,4,1]
PresentT [[1,2,3,4],[4],[4,1]]
>>>
pan @(GroupBy (Fst Id == Snd Id) Id) "hello goodbye"
P GroupBy ["h","e","ll","o"," ","g","oo","d","b","y","e"] | +- P Id "hello goodbye" | +- False i=0: 'h' == 'e' | +- False i=1: 'e' == 'l' | +- True i=2: 'l' == 'l' | +- False i=3: 'l' == 'o' | +- False i=4: 'o' == ' ' | +- True i=5: ' ' == ' ' | +- True i=6: ' ' == ' ' | +- True i=7: ' ' == ' ' | +- False i=8: ' ' == 'g' | +- False i=9: 'g' == 'o' | +- True i=10: 'o' == 'o' | +- False i=11: 'o' == 'd' | +- False i=12: 'd' == 'b' | +- False i=13: 'b' == 'y' | `- False i=14: 'y' == 'e' PresentT ["h","e","ll","o"," ","g","oo","d","b","y","e"]
similar to break
>>>
pz @(Break (Ge 3) Id) [10,4,1,7,3,1,3,5]
PresentT ([],[10,4,1,7,3,1,3,5])
>>>
pz @(Break (Lt 3) Id) [10,4,1,7,3,1,3,5]
PresentT ([10,4],[1,7,3,1,3,5])
>>>
pl @(Break (Gt 2) Id) [1..11]
Present ([1,2],[3,4,5,6,7,8,9,10,11]) (Break cnt=(2,9)) PresentT ([1,2],[3,4,5,6,7,8,9,10,11])
>>>
pl @(Break (If (Gt 2) 'True (If (Gt 4) (Failt _ "ASfd") 'False)) Id) [1..8]
Present ([1,2],[3,4,5,6,7,8]) (Break cnt=(2,6)) PresentT ([1,2],[3,4,5,6,7,8])
>>>
pl @(Break (Case 'False '[Gt 2,Gt 4] '[ W 'True, Failt _ "ASfd"] Id) Id) [1..8] -- case version
Present ([1,2],[3,4,5,6,7,8]) (Break cnt=(2,6)) PresentT ([1,2],[3,4,5,6,7,8])
>>>
pl @(Break (If (Gt 2) (Failt _ "ASfd") 'False) Id) [1..8]
Error ASfd (Break predicate failed) FailT "ASfd"
>>>
pl @(Break (Snd Id) Id) (zip [1..] [False,False,False,True,True,False])
Present ([(1,False),(2,False),(3,False)],[(4,True),(5,True),(6,False)]) (Break cnt=(3,3)) PresentT ([(1,False),(2,False),(3,False)],[(4,True),(5,True),(6,False)])
>>>
pl @(Break (Snd Id) Id) (zip [1..] [False,False,False,False])
Present ([(1,False),(2,False),(3,False),(4,False)],[]) (Break cnt=(4,0)) PresentT ([(1,False),(2,False),(3,False),(4,False)],[])
>>>
pl @(Break (Snd Id) Id) (zip [1..] [True,True,True,True])
Present ([],[(1,True),(2,True),(3,True),(4,True)]) (Break cnt=(0,4)) PresentT ([],[(1,True),(2,True),(3,True),(4,True)])
similar to span
>>>
pl @(Span (Lt 4) Id) [1..11]
Present ([1,2,3],[4,5,6,7,8,9,10,11]) (Break cnt=(3,8)) PresentT ([1,2,3],[4,5,6,7,8,9,10,11])
data Intercalate p q Source #
intercalate two lists
>>>
pz @(Intercalate '["aB"] '["xxxx","yz","z","www","xyz"]) ()
PresentT ["xxxx","aB","yz","aB","z","aB","www","aB","xyz"]
>>>
pz @(Intercalate '[W 99,Negate 98] Id) [1..5]
PresentT [1,99,-98,2,99,-98,3,99,-98,4,99,-98,5]
>>>
pz @(Intercalate '[99,100] Id) [1..5]
PresentT [1,99,100,2,99,100,3,99,100,4,99,100,5]
>>>
pl @(Intercalate (Fst Id) (Snd Id)) ([0,1], [12,13,14,15,16])
Present [12,0,1,13,0,1,14,0,1,15,0,1,16] (Intercalate [12,0,1,13,0,1,14,0,1,15,0,1,16] | [0,1] | [12,13,14,15,16]) PresentT [12,0,1,13,0,1,14,0,1,15,0,1,16]
>>>
pl @((Pure [] (Negate Len) &&& Id) >> Intercalate (Fst Id) (Snd Id)) [12,13,14,15,16]
Present [12,-5,13,-5,14,-5,15,-5,16] ((>>) [12,-5,13,-5,14,-5,15,-5,16] | {Intercalate [12,-5,13,-5,14,-5,15,-5,16] | [-5] | [12,13,14,15,16]}) PresentT [12,-5,13,-5,14,-5,15,-5,16]
Instances
(PP p x ~ [a], PP q x ~ PP p x, P p x, P q x, Show a) => P (Intercalate p q :: Type) x Source # | |
Defined in Predicate.Data.List type PP (Intercalate p q) x :: Type Source # eval :: MonadEval m => proxy (Intercalate p q) -> POpts -> x -> m (TT (PP (Intercalate p q) x)) Source # | |
type PP (Intercalate p q :: Type) x Source # | |
Defined in Predicate.Data.List |
miscellaneous
similar to length
for Foldable
instances
>>>
pz @(Length Id) (Left "aa")
PresentT 0
>>>
pz @(Length Id) (Right "aa")
PresentT 1
>>>
pz @(Length Right') (Right "abcd")
PresentT 4
>>>
pz @(Length (Thd (Snd Id))) (True,(23,'x',[10,9,1,3,4,2]))
PresentT 6
elem
function
>>>
pz @(Elem (Fst Id) (Snd Id)) ('x',"abcdxy")
TrueT
>>>
pz @(Elem (Fst Id) (Snd Id)) ('z',"abcdxy")
FalseT
>>>
pl @(Elem Id '[2,3,4]) 2
True (2 `elem` [2,3,4]) TrueT
>>>
pl @(Elem Id '[2,3,4]) 6
False (6 `elem` [2,3,4]) FalseT
>>>
pl @(Elem Id '[13 % 2]) 6.5
True (13 % 2 `elem` [13 % 2]) TrueT
>>>
pl @(Elem Id '[13 % 2, 12 % 1]) 6.5
True (13 % 2 `elem` [13 % 2,12 % 1]) TrueT
>>>
pl @(Elem Id '[13 % 2, 12 % 1]) 6
False (6 % 1 `elem` [13 % 2,12 % 1]) FalseT
similar to inits
>>>
pz @Inits [4,8,3,9]
PresentT [[],[4],[4,8],[4,8,3],[4,8,3,9]]
>>>
pz @Inits []
PresentT [[]]
similar to tails
>>>
pz @Tails [4,8,3,9]
PresentT [[4,8,3,9],[8,3,9],[3,9],[9],[]]
>>>
pz @Tails []
PresentT [[]]
>>>
pl @Tails "abcd"
Present ["abcd","bcd","cd","d",""] (Tails ["abcd","bcd","cd","d",""] | "abcd") PresentT ["abcd","bcd","cd","d",""]
split a list into single values
>>>
pz @(Ones Id) [4,8,3,9]
PresentT [[4],[8],[3],[9]]
>>>
pz @(Ones Id) []
PresentT []
left pad 'q' with 'n' values from 'p'
>>>
pl @(PadL 5 0 Id) [1..3]
Present [0,0,1,2,3] (PadL 5 pad=0 [0,0,1,2,3] | [1,2,3]) PresentT [0,0,1,2,3]
>>>
pz @(PadL 5 999 Id) [12,13]
PresentT [999,999,999,12,13]
>>>
pz @(PadR 5 (Fst Id) '[12,13]) (999,'x')
PresentT [12,13,999,999,999]
>>>
pz @(PadR 2 (Fst Id) '[12,13,14]) (999,'x')
PresentT [12,13,14]
>>>
pl @(PadL 10 0 Id) [1..3]
Present [0,0,0,0,0,0,0,1,2,3] (PadL 10 pad=0 [0,0,0,0,0,0,0,1,2,3] | [1,2,3]) PresentT [0,0,0,0,0,0,0,1,2,3]
right pad 'q' with 'n' values from 'p'
>>>
pl @(PadR 5 8 Id) [1..3]
Present [1,2,3,8,8] (PadR 5 pad=8 [1,2,3,8,8] | [1,2,3]) PresentT [1,2,3,8,8]
>>>
pl @(PadR 5 0 Id) [1..5]
Present [1,2,3,4,5] (PadR 5 pad=0 [1,2,3,4,5] | [1,2,3,4,5]) PresentT [1,2,3,4,5]
>>>
pl @(PadR 5 0 Id) [1..6]
Present [1,2,3,4,5,6] (PadR 5 pad=0 [1,2,3,4,5,6] | [1,2,3,4,5,6]) PresentT [1,2,3,4,5,6]
split a list 'p' into parts using the lengths in the type level list 'ns'
>>>
pz @(SplitAts '[2,3,1,1] Id) "hello world"
PresentT ["he","llo"," ","w","orld"]
>>>
pz @(SplitAts '[2] Id) "hello world"
PresentT ["he","llo world"]
>>>
pz @(SplitAts '[10,1,1,5] Id) "hello world"
PresentT ["hello worl","d","",""]
>>>
pl @(SplitAts '[1,3,4] Id) [1..12]
Present [[1],[2,3,4],[5,6,7,8],[9,10,11,12]] (SplitAts [[1],[2,3,4],[5,6,7,8],[9,10,11,12]] | ns=[1,3,4] | [1,2,3,4,5,6,7,8,9,10,11,12]) PresentT [[1],[2,3,4],[5,6,7,8],[9,10,11,12]]
>>>
pl @(SplitAts '[3,1,1,1] Id >> Filter (Not Null) Id) [1..4]
Present [[1,2,3],[4]] ((>>) [[1,2,3],[4]] | {Fst [[1,2,3],[4]] | ([[1,2,3],[4]],[[],[]])}) PresentT [[1,2,3],[4]]
similar to splitAt
>>>
pz @(SplitAt 4 Id) "hello world"
PresentT ("hell","o world")
>>>
pz @(SplitAt 20 Id) "hello world"
PresentT ("hello world","")
>>>
pz @(SplitAt 0 Id) "hello world"
PresentT ("","hello world")
>>>
pz @(SplitAt (Snd Id) (Fst Id)) ("hello world",4)
PresentT ("hell","o world")
>>>
pz @(SplitAt (Negate 2) Id) "hello world"
PresentT ("hello wor","ld")
>>>
pl @(Snd Id >> SplitAt 2 Id >> Len *** Len >> Fst Id > Snd Id) ('x',[1..5])
False ((>>) False | {2 > 3}) FalseT
splits a list pointed to by 'p' into lists of size 'n'
>>>
pz @(ChunksOf 2 Id) "abcdef"
PresentT ["ab","cd","ef"]
>>>
pz @(ChunksOf 2 Id) "abcdefg"
PresentT ["ab","cd","ef","g"]
>>>
pz @(ChunksOf 2 Id) ""
PresentT []
>>>
pz @(ChunksOf 2 Id) "a"
PresentT ["a"]
rotate a list 'p' 'n' units
>>>
pz @(Rotate 0 Id) [1,2,3,4]
PresentT [1,2,3,4]
>>>
pz @(Rotate (Negate 1) Id) [1,2,3,4]
PresentT [4,1,2,3]
>>>
pz @(Rotate 2 Id) [1,2,3,4]
PresentT [3,4,1,2]
>>>
pz @(Map (Rotate Id "abcd") Id) [-3..7]
PresentT ["bcda","cdab","dabc","abcd","bcda","cdab","dabc","abcd","bcda","cdab","dabc"]
filters a list 'q' removing those elements in 'p'
>>>
pz @(Remove '[5] '[1,5,5,2,5,2]) ()
PresentT [1,2,2]
>>>
pz @(Remove '[0,1,1,5] '[1,5,5,2,5,2]) ()
PresentT [2,2]
>>>
pz @(Remove '[99] '[1,5,5,2,5,2]) ()
PresentT [1,5,5,2,5,2]
>>>
pz @(Remove '[99,91] '[1,5,5,2,5,2]) ()
PresentT [1,5,5,2,5,2]
>>>
pz @(Remove Id '[1,5,5,2,5,2]) []
PresentT [1,5,5,2,5,2]
>>>
pz @(Remove '[] '[1,5,5,2,5,2]) 44 -- works if you make this a number!
PresentT [1,5,5,2,5,2]
filters a list 'q' keeping those elements in 'p'
>>>
pz @(Keep '[5] '[1,5,5,2,5,2]) ()
PresentT [5,5,5]
>>>
pz @(Keep '[0,1,1,5] '[1,5,5,2,5,2]) ()
PresentT [1,5,5,5]
similar to reverse
>>>
pz @Reverse [1,2,4]
PresentT [4,2,1]
>>>
pz @Reverse "AbcDeF"
PresentT "FeDcbA"
reverses using reversing
>>>
pz @ReverseL (T.pack "AbcDeF")
PresentT "FeDcbA"
>>>
pz @ReverseL ("AbcDeF" :: String)
PresentT "FeDcbA"
>>>
pl @ReverseL ("asfd" :: T.Text)
Present "dfsa" (ReverseL "dfsa" | "asfd") PresentT "dfsa"