-
Notifications
You must be signed in to change notification settings - Fork 50
Deduplicate testing code - with records #200
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
base: master
Are you sure you want to change the base?
Changes from all commits
49acc40
45dc68e
e3043d0
9a190dd
ef11865
0e0efe2
c6bcc03
dcf14e8
2c530d8
0bbca7c
4164c1f
75eb742
51356f2
f3d4305
f34b041
6bd54d1
8f94430
039f866
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ module Data.List | |
, someRec | ||
, many | ||
, manyRec | ||
-- , replicate -- questionable specialization | ||
|
||
, null | ||
, length | ||
|
@@ -95,6 +96,13 @@ module Data.List | |
, foldM | ||
|
||
, module Exports | ||
|
||
-- additions | ||
, appendFoldable | ||
|
||
, cons' | ||
, snoc' | ||
|
||
) where | ||
|
||
import Prelude | ||
|
@@ -109,7 +117,7 @@ import Data.Foldable (foldl, foldr, foldMap, fold, intercalate, elem, notElem, f | |
import Data.FunctorWithIndex (mapWithIndex) as FWI | ||
import Data.List.Internal (emptySet, insertAndLookupBy) | ||
import Data.List.Types (List(..), (:)) | ||
import Data.List.Types (NonEmptyList(..)) as NEL | ||
import Data.List.Types as NEL | ||
import Data.Maybe (Maybe(..)) | ||
import Data.Newtype (class Newtype) | ||
import Data.NonEmpty ((:|)) | ||
|
@@ -119,6 +127,18 @@ import Data.Tuple (Tuple(..)) | |
import Data.Unfoldable (class Unfoldable, unfoldr) | ||
import Prim.TypeError (class Warn, Text) | ||
|
||
|
||
---------- Additions | ||
|
||
appendFoldable :: forall t a. Foldable t => List a -> t a -> List a | ||
appendFoldable xs ys = xs <> fromFoldable ys | ||
|
||
cons' :: forall a. a -> NEL.NonEmptyList a -> List a | ||
cons' x xs = Cons x $ NEL.toList xs | ||
|
||
snoc' :: forall a. NEL.NonEmptyList a -> a -> List a | ||
snoc' xs x = snoc (NEL.toList xs) x | ||
|
||
-- | Convert a list into any unfoldable structure. | ||
-- | | ||
-- | Running time: `O(n)` | ||
|
@@ -180,6 +200,15 @@ manyRec p = tailRecM go Nil | |
aa <- (Loop <$> p) <|> pure (Done unit) | ||
pure $ bimap (_ : acc) (\_ -> reverse acc) aa | ||
|
||
-- Questionable whether this should be specialized | ||
-- -- | Create a list containing a value repeated n times | ||
-- replicate :: forall a. Int -> a -> List a | ||
-- replicate num x = go num Nil | ||
-- where | ||
-- go n xs | n < 1 = xs | ||
-- | otherwise = go (n - 1) (x : xs) | ||
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'm wondering whether this should be added. Does anyone use this? Would anyone use this? 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'm wondering the same. Current plan is to just provide a specialized |
||
|
||
|
||
-------------------------------------------------------------------------------- | ||
-- List size ------------------------------------------------------------------- | ||
-------------------------------------------------------------------------------- | ||
|
@@ -626,17 +655,16 @@ groupBy _ Nil = Nil | |
groupBy eq (x : xs) = case span (eq x) xs of | ||
{ init: ys, rest: zs } -> NEL.NonEmptyList (x :| ys) : groupBy eq zs | ||
|
||
-- | Group equal elements of a list into lists, using the specified | ||
-- | equivalence relation to determine equality. | ||
-- | | ||
-- | For example, | ||
-- | Sort, then group equal elements of a list into lists, using the provided comparison function. | ||
-- | | ||
-- | ```purescript | ||
-- | groupAllBy (\a b -> odd a && odd b) (1 : 3 : 2 : 4 : 3 : 3 : Nil) == | ||
-- | (NonEmptyList (NonEmpty 1 Nil)) : (NonEmptyList (NonEmpty 2 Nil)) : (NonEmptyList (NonEmpty 3 (3 : 3 : Nil))) : (NonEmptyList (NonEmpty 4 Nil)) : Nil | ||
-- | groupAllBy (compare `on` (_ `div` 10)) (32 : 31 : 21 : 22 : 11 : 33 : Nil) == | ||
-- | NonEmptyList (11 :| Nil) : NonEmptyList (21 :| 22 : Nil) : NonEmptyList (32 :| 31 : 33) : Nil | ||
-- | ``` | ||
groupAllBy :: forall a. Ord a => (a -> a -> Boolean) -> List a -> List (NEL.NonEmptyList a) | ||
groupAllBy p = groupBy p <<< sort | ||
-- | | ||
-- | Running time: `O(n log n)` | ||
groupAllBy :: forall a. (a -> a -> Ordering) -> List a -> List (NEL.NonEmptyList a) | ||
groupAllBy p = groupBy (\x y -> p x y == EQ) <<< sortBy p | ||
|
||
-- | Returns a lists of elements which do and do not satisfy a predicate. | ||
-- | | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to implement this PR without the above breaking changes? The changes could still be made in a separate PR that we could wait to merge until another breaking PS release is made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes have already been made and released; I think this is just a bad merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm planning on merging this after #191 goes though, so I incorporated changes from that PR here too.
But yes, this is a pretty sloppy PR. Just wanted to upload the WIP to share some context during yesterday's meetup.