@@ -313,8 +313,6 @@ route Api = AuthApi | ClientApi | FederationApi
313313-- for clarity per the file header.
314314
315315-- True when every element matches.
316−all : [a] -> (a -> Bool) -> Bool
317−all = \xs pred -> not (any (\x -> not pred x) xs)
318316findFirst : [a] -> (a -> Bool) -> Maybe a
319317findFirst = \xs pred -> headOf (filter pred xs)
320318-- Run `action` only when `cond` is True; otherwise no-op.
@@ -330,13 +328,15 @@ clamp = \lo hi x -> max lo (min hi x)
330328
331329-- First element of a list, or Nothing for an empty list.
332330headOf : [a] -> Maybe a
333−headOf = \items -> fold (\_ x -> Just {value: x}) (Nothing {}) (take 1 items)
331+headOf = \items -> case items of
332+ Cons x _ -> Just {value: x}
333+ [] -> Nothing {}
334334
335335-- Cap to maxN by dropping the smallest-key entries (LRU-style). Always sorts.
336336-- For session/challenge/rate caps, `getKey` is typically `expiresAt` or
337337-- `windowStart` so the oldest entries are evicted first.
338338capList : [a] -> Int -> (a -> b) -> [a]
339−capList = \items maxN getKey -> dropRelation (max 0 (count items - maxN)) (sortBy getKey items)
339+capList = \items maxN getKey -> drop (max 0 (count items - maxN)) (sortBy getKey items)
340340
341341-- Cap pred-matching entries to maxN-1 (caller adds one more). Splits the list
342342-- into "doesn't match" (untouched) and "matches" (capped + LRU-evicted) so a
@@ -348,20 +348,20 @@ capPerKey = \items pred maxN getKey -> union (filter (\x -> not pred x) items) (
348348-- Sequence an IO action over each item, in order. Recurses through the list
349349-- one element at a time; this is the closest equivalent of `mapM_` here.
350350forEach : [a] -> (a -> IO {} {}) -> IO {} {}
351−forEach = \items action -> case single (take 1 items) of
352− Nothing {} -> yield {}
353− Just {value: x} -> do
351+forEach = \items action -> case items of
352+ [] -> yield {}
353+ Cons x rest -> do
354354 action x
355− forEach (dropRelation 1 items) action
355+ forEach rest action
356356
357357-- Like forEach, but collects each action's result into a list.
358358mapEach : [a] -> (a -> IO {} b) -> IO {} [b]
359−mapEach = \items action -> case headOf items of
360− Nothing {} -> yield []
361− Just {value: x} -> do
359+mapEach = \items action -> case items of
360+ [] -> yield []
361+ Cons x rest -> do
362362 r <- action x
363− rest <- mapEach (dropRelation 1 items) action
364− yield (union [r] rest)
363+ rs <- mapEach rest action
364+ yield (union [r] rs)
365365
366366-- Hex tokens: one random hex char per recursive call. `n` is the desired
367367-- length in characters (so n=48 yields 24 random bytes of entropy).