Commit 16c32f16 authored by Steffen Michels's avatar Steffen Michels

add function from iTasks examples to Data.List

parent c28cd6c8
Pipeline #8760 passed with stage
in 1 minute and 24 seconds
......@@ -135,6 +135,13 @@ intersectBy :: (a -> b -> .Bool) !.[a] !.[b] -> .[a]
union :: u:(.[a] -> v:(.[a] -> .[a])) | == a, [v <= u]
unionBy :: (a -> .(a -> .Bool)) !.[a] .[a] -> .[a]
/** hasDup @as = True:
@as has at least one element that occurs twice.
hasDup @as = False:
@as has no elements that occur twice.
*/
hasDup :: ![a] -> Bool | Eq a
isMemberGen :: !a !.[a] -> Bool | gEq{|*|} a
strictFoldr :: !(.a -> .(.b -> .b)) !.b ![.a] -> .b
......@@ -160,3 +167,8 @@ strictTRZip2Acc :: ![a] ![b] ![(!a, !b)] -> [(!a, !b)]
strictTRZipWith3 :: !(a b c -> d) ![a] ![b] ![c] -> [d]
strictTRZipWith3Rev :: !(a b c -> d) ![a] ![b] ![c] -> [d]
strictTRZipWith3Acc :: !(a b c -> d) ![a] ![b] ![c] ![d] -> [d]
// variants of the fold functions that use a queue instead of a fixed size list:
qfoldl :: (a -> b -> [b]) (a -> b -> a) a ![b] -> a
qfoldr :: (a -> b -> [b]) (b -> a -> a) a ![b] -> a
......@@ -389,6 +389,10 @@ union = unionBy (==)
unionBy :: (a -> .(a -> .Bool)) !.[a] .[a] -> .[a]
unionBy eq xs ys = xs ++ foldl (flip (deleteBy eq)) (nubBy eq ys) xs
hasDup :: ![a] -> Bool | Eq a
hasDup [] = False
hasDup [x:xs] = isMember x xs || hasDup xs
isMemberGen :: !a !.[a] -> Bool | gEq{|*|} a
isMemberGen x [hd:tl] = hd === x || isMemberGen x tl
isMemberGen x [] = False
......@@ -496,3 +500,16 @@ strictTRZipWith3Acc :: !(a b c -> d) ![a] ![b] ![c] ![d] -> [d]
strictTRZipWith3Acc f [a:as] [b:bs] [c:cs] acc
= strictTRZipWith3Acc f as bs cs [f a b c : acc]
strictTRZipWith3Acc _ _ _ _ acc = acc
qfoldl :: (a -> b -> [b]) (a -> b -> a) a ![b] -> a
qfoldl _ _ a []
= a
qfoldl f g a [b:bs]
= let a` = g a b in qfoldl f g a` (bs ++ f a` b)
qfoldr :: (a -> b -> [b]) (b -> a -> a) a ![b] -> a
qfoldr _ _ a []
= a
qfoldr f g a [b:bs]
= let a` = g b a in qfoldr f g a` (bs ++ f a` b)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment