Skip to content

Instantly share code, notes, and snippets.

@ibtaylor
Created February 10, 2011 03:18
Show Gist options
  • Save ibtaylor/819868 to your computer and use it in GitHub Desktop.
Save ibtaylor/819868 to your computer and use it in GitHub Desktop.
ngrams :: Int -> Text -> [Text]
ngrams !n =
foldr f [] . T.tails
where
f e a
| len == n = gram : a
| otherwise = a
where
!len = T.length gram
!gram = T.take n e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment