Skip to content

Commit 3847a8c

Browse files
committed
anatomy: further refactor implicit to contextual abstractions
1 parent 1fa5dec commit 3847a8c

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/pages/type-classes/anatomy.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,26 +141,25 @@ for the using clauses and fills them in for us:
141141
Person("Dave", "dave@example.com").toJson(using personWriter)
142142
```
143143

144-
**The *implicitly* Method**
144+
**The *summon* Method**
145145

146146
The Scala standard library provides
147-
a generic type class interface called `implicitly`.
147+
a generic type class interface called `summon`.
148148
Its definition is very simple:
149149

150150
```scala
151-
def implicitly[A](using value: A): A =
152-
value
151+
def summon[A](using value: A): A = value
153152
```
154153

155-
We can use `implicitly` to summon any value from implicit scope.
156-
We provide the type we want and `implicitly` does the rest:
154+
We can use `summon` to summon any value from the contextual abstractions scope.
155+
We provide the type we want and `summon` does the rest:
157156

158157
```scala mdoc
159-
implicitly[JsonWriter[String]]
158+
summon[JsonWriter[String]]
160159
```
161160

162161
Most type classes in Cats provide other means to summon instances.
163-
However, `implicitly` is a good fallback for debugging purposes.
164-
We can insert a call to `implicitly` within the general flow of our code
162+
However, `summon` is a good fallback for debugging purposes.
163+
We can insert a call to `summon` within the general flow of our code
165164
to ensure the compiler can find an instance of a type class
166165
and ensure that there are no ambiguous given instances errors.

0 commit comments

Comments
 (0)