~singpolyma/cheogram

ref: 044e5791acf6b63c8f33172e0cfad4fb449a2fbd cheogram/UniquePrefix.hs -rw-r--r-- 369 bytes
044e5791Christopher Vollick Update Dhall to Newer Version 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
module UniquePrefix where

import Data.List
import qualified Data.Set as S
import qualified Data.Text as T

uniquePrefix txts = helper [] $ map (S.fromList . tail . T.inits) txts

helper done (prefixes:otherPrefixes) =
	(foldl' S.difference prefixes (done ++ otherPrefixes)) : helper (prefixes:done) otherPrefixes
helper _ [] = []

--ALT: https://pastebin.com/hFKdZw2g