Skip to content

Instantly share code, notes, and snippets.

@davidchambers
Created November 26, 2014 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidchambers/34fdbaf7e281b07ebf4b to your computer and use it in GitHub Desktop.
Save davidchambers/34fdbaf7e281b07ebf4b to your computer and use it in GitHub Desktop.
findX :: (MatchObj -> Maybe MatchObj) -> [String] -> Maybe MatchObj
findX matcher words = head xs
where
xs = do len <- length words .. 1
idx <- 0 .. length words - len
let m = matcher { before: take idx words
, group: (drop idx >>> take len) words
, after: drop (idx + len) words
, matches: defaultTransaction
, context: []
}
guard $ isJust m
return $ fromJust m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment