You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/src/main/tut/pretty_print.md
+20-15
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ section: "main_menu"
5
5
position: 3
6
6
---
7
7
8
-
## Case class Example
8
+
## Typesafe pretty-print of case-class.
9
9
10
10
```scala
11
11
@@ -32,39 +32,44 @@ This works for any level of **deep nested structure of case class**. This is don
32
32
The main idea here is, if any field in any part of the nested case class isn't safe to be converted to string, it will throw a compile time.
33
33
Also, if any part of case classes has `Secret`s in it, the value will be hidden. More on this in `Secret / Password` section
34
34
35
-
## Type-safety
35
+
## Why case-classes ?
36
36
37
-
As mentioned in the simple example, `safeStr` can take **_ONLY_****strings** and **case class instances**.
38
-
Infact, the purpose of `safe-string-interpolation` is to make sure you are passing only Strings to `safeStr`.
39
-
Do remember that, if it isn't a case class passed to `safeStr`, there will not be any automatic conversion of non-string types to string types through any automatic `Safe` instances in scope.
40
-
This is intentional. You have to explicitly convert your non-case-class types to string using `nonString.asStr`.
41
-
42
-
#### Case class isn't a string ! So why should it work with safeStr ?
43
-
Delegating the job of stringifying a case class to the user has always been troublesome and it kills the user's time. In fact, it is a popular problem that we solved here.
37
+
While the purpose of `safe-string-interpolation` is to make sure you are passing only Strings to `safeStr`, it works for case-class instances as well.
38
+
There is a reason for this.
39
+
40
+
Delegating the job of stringifying a case class to the user has always been an infamous problem and it kills the user's time.
44
41
The `safe-string-interpolation` takes up this tedious job, and macros under the hood converts it to a readable string, while hiding `Secret` types.
45
-
As mentioned earlier, anything else other than strings and (automatically stringifiable) case classes will be rejected by compiler.
0 commit comments