Skip to content

Commit 9cd5a47

Browse files
author
José Valim
committed
Improve docs for Dict.Behaviour
1 parent be3ab7d commit 9cd5a47

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

lib/elixir/lib/dict/behaviour.ex

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule Dict.Behaviour do
33
This module makes it easier to create your own `Dict` compliant
44
module, by providing default implementations for some required functions.
55
6-
Usage:
6+
## Example
77
88
defmodule MyDict do
99
use Dict.Behaviour
@@ -13,17 +13,39 @@ defmodule Dict.Behaviour do
1313
# override default implementations if needed
1414
end
1515
16-
The client module must contain following functions: `size/1`, `fetch/2`,
17-
`put/3`, `update/4`, `delete/2` and `reduce/3`. All of them are part of
18-
the Dict behaviour, so no extra functions are actually required.
16+
The client module must contain following functions:
1917
20-
Based on these functions, `Dict.Behaviour` generates default implementations
21-
for other functions such as `drop`, `take`, etc. All of the functions are
22-
defined as overridable, so you can provide your own implementation if
23-
needed.
18+
* `delete/2`
19+
* `fetch/2`,
20+
* `put/3`
21+
* `reduce/3`
22+
* `size/1`
23+
* `update/4`
24+
25+
All of them are part of the Dict behaviour, so no extra functions are
26+
actually required.
2427
25-
If you implement `new/0` and `new/1` functions, you can also test your custom
26-
module via `Dict` doctests:
28+
Based on these functions, `Dict.Behaviour` generates default implementations
29+
for the following functions:
30+
31+
* `drop/2`
32+
* `equal?/2`
33+
* `fetch!/2`
34+
* `get/2`
35+
* `get/3`
36+
* `has_key?/2`
37+
* `keys/1`
38+
* `merge/2`
39+
* `merge/3`
40+
* `put_new/3`
41+
* `take/2`
42+
* `to_list/1`
43+
* `values/1`
44+
45+
All of the functions are defined as overridable, so you can provide your own
46+
implementation if needed.
47+
48+
Note you can also test your custom module via `Dict`'s doctests:
2749
2850
defmodule MyDict do
2951
def new(keywords // []) do

0 commit comments

Comments
 (0)