@@ -3364,8 +3364,10 @@ defmodule Kernel do
3364
3364
end
3365
3365
3366
3366
@ doc """
3367
- Defines a module as a protocol and specifies the API that
3368
- should be defined by its implementations.
3367
+ Defines a protocol.
3368
+
3369
+ A protocol specifies an API that should be defined by its
3370
+ implementations.
3369
3371
3370
3372
## Examples
3371
3373
@@ -3407,7 +3409,7 @@ defmodule Kernel do
3407
3409
And we would have to define the implementation for all types.
3408
3410
The supported types available are:
3409
3411
3410
- * Record (see below)
3412
+ * Structs (see below)
3411
3413
* Tuple
3412
3414
* Atom
3413
3415
* List
@@ -3416,23 +3418,24 @@ defmodule Kernel do
3416
3418
* Float
3417
3419
* Function
3418
3420
* PID
3421
+ * Map
3419
3422
* Port
3420
3423
* Reference
3421
3424
* Any (see below)
3422
3425
3423
- ## Protocols + Records
3426
+ ## Protocols + Structs
3424
3427
3425
- The real benefit of protocols comes when mixed with records .
3428
+ The real benefit of protocols comes when mixed with structs .
3426
3429
For instance, Elixir ships with many data types implemented as
3427
- records , like `HashDict` and `HashSet`. We can implement the
3430
+ structs , like `HashDict` and `HashSet`. We can implement the
3428
3431
`Blank` protocol for those types as well:
3429
3432
3430
- defimpl Blank, for: HashDict do
3433
+ defimpl Blank, for: [ HashDict, HashSet] do
3431
3434
def blank?(dict), do: Dict.empty?(dict)
3432
3435
end
3433
3436
3434
- Since records are tuples, if a protocol is not found a given
3435
- type, it will fallback to `Tuple `.
3437
+ If a protocol is not found for a given type, it will fallback to
3438
+ `Any `.
3436
3439
3437
3440
## Fallback to any
3438
3441
@@ -3466,8 +3469,8 @@ defmodule Kernel do
3466
3469
3467
3470
## Types
3468
3471
3469
- As in records, defining a protocol automatically defines a type
3470
- named `t`, which can be used as:
3472
+ Defining a protocol automatically defines a type named `t`, which
3473
+ can be used as:
3471
3474
3472
3475
@spec present?(Blank.t) :: boolean
3473
3476
def present?(blank) do
0 commit comments