Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/harmboschloo/elm-dict-intersect
Provides intersections of multiple dictionaries
https://github.com/harmboschloo/elm-dict-intersect
dictionaries elm intersection
Last synced: about 1 month ago
JSON representation
Provides intersections of multiple dictionaries
- Host: GitHub
- URL: https://github.com/harmboschloo/elm-dict-intersect
- Owner: harmboschloo
- License: bsd-3-clause
- Created: 2019-03-02T09:58:50.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-02T10:01:33.000Z (almost 6 years ago)
- Last Synced: 2024-10-08T07:04:55.311Z (2 months ago)
- Topics: dictionaries, elm, intersection
- Language: Elm
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ccamel - harmboschloo/elm-dict-intersect - Provides intersections of multiple dictionaries (Elm)
README
# Dict.Intersect
Provides intersections of multiple dictionaries based on their key.
## Example
```elm
import Dict exposing (Dict)
import Dict.Intersecttype alias Car =
{ wheels : Int
}type alias Boat =
{ speed : Float
}type alias Amphibian =
{ car : Car
, boat : Boat
}cars : Dict Int Car
cars =
Dict.fromList [ ( 0, Car 4 ), ( 1, Car 4 ), ( 2, Car 6 ) ]boats : Dict Int Boat
boats =
Dict.fromList [ ( 2, Boat 20 ), ( 3, Boat 30 ) ]amphibians : List ( Int, Amphibian )
amphibians =
Dict.Intersect.foldr2
(\id car boat list -> ( id, Amphibian car boat ) :: list)
[]
cars
boats-- amphibians == [ ( 2, { boat = { speed = 20 }, car = { wheels = 6 } } ) ]
```## Note on performance
When folding over multiple dictionaries it is generally faster to have the smallest dictionary as the first argument and the one with the least amount of intersections next. See [these benchmarks](https://github.com/harmboschloo/elm-dict-intersect/blob/master/benchmarks/src/OrderPerformance.elm) for an example.