on master help sign in
Simplify server.knot: eta-reduce unique, inline pruneRef calls in collectAndPrune and removeForKey
commite4dda70f79635ba1f639e21777886f9ad95dd307 authoriko <mail@iko.soy> dateMon 27 Apr 2026, 21:04 (5 months ago) parent4cd62e4
1 file changed+5−5
server.knot+5−5
server.knot+5−5
@@ -460,7 +460,7 @@ clamp = \lo hi x -> max lo (min hi x)
460460abs = \x -> if x < 0 then 0 - x else x
461461
462462-- Dedup: keeps first occurrence (O(n^2)).
463−unique = \items -> fold (\acc x -> if elem acc x then acc else union acc [x]) [] items
463+unique = fold (\acc x -> if elem acc x then acc else union acc [x]) []
464464
465465-- Pair each element with its 0-based index.
466466withIndex = fold (\acc x -> union acc [{i: count acc, v: x}]) []
@@ -499,16 +499,16 @@ pct = \cur maxN -> if maxN > 0 then cur * 100 / maxN else 0
499499-- Read entries matching `pred` (transformed by `extract`) and prune them in one step.
500500collectAndPrune = \ref pred extract -> do
501501 items <- *ref
502− pruneRef ref (\x -> not (pred x))
502+ set *ref = removeWhere items pred
503503 yield (mapWhere items pred extract)
504504
505505-- Common ack/delete tail: pull matching messages, drop them and their forwards.
506506removeForKey = \pred -> do
507507 msgs <- *messages
508− let toRemove = filter msgs pred
508+ fwds <- *forwards
509509 set *messages = removeWhere msgs pred
510− pruneRef forwards (\f -> not (pred f))
511− yield toRemove
510+ set *forwards = removeWhere fwds pred
511+ yield (filter msgs pred)
512512
513513-- Cap pred-matching entries to maxN-1 (caller adds one more).
514514capPerKey = \items pred maxN getKey ->