From 74e1c3d31a332f440feb92809adbee14b3344a4a Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 1 Mar 2020 09:48:27 +0000 Subject: [PATCH] Remove Util module --- src/Profold/LineNode.hs | 6 ++++-- src/Profold/Util.hs | 16 ---------------- 2 files changed, 4 insertions(+), 18 deletions(-) delete mode 100644 src/Profold/Util.hs diff --git a/src/Profold/LineNode.hs b/src/Profold/LineNode.hs index 7a25aea..b07dab5 100644 --- a/src/Profold/LineNode.hs +++ b/src/Profold/LineNode.hs @@ -9,8 +9,6 @@ module Profold.LineNode import qualified Data.Text as T import qualified Data.Vector as V -import Profold.Util - data LineNode = LineNode { lineText :: T.Text , lineChildren :: V.Vector LineNode @@ -32,6 +30,10 @@ flatten ln flattenChild :: Int -> LineNode -> V.Vector (Path, LineNode) 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 f [] ln = f ln modify f (i:is) ln = diff --git a/src/Profold/Util.hs b/src/Profold/Util.hs deleted file mode 100644 index 7f7a7f2..0000000 --- a/src/Profold/Util.hs +++ /dev/null @@ -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))