我正在将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'。 –