-
Notifications
You must be signed in to change notification settings - Fork 26
Drop Semigroup/Monoid instances for Map; add SemigroupMap #38
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
JordanMartinez
merged 45 commits into
purescript:master
from
JordanMartinez:addUnbiasedMap
Jan 26, 2021
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
21b21a1
Copy Internal, Gen, and main Map module to new Unbiased folder
JordanMartinez e6820c1
Add 'Unbiased' to new modules
JordanMartinez 77e3802
Unbias the Map's Semigroup instance
JordanMartinez 12ca79d
Update instance name to match conventions
JordanMartinez c7dc864
Add Alt instance to unbiased Map
JordanMartinez ffdf000
Duplicate biased Map's test into Unbiased file
JordanMartinez c2ec2a2
Update unbiased test to use unbiased Map
JordanMartinez 9f1c384
Fix Alt instance
JordanMartinez 43adba9
Export the unbiased map internal module
JordanMartinez 868eb71
Convert unbiased Map to newtype
JordanMartinez 732af66
Fix Arbitrary instances
JordanMartinez 7e5b11a
Replace specialized A.all with generic all
JordanMartinez 7c2788a
Add Semigroup tests to both Maps
JordanMartinez c7ca250
Include unbiased map tests in repo's tests
JordanMartinez e5bfeb6
Remove all non-typeclass-instance code from Unbiased Map
JordanMartinez 01232e1
Add newtype instance to Unbiased Map
JordanMartinez ef7ef66
Remove unused import
JordanMartinez 1e66c06
Merge remote-tracking branch 'upstream/master' into addUnbiasedMap
JordanMartinez 7b59b05
Add Apply and Bind instances to Unbiased Map to match Map
JordanMartinez 5bb69aa
Remove Semigroup and Monoid instances for normal Map
JordanMartinez 95700f3
Add Alt instance to normal Map and derive it for Unbiased Map
JordanMartinez 79cd3e3
No longer derive unbiased Map's Monoid instance
JordanMartinez f485637
Remove normal Map's Semigroup instance test
JordanMartinez d70951e
Reimplement submap without depending on Monoid instance
JordanMartinez e3d7d07
Remove "\" character that I somehow inserted
JordanMartinez 618c922
Update unbiased Map's Semigroup instance name to match naming convent…
JordanMartinez 169152c
Move asList past type class instances
JordanMartinez e39ae7e
Move SemigroupMap (aka the unbiased Map) into Data.Map; update tests
JordanMartinez cca21c6
Merge remote-tracking branch 'upstream/master' into addUnbiasedMap
JordanMartinez 6a74675
Remove unused safe coerce as a dependency
JordanMartinez 87ebc7b
Add Plus instance to Map
JordanMartinez 8e86d2e
Remove role annotations for SemigroupMap; it will use Map's role anno…
JordanMartinez cee5474
Use long-form names for SemigroupMap's type parameters in docs
JordanMartinez 985a076
Fix typo in docs: Last 1 should be Last 2
JordanMartinez 793c52b
Remove module prefixes in SemigroupMap docs; types are in same module
JordanMartinez 5ef6eb7
Update Semigroup docs to use `k v` rather than `key value`
JordanMartinez c266d77
Derive Show instance for SemigroupMap
JordanMartinez 134ce5e
Move SemigroupMap from Internal module to Data.Map
JordanMartinez db87c5d
Update CI to 0.14.0-rc5
JordanMartinez 4be58ec
Fix imports due to relocating SemigroupMap
JordanMartinez b0bfa20
Fix NonEmptySet Foldable1 instance
JordanMartinez ec42bd5
Fix tests that use `nubBy`
JordanMartinez e277da4
Merge remote-tracking branch 'upstream/master' into addUnbiasedMap
JordanMartinez aa75462
Add this PR to the changelog
JordanMartinez 694fa0f
Update changelog: added Alt and Plus instances to Map
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,65 @@ | ||
module Data.Map | ||
( module Data.Map.Internal | ||
, keys | ||
, SemigroupMap(..) | ||
) where | ||
|
||
import Prelude | ||
|
||
import Control.Alt (class Alt) | ||
import Control.Plus (class Plus) | ||
import Data.Eq (class Eq1) | ||
import Data.Foldable (class Foldable) | ||
import Data.FoldableWithIndex (class FoldableWithIndex) | ||
import Data.FunctorWithIndex (class FunctorWithIndex) | ||
import Data.Map.Internal (Map, alter, catMaybes, checkValid, delete, empty, filter, filterKeys, filterWithKey, findMax, findMin, foldSubmap, fromFoldable, fromFoldableWith, fromFoldableWithIndex, insert, insertWith, isEmpty, isSubmap, lookup, lookupGE, lookupGT, lookupLE, lookupLT, member, pop, showTree, singleton, size, submap, toUnfoldable, toUnfoldableUnordered, union, unionWith, unions, intersection, intersectionWith, difference, update, values, mapMaybeWithKey, mapMaybe) | ||
import Data.Newtype (class Newtype) | ||
import Data.Ord (class Ord1) | ||
import Data.Traversable (class Traversable) | ||
import Data.TraversableWithIndex (class TraversableWithIndex) | ||
import Data.Set (Set, fromMap) | ||
|
||
-- | The set of keys of the given map. | ||
-- | See also `Data.Set.fromMap`. | ||
keys :: forall k v. Map k v -> Set k | ||
keys = fromMap <<< void | ||
|
||
-- | `SemigroupMap k v` provides a `Semigroup` instance for `Map k v` whose | ||
-- | definition depends on the `Semigroup` instance for the `v` type. | ||
-- | You should only use this type when you need `Data.Map` to have | ||
-- | a `Semigroup` instance. | ||
-- | | ||
-- | ```purescript | ||
-- | let | ||
-- | s :: forall key value. key -> value -> SemigroupMap key value | ||
-- | s k v = SemigroupMap (singleton k v) | ||
-- | | ||
-- | (s 1 "foo") <> (s 1 "bar") == (s 1 "foobar") | ||
-- | (s 1 (First 1)) <> (s 1 (First 2)) == (s 1 (First 1)) | ||
-- | (s 1 (Last 1)) <> (s 1 (Last 2)) == (s 1 (Last 2)) | ||
-- | ``` | ||
newtype SemigroupMap k v = SemigroupMap (Map k v) | ||
|
||
derive newtype instance eq1SemigroupMap :: Eq k => Eq1 (SemigroupMap k) | ||
derive newtype instance eqSemigroupMap :: (Eq k, Eq v) => Eq (SemigroupMap k v) | ||
derive newtype instance ord1SemigroupMap :: Ord k => Ord1 (SemigroupMap k) | ||
derive newtype instance ordSemigroupMap :: (Ord k, Ord v) => Ord (SemigroupMap k v) | ||
derive instance newtypeSemigroupMap :: Newtype (SemigroupMap k v) _ | ||
derive newtype instance showSemigroupMap :: (Show k, Show v) => Show (SemigroupMap k v) | ||
|
||
instance semigroupSemigroupMap :: (Ord k, Semigroup v) => Semigroup (SemigroupMap k v) where | ||
append (SemigroupMap l) (SemigroupMap r) = SemigroupMap (unionWith append l r) | ||
|
||
instance monoidSemigroupMap :: (Ord k, Semigroup v) => Monoid (SemigroupMap k v) where | ||
mempty = SemigroupMap empty | ||
|
||
derive newtype instance altSemigroupMap :: Ord k => Alt (SemigroupMap k) | ||
derive newtype instance plusSemigroupMap :: Ord k => Plus (SemigroupMap k) | ||
derive newtype instance functorSemigroupMap :: Functor (SemigroupMap k) | ||
derive newtype instance functorWithIndexSemigroupMap :: FunctorWithIndex k (SemigroupMap k) | ||
derive newtype instance applySemigroupMap :: Ord k => Apply (SemigroupMap k) | ||
derive newtype instance bindSemigroupMap :: Ord k => Bind (SemigroupMap k) | ||
derive newtype instance foldableSemigroupMap :: Foldable (SemigroupMap k) | ||
derive newtype instance foldableWithIndexSemigroupMap :: FoldableWithIndex k (SemigroupMap k) | ||
derive newtype instance traversableSemigroupMap :: Traversable (SemigroupMap k) | ||
derive newtype instance traversableWithIndexSemigroupMap :: TraversableWithIndex k (SemigroupMap k) |
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.