From 438cb5f04ce7b2ad9910ca6a0879beabd0480af1 Mon Sep 17 00:00:00 2001 From: joshvera Date: Fri, 4 Dec 2015 14:18:26 -0500 Subject: [PATCH] Promote through empty columns --- src/Split.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Split.hs b/src/Split.hs index f97fdec81..3a48985c0 100644 --- a/src/Split.hs +++ b/src/Split.hs @@ -74,7 +74,16 @@ rowFromMaybeRows a b = Row (Maybe.maybeToList a) (Maybe.maybeToList b) adjoinRows :: [Row] -> [Row] -> [Row] adjoinRows [] rows = rows adjoinRows rows [] = rows -adjoinRows accum (row : rows) = init accum ++ [ last accum <> row ] ++ rows +adjoinRows accum (row : rows) = reverse (adjoin2 (reverse accum) row) ++ rows + +adjoin2 :: [Row] -> Row -> [Row] +adjoin2 [] row = [row] +adjoin2 (Row [] [] : init) row = adjoin2 init row +adjoin2 (Row [] rights : Row lefts rights' : init) (Row xs ys) = + Row [] (rights <> ys) : Row (lefts <> xs) rights' : init +adjoin2 (Row lefts [] : Row lefts' rights : init) (Row xs ys) = + Row (lefts <> xs) [] : Row lefts' (rights <> ys) : init +adjoin2 (last:init) row = (last <> row) : init zipWithMaybe :: (Maybe a -> Maybe b -> c) -> [a] -> [b] -> [c] zipWithMaybe f la lb = take len $ zipWith f la' lb'