~singpolyma/cheogram

ref: a42b06986fa64052a1688947021fb87e590e9cf1 cheogram/UniquePrefix.hs -rw-r--r-- 369 bytes
a42b0698Stephen Paul Weber oops, add files 1 year, 8 months 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