Skip to content

Commit 82ad71b

Browse files
author
Oron Port
authored
Clarify "the new" in dependent function types
(also added missing `val`) I was skimming over at this documentation and it actually took me a while to notice what is new. So I added the comment to clarify. It is also possible to write `type EntryToKey = (e: Entry) => e.Key` and use it instead to clarify this is a dependent type
1 parent 3004af3 commit 82ad71b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

docs/docs/reference/dependent-function-types.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ title: "Dependent Function Types"
66
A dependent function type describes functions where the result type may depend
77
on the function's parameter values. Example:
88

9-
class Entry { type Key; key: Key }
9+
class Entry { type Key; val key: Key }
1010

1111
def extractKey(e: Entry): e.Key = e.key // a dependent method
1212
val extractor: (e: Entry) => e.Key = extractKey // a dependent function value
13-
13+
// ║ ⇓ ⇓ ⇓ ⇓ ⇓ ⇓ ⇓ ║
14+
// ║ Dependent ║
15+
// ║ Function Type ║
16+
// ╚═══════════════════╝
1417
Scala already has _dependent methods_, i.e. methods where the result
1518
type refers to some of the parameters of the method. Method
1619
`extractKey` is an example. Its result type, `e.key` refers its

0 commit comments

Comments
 (0)