Skip to content

Commit

Permalink
fix tutorial complex types 2
Browse files Browse the repository at this point in the history
  • Loading branch information
melrief committed Aug 6, 2017
1 parent 6a0f319 commit 5ad5a54
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions docs/add-support-for-complex-types.md
Expand Up @@ -27,15 +27,15 @@ class Class2(id: String, value: Int) extends Identifiable {
}
```

Because PureConfig is based on Shapeless and Shapeless doesn't support non-case classes and interfaces,
Because PureConfig is based on shapeless and shapeless doesn't support non-case classes and interfaces,
the class above cannot be read automatically by PureConfig.

#### Add support for Identifiable

##### Method 1: Use a Scala copy of the configuration

Because PureConfig works out-of-the-box with Scala sealed familes of case classes, one simple solution
to support unsupported complex types is to
Because PureConfig works out-of-the-box with Scala sealed familes of case classes, one simple solution
to support unsupported complex types is to:

1. define a hierarchy of Scala classes mirroring the complex type;
2. define a conversion from this Scala configuration to the complex type.
Expand Down Expand Up @@ -75,7 +75,7 @@ implicit val identifiableConfigReader: ConfigReader[Identifiable] =
```

**pros**: it's idiomatic and elegant. It uses a type supported by PureConfig to extract the data
needed from the configuration and then map it to the original complex type. Note that this
needed from the configuration and then maps it to the original complex type. Note that this
method follows what you usually do in other libraries (e.g. Circe) to support new data types and
it's both composable and nice to read.

Expand Down
3 changes: 2 additions & 1 deletion docs/add-support-for-simple-types.md
@@ -1,6 +1,7 @@
### Add support for simple types

Let's see how to support the type
PureConfig supports case classes but not regular classes. Let's see how to add support
for a regular class with a single mutable field

```scala
import com.typesafe.config.ConfigFactory.parseString
Expand Down
8 changes: 4 additions & 4 deletions docs/src/main/tut/add-support-for-complex-types.md
Expand Up @@ -27,15 +27,15 @@ class Class2(id: String, value: Int) extends Identifiable {
}
```

Because PureConfig is based on Shapeless and Shapeless doesn't support non-case classes and interfaces,
Because PureConfig is based on shapeless and shapeless doesn't support non-case classes and interfaces,
the class above cannot be read automatically by PureConfig.

#### Add support for Identifiable

##### Method 1: Use a Scala copy of the configuration

Because PureConfig works out-of-the-box with Scala sealed familes of case classes, one simple solution
to support unsupported complex types is to
Because PureConfig works out-of-the-box with Scala sealed familes of case classes, one simple solution
to support unsupported complex types is to:

1. define a hierarchy of Scala classes mirroring the complex type;
2. define a conversion from this Scala configuration to the complex type.
Expand Down Expand Up @@ -75,7 +75,7 @@ implicit val identifiableConfigReader: ConfigReader[Identifiable] =
```

**pros**: it's idiomatic and elegant. It uses a type supported by PureConfig to extract the data
needed from the configuration and then map it to the original complex type. Note that this
needed from the configuration and then maps it to the original complex type. Note that this
method follows what you usually do in other libraries (e.g. Circe) to support new data types and
it's both composable and nice to read.

Expand Down
3 changes: 2 additions & 1 deletion docs/src/main/tut/add-support-for-simple-types.md
@@ -1,6 +1,7 @@
### Add support for simple types

Let's see how to support the type
PureConfig supports case classes but not regular classes. Let's see how to add support
for a regular class with a single mutable field

```tut:silent
import com.typesafe.config.ConfigFactory.parseString
Expand Down

0 comments on commit 5ad5a54

Please sign in to comment.