2015-12-24 06:38:02 +03:00
|
|
|
module Source where
|
|
|
|
|
2015-12-24 06:38:20 +03:00
|
|
|
import Range
|
2015-12-24 06:48:31 +03:00
|
|
|
import qualified Data.Vector as Vector
|
2015-12-24 06:38:20 +03:00
|
|
|
|
2015-12-24 06:48:31 +03:00
|
|
|
newtype Source a = Source (Vector.Vector a)
|
2015-12-24 06:38:20 +03:00
|
|
|
deriving (Eq, Show, Functor, Foldable)
|
|
|
|
|
|
|
|
makeSource :: [a] -> Source a
|
2015-12-24 06:48:31 +03:00
|
|
|
makeSource = Source . Vector.fromList
|
2015-12-24 06:38:20 +03:00
|
|
|
|
|
|
|
unSource :: Source a -> [a]
|
2015-12-24 06:48:31 +03:00
|
|
|
unSource (Source vector) = Vector.toList vector
|
2015-12-24 06:38:20 +03:00
|
|
|
|
|
|
|
subsource :: Range -> Source a -> Source a
|
2015-12-24 06:48:31 +03:00
|
|
|
subsource range (Source vector) = Source (Vector.slice (start range) (end range) vector)
|
2015-12-24 06:38:20 +03:00
|
|
|
|
|
|
|
toString :: Source Char -> String
|
|
|
|
toString = unSource
|
|
|
|
|
|
|
|
at :: Source a -> Int -> a
|
|
|
|
at = (!!) . unSource
|
2015-12-24 07:04:50 +03:00
|
|
|
|
|
|
|
null :: Source a -> Bool
|
|
|
|
null (Source vector) = Vector.null vector
|
2015-12-24 07:05:01 +03:00
|
|
|
|
|
|
|
uncons :: Source a -> Maybe (a, Source a)
|
|
|
|
uncons (Source vector) = if Vector.null vector then Nothing else Just (Vector.head vector, Source $ Vector.tail vector)
|