Skip to content

Commit 8f45a2e

Browse files
committed
📝 Add note about duplicates
1 parent 8aeeef7 commit 8f45a2e

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ jobs:
3333
- run: mix compile --warnings-as-errors
3434
- run: mix test --trace
3535
- run: mix coveralls.github
36+
if: matrix.combo.elixir == '1.19.5'
3637
env:
3738
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

lib/simple_enum.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ defmodule SimpleEnum do
2727
2828
* `:allow_duplicate_keys` - when `true`, allows duplicate keys
2929
in the enumerators list. Defaults to `false`.
30+
Note: when duplicates exist, `name/1` and `name/2` will return
31+
the value of the first match (standard Keyword list behavior).
32+
`name_keys/0` returns deduplicated keys.
3033
* `:allow_duplicate_values` - when `true`, allows duplicate values
3134
in the enumerators list. Defaults to `false`.
35+
Note: when duplicates exist, `name/1` will return the first
36+
matching key for a given value.
37+
`name_values/0` returns deduplicated values.
3238
3339
The following macros are generated:
3440
@@ -124,8 +130,8 @@ defmodule SimpleEnum do
124130
@name unquote(expanded_name)
125131
@enum_name unquote(enum_name)
126132
@fields unquote(fields)
127-
@keys unquote(keys)
128-
@values unquote(values)
133+
@keys unquote(Enum.uniq(keys))
134+
@values unquote(Enum.uniq(values))
129135
@fields_rev @fields
130136
|> Enum.map(fn {k, v} -> {v, k} end)
131137
|> Map.new()

0 commit comments

Comments
 (0)