Helpful library updates

This commit is contained in:
2026-05-19 17:30:43 -05:00
parent 020fa769a9
commit e2a1744508
11 changed files with 1684 additions and 966 deletions

View File

@@ -37,9 +37,13 @@ length = y (self : matchList
0
(_ tail : succ (self tail)))
reverse = y (self : matchList
t
(head tail : append (self tail) (pair head t)))
reverse_ = y (self xs acc :
matchList
acc
(h r : self r (pair h acc))
xs)
reverse = xs : reverse_ xs t
snoc = y (self x : matchList
(pair x t)
@@ -80,3 +84,166 @@ nth_ = y (self n xs i :
xs)
nth = n xs : nth_ n xs 0
headMaybe = matchList nothing (h _ : just h)
lastMaybe = y (self : matchList
nothing
(hd tl : matchBool
(just hd)
(self tl)
(emptyList? tl)))
nthMaybe_ = y (self n xs i :
matchList
nothing
(h r :
matchBool
(just h)
(self n r (succ i))
(equal? i n))
xs)
nthMaybe = n xs : nthMaybe_ n xs 0
take_ = y (self n xs i :
matchList
t
(h r :
matchBool
t
(pair h (self n r (succ i)))
(equal? i n))
xs)
take = n xs : take_ n xs 0
drop_ = y (self n xs i :
matchBool
xs
(matchList
t
(_ r : self n r (succ i))
xs)
(equal? i n))
drop = n xs : drop_ n xs 0
splitAt = n xs : pair (take n xs) (drop n xs)
concatMap_ = y (self f xs :
matchList
t
(h r : append (f h) (self f r))
xs)
concatMap = f xs : concatMap_ f xs
find = y (self pred xs :
matchList
nothing
(h r : matchBool (just h) (self pred r) (pred h))
xs)
partition_ = y (self pred xs trues falses :
matchList
(pair (reverse trues) (reverse falses))
(h r :
matchBool
(self pred r (pair h trues) falses)
(self pred r trues (pair h falses))
(pred h))
xs)
partition = pred xs : partition_ pred xs t t
partition = pred xs : partition_ pred xs t t
strLength = length
strAppend = append
strEq? = equal?
strEmpty? = emptyList?
startsWith? = y (self prefix str :
matchList
true
(ph pr :
matchList
false
(sh sr :
matchBool
(self pr sr)
false
(equal? ph sh))
str)
prefix)
endsWith? = prefix str : startsWith? (reverse prefix) (reverse str)
contains? = y (self needle haystack :
matchBool
true
(matchList
false
(_ r : self needle r)
haystack)
(startsWith? needle haystack))
lines_ = y (self str :
matchList
(acc current : append acc [(reverse current)])
(h r :
acc current :
matchBool
(self r (append acc [(reverse current)]) t)
(self r acc (pair h current))
(equal? h 10))
str)
lines = str : lines_ str t t
unlines = y (self lines :
matchList
""
(h r : append h (append "\n" (self r)))
lines)
words_ = y (self str :
matchList
(acc current :
matchBool
acc
(append acc [(reverse current)])
(emptyList? current))
(h r :
acc current :
matchBool
(matchBool
(self r acc current)
(self r (append acc [(reverse current)]) t)
(emptyList? current))
(self r acc (pair h current))
(equal? h 32))
str)
words = str : words_ str t t
unwords = y (self words :
matchList
""
(h r :
matchBool
h
(append h (append " " (self r)))
(emptyList? r))
words)
zipWith = y (self f xs ys :
matchList
t
(xh xt :
matchList
t
(yh yt : pair (f xh yh) (self f xt yt))
ys)
xs)