Move the function 'first' from Parser to MyPrelude
It is useful and generic.
This commit is contained in:
parent
60f59bb2b7
commit
24810e5970
@ -40,3 +40,8 @@ tailInit :: [a] -> [a]
|
|||||||
tailInit xs
|
tailInit xs
|
||||||
| length xs > 2 = tail . init $ xs
|
| length xs > 2 = tail . init $ xs
|
||||||
| otherwise = []
|
| otherwise = []
|
||||||
|
|
||||||
|
|
||||||
|
-- |Apply a function to the first element of a tuple.
|
||||||
|
first :: (a -> b) -> (a,c) -> (b,c)
|
||||||
|
first f (x,y) = (f x, y)
|
||||||
|
@ -14,6 +14,7 @@ module Parser.Core (Parser,
|
|||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Data.Char
|
import Data.Char
|
||||||
|
import MyPrelude
|
||||||
|
|
||||||
|
|
||||||
-- |The parser type. It allows us to create specific parsers,
|
-- |The parser type. It allows us to create specific parsers,
|
||||||
@ -49,10 +50,6 @@ inParser :: ((String -> Maybe (a1, String))
|
|||||||
inParser f p = MkParser . f . runParser $ p
|
inParser f p = MkParser . f . runParser $ p
|
||||||
|
|
||||||
|
|
||||||
first :: (a -> b) -> (a,c) -> (b,c)
|
|
||||||
first f (x,y) = (f x, y)
|
|
||||||
|
|
||||||
|
|
||||||
-- |Creates a Parser that parses a Char depending on a given condition.
|
-- |Creates a Parser that parses a Char depending on a given condition.
|
||||||
satisfy :: (Char -> Bool) -- ^ condition
|
satisfy :: (Char -> Bool) -- ^ condition
|
||||||
-> Parser Char -- ^ created Parser
|
-> Parser Char -- ^ created Parser
|
||||||
|
Loading…
Reference in New Issue
Block a user