1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 15:35:14 +03:00
semantic/src/Source.hs

23 lines
542 B
Haskell
Raw Normal View History

2015-12-24 06:38:02 +03:00
module Source where
import Range
2015-12-24 06:48:31 +03:00
import qualified Data.Vector as Vector
2015-12-24 06:48:31 +03:00
newtype Source a = Source (Vector.Vector a)
deriving (Eq, Show, Functor, Foldable)
makeSource :: [a] -> Source a
2015-12-24 06:48:31 +03:00
makeSource = Source . Vector.fromList
unSource :: Source a -> [a]
2015-12-24 06:48:31 +03:00
unSource (Source vector) = Vector.toList vector
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)
toString :: Source Char -> String
toString = unSource
at :: Source a -> Int -> a
at = (!!) . unSource