-
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
Changes from all commits
6bd8e51
1108d57
5435ce4
bfc64e1
9c574f5
2e54ab5
8d0751e
609ce1f
99fefef
6369cfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ Breaking changes: | |
- Update project and deps to PureScript v0.15.0 (#203 by @JordanMartinez) | ||
- Drop deprecated `MonadZero` instance (#205 by @JordanMartinez) | ||
- Drop deprecated `group'` and `mapWithIndex` (#206 by @JordanMartinez) | ||
- Change `groupAllBy` to use a comparison function (#191) | ||
|
||
New features: | ||
|
||
|
@@ -43,7 +44,7 @@ Breaking changes: | |
|
||
New features: | ||
- Added `nubEq`/`nubByEq` (#179) | ||
- Added `groupAllBy` (#182, #191) | ||
- Added `groupAllBy` (#182) | ||
Comment on lines
-46
to
+47
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. I prematurely added this PR to the changelog in #195. I was hoping this PR would have been included in the batch of breaking changes, so the release history would show In hindsight, it would have been better to add the |
||
- Added `Eq1` and `Ord1` instances to `NonEmptyList` and `LazyNonEmptyList` (#188) | ||
|
||
Bugfixes: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ module Test.Data.List (testList) where | |
import Prelude | ||
|
||
import Data.Array as Array | ||
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(..), Pattern(..), alterAt, catMaybes, concat, concatMap, delete, deleteAt, deleteBy, drop, dropEnd, dropWhile, elemIndex, elemLastIndex, filter, filterM, findIndex, findLastIndex, foldM, fromFoldable, group, groupAll, groupAllBy, groupBy, head, init, insert, insertAt, insertBy, intersect, intersectBy, last, length, mapMaybe, modifyAt, nub, nubBy, nubByEq, nubEq, null, partition, range, reverse, singleton, snoc, sort, sortBy, span, stripPrefix, tail, take, takeEnd, takeWhile, transpose, uncons, union, unionBy, unsnoc, unzip, updateAt, zip, zipWith, zipWithA, (!!), (..), (:), (\\)) | ||
|
@@ -23,7 +23,11 @@ import Test.Assert (assert) | |
|
||
testList :: Effect Unit | ||
testList = do | ||
let l = fromFoldable | ||
let | ||
l = fromFoldable | ||
|
||
nel :: forall f a. Foldable f => a -> f a -> NEL.NonEmptyList a | ||
nel x xs = NEL.NonEmptyList $ x :| fromFoldable xs | ||
|
||
log "strip prefix" | ||
assert $ stripPrefix (Pattern (1:Nil)) (1:2:Nil) == Just (2:Nil) | ||
|
@@ -272,8 +276,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]) | ||
|
Uh oh!
There was an error while loading. Please reload this page.