1. Have a look at the code examples (https://github.com/bszwej/ddd-with-fp-in-scala/blob/master/src/main/scala/com/example/example.scala#L20). If you have e.g. a REST service, you can define DTOs representing your requests using primitive types, but then convert them to the proper core domain model types in the http controller, before entering the inner layers of you application.

2. That sounds like you want to perform an async validation. In this case you have two options:

a) When constructing an object you can pass a function performing the async validation. For instance, if constructing a valid CustomerId requires it to exist in a DB, the smart constructor would have the following signature

```def create(isValid: String => IO[Boolean], value: String): IO[Either[ValidationError, CustomerId]]```.

The drawback here is that the compiler cannot guarantee that CustomerId will be valid i.e. someone might replace the `isValid` function with `_ => IO.pure(true)` in the production code and it'd still compile.

b) You can perform the async validations inside the domain service.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store