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)
22 | find1 f [] t = Nothing # t
25 | in if b then Just x # t else find1 f xs t
32 | any1 : (a -> F1 s Bool) -> List a -> F1 s Bool
33 | any1 f [] t = False # t
36 | in if b then True # t else any1 f xs t
43 | all1 : (a -> F1 s Bool) -> List a -> F1 s Bool
44 | all1 f [] t = True # t
47 | in if b then all1 f xs t else False # t
55 | span1 : (a -> F1 s Bool) -> List a -> F1 s (List a, List a)
58 | go : SnocList a -> List a -> F1 s (List a, List a)
59 | go sx [] t = (sx<>>[], []) # t
62 | in if b then go (sx:<x) xs t else (sx<>>[],x::xs) # t
67 | break1 : (a -> F1 s Bool) -> List a -> F1 s (List a, List a)
68 | break1 p = span1 $
\v,t => let b # t := p v t in not b # t
77 | partition1 : (a -> F1 s Bool) -> List a -> F1 s (List a, List a)
78 | partition1 f = go [<] [<]
80 | go : SnocList a -> SnocList a -> List a -> F1 s (List a, List a)
81 | go sx sy [] t = (sx <>> [], sy <>> []) # t
82 | go sx sy (x :: xs) t =
84 | in if b then go sx (sy:<x) xs t else go (sx:<x) sy xs t
88 | mapMaybe1 : (a -> F1 s (Maybe b)) -> List a -> F1 s (List b)
89 | mapMaybe1 f = go [<]
91 | go : SnocList b -> List a -> F1 s (List b)
92 | go sx [] t = (sx <>> []) # t
94 | let Just v # t := f x t | Nothing # t => go sx xs t
95 | in go (sx :< v) xs t
99 | replicate1 : Nat -> F1 s a -> F1 s (List a)
100 | replicate1 n f = go [<] n
102 | go : SnocList a -> Nat -> F1 s (List a)
103 | go sx 0 t = (sx <>> []) # t
104 | go sx (S k) t = let v # t2 := f t in go (sx :< v) k t2