-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update scala-cli-md-spec to 0.1.0, fix workarounds for index.md with …
…multi-file Scala CLI snippet
- Loading branch information
1 parent
8b7ef49
commit bd356ac
Showing
2 changed files
with
90 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ What does it mean? Imagine you'd have to convert between this Protobuf-like defi | |
!!! example | ||
|
||
```scala | ||
// file: dto.scala - part of the demo | ||
//> using scala {{ scala.3 }} | ||
case class UserDTO( | ||
name: String, // 1. primitive | ||
addresses: Seq[AddressDTO], // 2. Seq collection | ||
|
@@ -42,6 +44,7 @@ and this domain model: | |
!!! example | ||
|
||
```scala | ||
// file: domain.scala - part of the demo | ||
case class User( | ||
name: Username, // 1. value class | ||
addresses: List[Address], // 2. List collection | ||
|
@@ -71,19 +74,19 @@ From now on, forget about it! Encoding domain object with an infallible transfor | |
!!! example | ||
|
||
```scala | ||
// file: conversion.sc - part of the demo | ||
//> using dep io.scalaland::chimney::{{ chimney_version() }} | ||
import io.scalaland.chimney.dsl._ | ||
|
||
User( | ||
Username("John"), | ||
List(Address("Paper St", "Somewhere")), | ||
RecoveryMethod.Email("[email protected]") | ||
).transformInto[UserDTO] | ||
// UserDTO( | ||
// "John", | ||
// Seq(AddressDTO("Paper St", "Somewhere")), | ||
// Some(RecoveryMethodDTO.Email(EmailDTO("[email protected]"))) | ||
// ) | ||
println( | ||
User( | ||
Username("John"), | ||
List(Address("Paper St", "Somewhere")), | ||
RecoveryMethod.Email("[email protected]") | ||
).transformInto[UserDTO] | ||
) | ||
// expected output: | ||
// UserDTO(John,List(AddressDTO(Paper St,Somewhere)),Some(Email(EmailDTO([email protected])))) | ||
``` | ||
|
||
??? example "Curious about the generated code?" | ||
|
@@ -122,34 +125,37 @@ Done! Decoding Protobuf into domain object with a fallible transformation, like | |
!!! example | ||
|
||
```scala | ||
// file: conversion.sc - part of the demo | ||
//> using dep io.scalaland::chimney::{{ chimney_version() }} | ||
import io.scalaland.chimney.dsl._ | ||
|
||
UserDTO( | ||
"John", | ||
Seq(AddressDTO("Paper St", "Somewhere")), | ||
Option(RecoveryMethodDTO.Email(EmailDTO("[email protected]"))) | ||
println( | ||
UserDTO( | ||
"John", | ||
Seq(AddressDTO("Paper St", "Somewhere")), | ||
Option(RecoveryMethodDTO.Email(EmailDTO("[email protected]"))) | ||
) | ||
.transformIntoPartial[User] | ||
.asEither | ||
.left | ||
.map(_.asErrorPathMessages) | ||
) | ||
.transformIntoPartial[User] | ||
.asEither | ||
.left | ||
.map(_.asErrorPathMessages) | ||
// Right(User( | ||
// Username("John"), | ||
// List(Address("Paper St", "Somewhere")), | ||
// RecoveryMethod.Email("[email protected]") | ||
// )) | ||
|
||
UserDTO( | ||
"John", | ||
Seq(AddressDTO("Paper St", "Somewhere")), | ||
None | ||
// expected output: | ||
// Right(User(Username(John),List(Address(Paper St,Somewhere)),Email([email protected]))) | ||
|
||
println( | ||
UserDTO( | ||
"John", | ||
Seq(AddressDTO("Paper St", "Somewhere")), | ||
None | ||
) | ||
.transformIntoPartial[User] | ||
.asEither | ||
.left | ||
.map(_.asErrorPathMessages) | ||
) | ||
.transformIntoPartial[User] | ||
.asEither | ||
.left | ||
.map(_.asErrorPathMessages) | ||
// Left(List("recovery" -> EmptyValue)) | ||
// expected output: | ||
// Left(List((recovery,EmptyValue))) | ||
``` | ||
|
||
??? example "Curious about the generated code?" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters