Remove Util module
This commit is contained in:
parent
c76a16bcbe
commit
74e1c3d31a
2 changed files with 4 additions and 18 deletions
|
|
@ -9,8 +9,6 @@ module Profold.LineNode
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
|
|
||||||
import Profold.Util
|
|
||||||
|
|
||||||
data LineNode = LineNode
|
data LineNode = LineNode
|
||||||
{ lineText :: T.Text
|
{ lineText :: T.Text
|
||||||
, lineChildren :: V.Vector LineNode
|
, lineChildren :: V.Vector LineNode
|
||||||
|
|
@ -32,6 +30,10 @@ flatten ln
|
||||||
flattenChild :: Int -> LineNode -> V.Vector (Path, LineNode)
|
flattenChild :: Int -> LineNode -> V.Vector (Path, LineNode)
|
||||||
flattenChild i c = V.map (\(is, n) -> (i : is, n)) $ flatten c
|
flattenChild i c = V.map (\(is, n) -> (i : is, n)) $ flatten c
|
||||||
|
|
||||||
|
modifyAtIndex :: Int -> (a -> a) -> V.Vector a -> V.Vector a
|
||||||
|
-- Yes, this function looks ugly, but it's short enough that I don't care.
|
||||||
|
modifyAtIndex i f v = maybe v (\a -> v V.// [(i, f a)]) (v V.!? i)
|
||||||
|
|
||||||
modify :: (LineNode -> LineNode) -> Path -> LineNode -> LineNode
|
modify :: (LineNode -> LineNode) -> Path -> LineNode -> LineNode
|
||||||
modify f [] ln = f ln
|
modify f [] ln = f ln
|
||||||
modify f (i:is) ln =
|
modify f (i:is) ln =
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
module Profold.Util
|
|
||||||
( modifyAtIndex
|
|
||||||
, findSurrounding
|
|
||||||
) where
|
|
||||||
|
|
||||||
import Data.Maybe
|
|
||||||
import qualified Data.Vector as V
|
|
||||||
|
|
||||||
modifyAtIndex :: Int -> (a -> a) -> V.Vector a -> V.Vector a
|
|
||||||
-- Yes, this function looks ugly, but it's short enough that I don't care.
|
|
||||||
modifyAtIndex i f v = maybe v (\a -> v V.// [(i, f a)]) (v V.!? i)
|
|
||||||
|
|
||||||
findSurrounding :: (a -> Bool) -> V.Vector a -> (Maybe a, Maybe a)
|
|
||||||
findSurrounding f v = fromMaybe (Nothing, Nothing) $ do
|
|
||||||
i <- V.findIndex f v
|
|
||||||
pure (v V.!? (i - 1), v V.!? (i + 1))
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue