-
Notifications
You must be signed in to change notification settings - Fork 186
Add 'compose' for maps #672
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
02f3997
a7534a9
db55ad4
0c5c1e1
2bf99eb
4a86a91
612020b
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 |
---|---|---|
|
@@ -192,6 +192,9 @@ module Data.Map.Internal ( | |
-- ** Disjoint | ||
, disjoint | ||
|
||
-- ** Compose | ||
, compose | ||
|
||
-- ** General combining function | ||
, SimpleWhenMissing | ||
, SimpleWhenMatched | ||
|
@@ -2088,6 +2091,25 @@ disjoint (Bin _ k _ l r) t | |
where | ||
(lt,found,gt) = splitMember k t | ||
|
||
{-------------------------------------------------------------------- | ||
Compose | ||
--------------------------------------------------------------------} | ||
-- | /O(|ab|*log(|bc|))/. Relate the keys of one map to the values of | ||
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. This bound is a bit funny when |bc| ≤ 1. Is it worth fixing? Not sure. 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. Wouldn't that also apply to the existing |
||
-- the other, by using the values of the former as keys for lookups | ||
-- in the latter. | ||
-- | ||
-- > compose (fromList [('a', "A"), ('b', "B")]) (fromList [(1,'a'),(2,'b'),(3,'z')]) = fromList [(1,"A"),(2,"B")] | ||
-- | ||
-- @ | ||
-- ('compose' bc ab '!?') = (bc '!?') <=< (ab '!?') | ||
-- @ | ||
-- | ||
-- @since UNRELEASED | ||
compose :: Ord b => Map b c -> Map a b -> Map a c | ||
compose bc !ab | ||
| null bc = empty | ||
| otherwise = mapMaybe (bc !?) ab | ||
|
||
#if !MIN_VERSION_base (4,8,0) | ||
-- | The identity type. | ||
newtype Identity a = Identity { runIdentity :: a } | ||
|
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.
Same correction and comments apply here.