~singpolyma/cheogram

cheogram/UniquePrefix.hs -rw-r--r-- 425 bytes
a445129aStephen Paul Weber Blacklist uncommon file extensions 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
module UniquePrefix where

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

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

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

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