Move towards implementing terminal autocomplete

This commit is contained in:
2025-08-16 23:13:24 +01:00
parent f7759b1f31
commit 76b6cda19b
14 changed files with 351 additions and 261 deletions
+6 -6
View File
@@ -31,19 +31,19 @@ lookupTrie :: Ord a => [a] -> Trie a b -> Maybe b
lookupTrie (k : ks) t = _trieChildren t M.!? k >>= lookupTrie ks
lookupTrie [] t = _trieMVal t
--nextTrie :: Ord a => [a] -> Trie a b -> Maybe (b, Trie a b)
nextTrie :: [a] -> Trie a b -> Maybe (b, Trie a b)
nextTrie (k:ks) t = undefined
nextTrie [] t = Nothing
----nextTrie :: Ord a => [a] -> Trie a b -> Maybe (b, Trie a b)
--nextTrie :: [a] -> Trie a b -> Maybe (b, Trie a b)
--nextTrie (k:ks) t = undefined
--nextTrie [] t = Nothing
splitLookupTrie :: Ord a => [a] -> Trie a b -> (Trie a b,Maybe b,Trie a b)
splitLookupTrie (k:ks) t@(Trie x xs) = case m of
splitLookupTrie (k:ks) (Trie x xs) = case m of
Nothing -> (Trie x l,Nothing,Trie x r)
Just t' -> let (l',m',r') = splitLookupTrie ks t'
in (Trie x (M.insert k l' l),m', Trie x (M.insert k r' r))
where
(l,m,r) = M.splitLookup k xs
splitLookupTrie [] t@(Trie x xs) = (Trie Nothing mempty,x, Trie Nothing xs)
splitLookupTrie [] (Trie x xs) = (Trie Nothing mempty,x, Trie Nothing xs)
-- the above would be better if it removed empty trie strings; the left trie
-- will always be empty and the right trie might be empty.
-- I cannot think of a smart way to do this