-
Notifications
You must be signed in to change notification settings - Fork 50
Revise groupAllBy to just use an Ordering function #191
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
thomashoneyman
merged 10 commits into
purescript:master
from
milesfrain:group-all-by-ordering
Mar 18, 2022
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6bd8e51
Revise groupAllBy to just use an Ordering function
milesfrain 1108d57
Don't use proposed infix notation yet
milesfrain 5435ce4
Back-out changes to docs and tests
milesfrain bfc64e1
Update changelog
milesfrain 9c574f5
Merge branch 'master' into group-all-by-ordering
milesfrain 2e54ab5
Fixup changelog
milesfrain 8d0751e
Review feedback - longform forall
milesfrain 609ce1f
Merge branch 'master' into group-all-by-ordering
milesfrain 99fefef
Update changelog
milesfrain 6369cfd
Merge branch 'master' into group-all-by-ordering
JordanMartinez 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,9 @@ module Test.Data.List (testList) where | |
|
||
import Prelude | ||
|
||
import Data.Foldable (foldMap, foldl) | ||
import Data.Foldable (class Foldable, foldMap, foldl) | ||
import Data.FoldableWithIndex (foldMapWithIndex, foldlWithIndex, foldrWithIndex) | ||
import Data.Function (on) | ||
import Data.List (List(..), (..), stripPrefix, Pattern(..), length, range, foldM, unzip, zip, zipWithA, zipWith, intersectBy, intersect, (\\), deleteBy, delete, unionBy, union, nubBy, nub, group, groupAll, groupBy, groupAllBy, partition, span, dropWhile, drop, dropEnd, takeWhile, take, takeEnd, sortBy, sort, catMaybes, mapMaybe, filterM, filter, concat, concatMap, reverse, alterAt, modifyAt, updateAt, deleteAt, insertAt, findLastIndex, findIndex, elemLastIndex, elemIndex, (!!), uncons, unsnoc, init, tail, last, head, insertBy, insert, snoc, null, singleton, fromFoldable, transpose, mapWithIndex, (:)) | ||
import Data.List.NonEmpty as NEL | ||
import Data.Maybe (Maybe(..), isNothing, fromJust) | ||
|
@@ -21,7 +22,11 @@ import Test.Assert (assert) | |
|
||
testList :: Effect Unit | ||
testList = do | ||
let l = fromFoldable | ||
let | ||
l = fromFoldable | ||
|
||
nel :: ∀ f a. Foldable f => a -> f a -> NEL.NonEmptyList a | ||
milesfrain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
nel x xs = NEL.NonEmptyList $ x :| fromFoldable xs | ||
|
||
log "strip prefix" | ||
assert $ stripPrefix (Pattern (1:Nil)) (1:2:Nil) == Just (2:Nil) | ||
|
@@ -273,8 +278,8 @@ testList = do | |
log "groupBy should group consecutive equal elements into lists based on an equivalence relation" | ||
assert $ groupBy (\x y -> odd x && odd y) (l [1, 1, 2, 2, 3, 3]) == l [NEL.NonEmptyList (1 :| l [1]), NEL.singleton 2, NEL.singleton 2, NEL.NonEmptyList (3 :| l [3])] | ||
|
||
log "groupAllBy should group equal elements into lists based on an equivalence relation" | ||
assert $ groupAllBy (\x y -> odd x && odd y) (l [1, 3, 2, 4, 3, 3]) == l [NEL.singleton 1, NEL.singleton 2, NEL.NonEmptyList (3 :| l [3, 3]), NEL.singleton 4] | ||
log "groupAllBy should sort then group equal elements into lists based on a comparison function" | ||
assert $ groupAllBy (compare `on` (_ `div` 10)) (l [32, 31, 21, 22, 11, 33]) == l [nel 11 [], nel 21 [22], nel 32 [31, 33]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A test case like this is necessary to demonstrate the degree of ordering preserved. |
||
|
||
log "partition should separate a list into a tuple of lists that do and do not satisfy a predicate" | ||
let partitioned = partition (_ > 2) (l [1, 5, 3, 2, 4]) | ||
|
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.