haskell / haskell/containers

Add intersections, intersectionsWith

Open
#359 5 comments 0 reactions 0 assignees View on GitHub
feature-request IntMap Map
Dominant language
Haskell
Stars
355
Forks
194
Avg merge
3d 4h
Merged PRs (30d)
4

Description

`Data.Map` and `Data.IntMap` have the functions

```haskell
unions :: Ord k => [Map k a] -> Map k a
unionsWith :: Ord k => (a -> a -> a) -> [Map k a] -> Map k a

unions :: [IntMap a] -> IntMap a
unionsWith :: (a -> a -> a) -> [IntMap a] -> IntMap a
```

should there be corresponding functions for intersection?

```haskell
intersections :: Ord k => [Map k a] -> Map k a
intersectionsWith :: Ord k => (a -> a -> a) -> [Map k a] -> Map k a

intersections :: [IntMap a] -> IntMap a
intersectionsWith :: (a -> a -> a) -> [IntMap a] -> IntMap a
```

They could all be given `Foldable` constraints.

There are some similar functions, from [`data-interval`](https://hackage.haskell.org/package/data-interval-0.6.0/candidate/docs/Data-Interval.html#v:intersections)

```haskell
intersections :: (Ord r, Num r) => [Interval r] -> Interval r
```

and [`fixplate`](https://hackage.haskell.org/package/fixplate-0.1.6/docs/Data-Generics-Fixplate-Util-Hash-Table.html#v:intersectionsWith)

```haskell
intersectionsWith :: (Ord hash, Ord k) => (v -> v -> v) -> [HashTable hash k v] -> HashTable hash k v
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.