Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> In more concise languages that whole piece would look like a single line:

---

  env.lines = [line for line in env.lines if not line.startswith("+++")]
---

I don't think that's what its actually doing. I think its actually return all the lines after the first line that starts with "+++". Or maybe all those lines but the first.

(I don't think its a good example of clear FP code, either.)



Yeah, in Haskell I'd probably have done something like

    dropWhile (not . T.isPrefixOf "+++") >>> \case
        [] -> return ()
        (line:lines) -> do
            header env line
            modified env 0 lines

edited to add: code above assumes LambdaCase and OverloadedStrings extensions, and that you've imported Data.Text qualified as T


lambdacase is one of my favorite extensions :D


I really like ScopedTypeVariables


To this Haskeller it appears to be keeping state as well.


Certainly some information is moving behind the scenes, given the "header ... ; modified ..."




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: