Popping from a list in state while a condition is true
You can simplify the code by using span:


  span :: (a -&gt; Bool) -&gt; [a] -&gt; ([a], [a])
  
  span, applied to a predicate p and a list xs, returns a tuple where
  first element is longest prefix (possibly empty) of xs of elements
  that satisfy p and second element is the remainder of the list


popWhile :: (Char -&gt; Bool) -&gt; StateT String Maybe String
popWhile p = do
    s &lt;- get
    let (xs, ys) = span p s
    put ys
    return xs




Thanks to @bisserlis for the suggestion to use state

popWhile = state . span