~singpolyma/cheogram

ref: 8606b4149fb3c28967d118b79112280690ef4e70 cheogram/UniquePrefix.hs -rw-r--r-- 425 bytes
8606b414Stephen Paul Weber Guix for CI now 5 months 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