Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also add src/Utils & src/System to move some helpers there, and changed (again) the way the reading, parsing and writing is composed
- Loading branch information
1 parent
818c554
commit 594e0d3
Showing
5 changed files
with
44 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module System | ||
( nthArg | ||
, argOr | ||
, putStderr | ||
) where | ||
|
||
import qualified Control.Applicative as Ap | ||
import qualified Data.Maybe as M | ||
import qualified System.Environment as Env | ||
import qualified System.IO as Sys | ||
import Utils (nth) | ||
|
||
nthArg :: Int -> IO (Maybe String) | ||
nthArg = Ap.liftA2 nth Env.getArgs . pure | ||
|
||
argOr :: Int -> String -> IO String | ||
argOr n def = M.fromMaybe def <$> nthArg n | ||
|
||
putStderr :: String -> IO () | ||
putStderr = Sys.hPutStrLn Sys.stderr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Utils | ||
(nth) where | ||
|
||
nth :: [a] -> Int -> Maybe a | ||
nth xs n | ||
| n >= length xs = Nothing | ||
| n < 0 = Nothing | ||
| otherwise = Just (xs !! n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters