consumer_base_lambda.tri (1616B)
1 -- Ordinary tricu library equivalents: workers remain runtime arguments. 2 !import "prelude" !Local 3 listMap worker xs = map worker xs 4 listAppend suffix xs = append xs suffix 5 listFold worker accumulator xs = foldl worker accumulator xs 6 listReverse xs = reverse xs 7 listFilter predicate xs = filter predicate xs 8 listPrefix_ self input prefix = 9 lazyList (_ : lazyList (_ : just t) (_ _ : nothing) prefix) 10 (head rest : lazyList (_ : just input) 11 (wanted more : lazyBool (_ : self rest more) (_ : nothing) 12 (equal? head wanted)) prefix) 13 input 14 listPrefix prefix input = y listPrefix_ input prefix 15 listPathName prefix target = lazyMaybe (_ : "missing") (suffix : suffix) (listPrefix prefix target) 16 workLambdaPath target = listPathName "/_arboricx/" target 17 mapReverse xs = map reverse xs 18 nonempty xs = not? (emptyList? xs) 19 wrap x = [x] 20 prepend acc x = pair x acc 21 workLambdaMap xs = listMap wrap xs 22 workLambdaFilter xs = listFilter nonempty xs 23 workLambda xs = workLambdaFilter (workLambdaMap xs) 24 main = foldl and? true [(equal? (listMap wrap [1 2 3]) [[1] [2] [3]]) 25 (equal? (listAppend [4 5] [1 2 3]) [1 2 3 4 5]) 26 (equal? (listFold prepend t [1 2 3]) [3 2 1]) 27 (equal? (listReverse [1 2 3]) [3 2 1]) 28 (equal? (mapReverse [[1 2] [3 4 5]]) [[2 1] [5 4 3]]) 29 (equal? (listFilter nonempty [[] [1] [2 3] []]) [[1] [2 3]]) 30 (equal? (listPrefix "/_arboricx/" "/_arboricx/health") (just "health")) 31 (equal? (listPrefix "/_arboricx/" "/_arboric/health") nothing) 32 (equal? (listPathName "/_arboricx/" "/_arboricx/health") "health") 33 (equal? (listPathName "/_arboricx/" "/other") "missing")] 34 main