我正在將zxcvbn password strength算法轉換爲Haskell。撰寫Haskell過濾器
我有檢查的所有字符爲ASCII兩個函數和蠻力攻擊是可能的:
filterAscii :: [String] -- ^terms to filter
-> [String] -- ^filtered terms
filterAscii = filter $ all (\ chr -> ord chr < 128)
和
filterShort :: [String] -- ^terms to filter
-> [String] -- ^filtered terms
filterShort terms = map fst $ filter long $ zip terms [1..]
where long (term, index) = (26^length term) > index
我由這些成一個單一的功能:
filtered :: [String] -- ^terms to filter
-> [String] -- ^filtered terms
filtered = filterAscii . filterShort
我現在需要用第三個過濾器來組合這些以檢查這些項是否爲空:
filter (not . null) terms
它發生,我認爲我創建一個過濾器鏈,它會更有意義,創建一個單一的函數,它的濾波功能列表,並構成他們在給定的順序。
如果我從我的閱讀中回憶,我相信這是一個應用函子的工作。我可以使用應用程序嗎?
我不知道如何處理filterShort
功能,我需要zip
每個項目與其基於one-based索引之前篩選。
爲什麼現在一切都需要成爲應用函子?好的舊'foldl(。)id'發生了什麼? –
如何使用它來解決我的問題,特別是帶索引部分的'zip'? – Ralph
這會鏈接'[String] - > [String]'函數,而不是'String-> Bool'。 BTW'ap'在這裏並不好,'xs ap ys'將每個'x'應用於每個'y'。 –