-
Notifications
You must be signed in to change notification settings - Fork 13
Remove emptyCell (#45) #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,66 @@ | ||
| {-# LANGUAGE DeriveFunctor #-} | ||
| {-# LANGUAGE DeriveFoldable #-} | ||
| module Text.Layout.Table.Spec.RowGroup where | ||
|
|
||
| import Text.Layout.Table.Spec.Util | ||
|
|
||
| import Data.List (transpose) | ||
| import Data.Functor (void) | ||
|
|
||
| -- | Groups rows together which should not be visually seperated from each other. | ||
| newtype RowGroup a | ||
| = RowGroup | ||
| { rows :: [Row a] | ||
| } | ||
| data RowGroup a | ||
| = SingletonRowGroup (Row a) | ||
| | MultiRowGroup [Row a] | ||
| | NullableRowGroup [Row (Maybe a)] | ||
|
|
||
| -- | Group the given rows together. | ||
| rowsG :: [Row a] -> RowGroup a | ||
| rowsG = RowGroup | ||
| rowsG = MultiRowGroup | ||
|
|
||
| -- | Make a group of a single row. | ||
| rowG :: Row a -> RowGroup a | ||
| rowG = RowGroup . (: []) | ||
| rowG = SingletonRowGroup | ||
|
|
||
| -- | Provide a 'RowGroup' where single cells may be missing. | ||
| nullableRowsG :: [Row (Maybe a)] -> RowGroup a | ||
| nullableRowsG = NullableRowGroup | ||
|
|
||
| -- | Extracts the shape of the 'RowGroup' from the first row. | ||
| rowGroupShape :: RowGroup a -> [()] | ||
| rowGroupShape rg = case rg of | ||
| SingletonRowGroup r -> void r | ||
| MultiRowGroup rs -> firstSubListShape rs | ||
| NullableRowGroup ors -> firstSubListShape ors | ||
| where | ||
| firstSubListShape l = case l of | ||
| r : _ -> void r | ||
| [] -> [] | ||
|
|
||
| data ColumnSegment a | ||
| = SingleValueSegment a | ||
| | ColumnSegment (Col a) | ||
| | NullableColumnSegment (Col (Maybe a)) | ||
| deriving (Functor, Foldable, Eq, Show) | ||
|
|
||
| newtype SegmentedColumn a = SegmentedColumn [ColumnSegment a] deriving (Functor, Foldable, Eq, Show) | ||
|
|
||
| -- | Break down several 'RowGroups', which conceptually form a column by | ||
| -- themselves, into a list of columns. | ||
| transposeRowGroups :: Col (RowGroup a) -> [SegmentedColumn a] | ||
| transposeRowGroups = fmap SegmentedColumn . transpose . map transposeRowGroup | ||
| where | ||
| transposeRowGroup :: RowGroup a -> [ColumnSegment a] | ||
| transposeRowGroup rg = case rg of | ||
| SingletonRowGroup row -> SingleValueSegment <$> row | ||
| MultiRowGroup rows -> ColumnSegment <$> transpose rows | ||
| NullableRowGroup rows -> NullableColumnSegment <$> transpose rows | ||
|
|
||
| -- | Map each column with the corresponding function and replace empty inputs | ||
| -- with the given value. | ||
| mapRowGroupColumns :: [(b, (a -> b))] -> RowGroup a -> [[b]] | ||
| mapRowGroupColumns mappers rg = case rg of | ||
| SingletonRowGroup row -> pure $ zipWith snd mappers row | ||
| MultiRowGroup rows -> mapGrid snd rows | ||
| NullableRowGroup orows -> mapGrid (uncurry maybe) orows | ||
| where | ||
| mapGrid applyMapper = map $ zipWith applyMapper mappers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.