Hi all, I’m looking at the documentation for Enum.sort_by
and saw its mapper
parameter has this typespec: (element() -> mapped_element), ... when mapped_element: element()
.
My questions:
- I’ve never seen this syntax before; is there something I can read on this?
- What’s the purpose of
mapped_element
here? Since element
is just any
, can’t we just write (element() -> element())
?

There are several resources available:
- What’s the purpose of
mapped_element
here? Since element
is just any
, can’t we just write (element() -> element())
?
It seems like in earlier versions of the function the type spec was a bit different:
@spec sort_by(t, (element -> mapped_element), (mapped_element, mapped_element -> boolean)) :: list
when mapped_element: element
where mapped_element
specified (probably not intentionally) that the arguments in sorter
should be the same.
2 Likes