License | GPL-2 |
---|---|

Maintainer | yi-devel@googlegroups.com |

Stability | experimental |

Portability | portable |

Safe Haskell | None |

Language | Haskell2010 |

Little helper for completion interfaces.

Intended to be imported qualified:

import qualified Yi.CompletionTree as CT

## Synopsis

- newtype CompletionTree a = CompletionTree (Map a (CompletionTree a))
- fromList :: (Ord a, ListLike a i, Eq i) => [a] -> CompletionTree a
- toList :: (Ord a, ListLike a i) => CompletionTree a -> [a]
- complete :: (Eq i, Ord a, ListLike a i) => CompletionTree a -> (a, CompletionTree a)
- update :: (Ord a, ListLike a i, Eq i) => CompletionTree a -> a -> CompletionTree a
- pretty :: Show a => CompletionTree a -> String
- unCompletionTree :: Lens' (CompletionTree a) (Map a (CompletionTree a))

# CompletionTree type

newtype CompletionTree a Source #

A CompletionTree is a map of partial completions.

Example:

fromList ["put","putStr","putStrLn","print","abc"]

Gives the following tree:

/ "p" "abc" / "ut" "rint" / Str "" / Ln ""

(The empty strings are needed to denote the end of a word) (A CompletionTree is not limited to a binary tree)

CompletionTree (Map a (CompletionTree a)) |

#### Instances

# Lists

fromList :: (Ord a, ListLike a i, Eq i) => [a] -> CompletionTree a Source #

This function converts a list of completable elements to a CompletionTree It finds elements that share a common prefix and groups them.

fromList . toList = id

toList :: (Ord a, ListLike a i) => CompletionTree a -> [a] Source #

Converts a CompletionTree to a list of completions.

toList . fromList = sort . nub

Examples:

`>>>`

[]`toList mempty`

`>>>`

["a"]`toList (fromList ["a"])`

`>>>`

["a"]`toList (fromList ["a","a","a"])`

`>>>`

["x","y","z"]`toList (fromList ["z","x","y"])`

# Modification

complete :: (Eq i, Ord a, ListLike a i) => CompletionTree a -> (a, CompletionTree a) Source #

Complete as much as possible without guessing.

Examples:

`>>>`

("put", fromList ["","Str","StrLn"])`complete $ fromList ["put","putStrLn","putStr"]`

`>>>`

("", fromList ["put","putStr","putStrLn","abc"])`complete $ fromList ["put","putStr","putStrLn","abc"]`

update :: (Ord a, ListLike a i, Eq i) => CompletionTree a -> a -> CompletionTree a Source #

Update the CompletionTree with new information. An empty list means that there is no completion left. A [mempty] means that the end of a word is reached.

Examples:

`>>>`

fromList ["ut","utStr"]`update (fromList ["put","putStr"]) "p"`

`>>>`

fromList ["","Str"]`update (fromList ["put","putStr"]) "put"`

`>>>`

fromList ["tr"]`update (fromList ["put","putStr"]) "putS"`

`>>>`

fromList []`update (fromList ["put"]) "find"`

`>>>`

fromList [""]`update (fromList ["put"]) "put"`

# Debugging

pretty :: Show a => CompletionTree a -> String Source #

For debugging purposes.

Example:

`>>>`

["put"[""|"Str"[""|"Ln"]]]`putStrLn $ pretty $ fromList ["put", "putStr", "putStrLn"]`

## Lens

unCompletionTree :: Lens' (CompletionTree a) (Map a (CompletionTree a)) Source #