pureIsAp :: [ByteString] -> (Match,[ByteString])
pureIsAp (ln:lns) = if ln =~ (pack "instance Applicative")
                           then let (appLn, rst) = findAp lns in
                                  if (BS.null appLn)
                                  then ([], rst)
                                  else ([ln,appLn], rst)
                           else ([], lns)
  where
    findAp :: [ByteString] -> (ByteString, [ByteString])
    findAp [] = (BS.empty,[])
    findAp (l:rst) = if l =~ (pack "\\(<\\*>\\)\\s*=\\s*ap")
                     then (l,rst)
                     else findAp rst

--"<\\*>.*=.*(`| )ap(`| )"
pureIsAp :: [ByteString] -> (Match,[ByteString])
pureIsAp (ln:lns) = if ln =~ (pack "instance Applicative")
                           then let (appLn, rst) = findAp lns in
                                  if (BS.null appLn)
                                  then ([], rst)
                                  else ([ln,appLn], rst)
                           else ([], lns)
  where
    findAp :: [ByteString] -> (ByteString, [ByteString])
    findAp [] = (BS.empty,[])
    findAp (l:rst) = if l =~ (pack "\\(<\\*>\\)\\s*=\\s*ap")
                     then (l,rst)
                     else findAp rst

--"<\\*>.*=.*(`| )ap(`| )"
pureIsAp (ln:lns) = if ln =~ (pack "instance Applicative")
                           then let (appLn, rst) = findAp lns in
                                  if (BS.null appLn)
                                  then ([], rst)
                                  else ([ln,appLn], rst)
                           else ([], lns)
  where
    findAp :: [ByteString] -> (ByteString, [ByteString])
    findAp [] = (BS.empty,[])
    findAp (l:rst) = if l =~ (pack "\\(<\\*>\\)\\s*=\\s*ap")
                     then (l,rst)
                     else findAp rst

--"<\\*>.*=.*(`| )ap(`| )"