Commit b1cfd066 authored by Mart Lubbers's avatar Mart Lubbers

Merge branch '30-add-function-from-itasks-examples-to-data-list'

parents dd7a53de a74a1532
......@@ -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,29 @@ 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]
/**
* Left-associative fold of a list.
* Variant that use a queue instead of a fixed size list.
*
* @param Function that generates new elements, appended to the end of the list,
* for each list element and accumulator value
* @param Function that updates the accumulator value for each list element
* @param The initial accumulator value
* @param The initial list
* @result The final accumulator value
*/
qfoldl :: (a -> b -> [b]) (a -> b -> a) a ![b] -> a
/**
* Right-associative fold of a list.
* Variant that use a queue instead of a fixed size list.
*
* @param Function that generates new elements, appended to the end of the list,
* for each list element and accumulator value
* @param Function that updates the accumulator value for each list element
* @param The initial accumulator value
* @param The initial list
* @result The final accumulator value
*/
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