Skip to content

Commit

Permalink
add eitherReader
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin authored and supki committed Jul 30, 2024
1 parent 345b092 commit 3e588a6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

* Added `instance (Field e a, ...) => Field e (Maybe a)` for generic environment parsing. (https://github.com/supki/envparse/pull/16)

* Added `eitherReader`. (https://github.com/supki/envparse/pull/24)

0.5
===

Expand Down
1 change: 1 addition & 0 deletions src/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module Env
, var
, Var
, Reader
, eitherReader
, str
, char
, nonempty
Expand Down
7 changes: 7 additions & 0 deletions src/Env/Internal/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Env.Internal.Parser
, Var(..)
, defaultVar
, Reader
, eitherReader
, str
, char
, nonempty
Expand Down Expand Up @@ -125,6 +126,12 @@ liftVarF =
-- | An environment variable's value parser. Use @(<=<)@ and @(>=>)@ to combine these
type Reader e a = String -> Either e a

-- | Create a 'Reader' from a simple parser function
eitherReader :: Error.AsUnread e => (String -> Either String a) -> Reader e a
eitherReader f s = left (Error.unread . suffix) $ f s
where
suffix x = x <> ": " <> show s

-- | Parse a particular variable from the environment
--
-- @
Expand Down

0 comments on commit 3e588a6

Please sign in to comment.