I love that kind of bullshit poetry.
Or you can do,
return filter(None,tokens)
Not obvious, but giving None is like giving "lambda x : x" to filter().If not, I'm now curious why the `None` special case was added to `filter`..
Eg, arr.filter(Boolean)
pure (n, guard (factor /= n) $> factor)
Which I think is more or less the same as this python line. return [factor for factor in factors if factor and not factor == n]
The article does fancy stuff with memory caches which I believe is easy to do in python but I need to understand the Haskell code better.[0] Haskell: A Great Procedural Language https://entropicthoughts.com/haskell-procedural-programming#... https://news.ycombinator.com/item?id=42754098
Returns a tuple: Left side is n, right side is (Just factor) if factor is not n, or Nothing if it is.
A more direct translation:
# py
[token for token in tokens if token]
-- hs
filter (not . null) tokens
The full functions: # py
def analyze(text):
tokens = tokenize(text)
tokens = lowercase_filter(tokens)
tokens = stopword_filter(tokens)
tokens = stem_filter(tokens)
return [token for token in tokens if token]
-- hs
analyze :: String -> [String]
analyze = filter (not . null) . stem_filter . stopword_filter . lowercase_filter . tokenizeMost of the difficulty in search is dealing with the sheer volume of data. The algorithms themselves are pretty trivial for the most part.
https://gist.github.com/benob/69d48421f88f5dcc2b26a204d3251d...