0 | module Data.Linear.List
2 | import public Data.Linear.Token
9 | filter1 : (a -> F1 s Bool) -> List a -> F1 s (List a)
12 | go : SnocList a -> List a -> F1 s (List a)
13 | go sx [] t = (sx <>> []) # t
16 | in if b then go (sx :< x) xs t else go sx xs t
21 | find1 : (a -> F1 s Bool) -> List a -> F1 s (Maybe a)
24 | go : List a -> F1 s (Maybe a)
25 | go [] t = Nothing # t
28 | in if b then Just x # t else go xs t
36 | span1 : (a -> F1 s Bool) -> List a -> F1 s (List a, List a)
39 | go : SnocList a -> List a -> F1 s (List a, List a)
40 | go sx [] t = (sx<>>[], []) # t
43 | in if b then go (sx:<x) xs t else (sx<>>[],x::xs) # t
48 | break1 : (a -> F1 s Bool) -> List a -> F1 s (List a, List a)
49 | break1 p = span1 $
\v,t => let b # t := p v t in not b # t
58 | partition1 : (a -> F1 s Bool) -> List a -> F1 s (List a, List a)
59 | partition1 f = go [<] [<]
61 | go : SnocList a -> SnocList a -> List a -> F1 s (List a, List a)
62 | go sx sy [] t = (sx <>> [], sy <>> []) # t
63 | go sx sy (x :: xs) t =
65 | in if b then go sx (sy:<x) xs t else go (sx:<x) sy xs t
69 | mapMaybe1 : (a -> F1 s (Maybe b)) -> List a -> F1 s (List b)
70 | mapMaybe1 f = go [<]
72 | go : SnocList b -> List a -> F1 s (List b)
73 | go sx [] t = (sx <>> []) # t
75 | let Just v # t := f x t | Nothing # t => go sx xs t
76 | in go (sx :< v) xs t
80 | replicate1 : Nat -> F1 s a -> F1 s (List a)
81 | replicate1 n f = go [<] n
83 | go : SnocList a -> Nat -> F1 s (List a)
84 | go sx 0 t = (sx <>> []) # t
85 | go sx (S k) t = let v # t2 := f t in go (sx :< v) k t2