1. Gauthier Segay
  2. haskell-playground

Commits

bdabd13  committed 60624d2

naive implementation of a list delimit function

  • Participants
  • Parent commits 1e1000a
  • Branches default

Comments (0)

Files changed (1)

File Playground/List.hs

View file
 overflow2 :: [a] -> [(a,a)]
 overflow2 [] = []
 overflow2 (x:xs) = zip (x:xs) (xs++[x])
+
+-- ^ delimits a list into sub lists components based on start and end detection functors
+delimit :: (a -> Bool) -> (a -> Bool) -> [a] -> [[a]]
+delimit _ _ [] = []
+delimit _ _ (x:[]) = [[x]]
+delimit isStart isEnd (x:xs)
+  | isStart x = [[x]++ takeWhile isNotEnd xs ++ (take 1 $ dropUntilIsEnd xs)] ++ delimit isStart isEnd remaining
+  | otherwise = [[x]] ++ delimit isStart isEnd xs
+  where
+    isNotEnd = not . isEnd
+    dropUntilIsEnd = dropWhile isNotEnd
+    remaining = drop 1 $ dropUntilIsEnd xs