generated from arrow-kt/Arrow-KMP-Template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Change Exact to abstract class * Fix README * Turn Exact back to interface but keep spec function * Change the position of example with delegation * Fix documentation * Pass ExactError on ensure Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com> --------- Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
- Loading branch information
Showing
10 changed files
with
232 additions
and
140 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
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
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
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 |
---|---|---|
@@ -1,34 +1,27 @@ | ||
// This file was automatically generated from Exact.kt by Knit tool. Do not edit. | ||
package arrow.exact.knit.example.exampleExact03 | ||
|
||
import arrow.core.raise.Raise | ||
import arrow.core.raise.ensure | ||
import arrow.exact.Exact | ||
import arrow.exact.ExactEither | ||
import arrow.exact.ExactError | ||
import arrow.exact.exact | ||
import arrow.exact.exactEither | ||
import arrow.exact.ensure | ||
|
||
@JvmInline value class NotBlankTrimmedString private constructor(val value: String) { | ||
companion object : Exact<String, NotBlankTrimmedString> by exact({ | ||
ensure(raw.isNotBlank()) { ExactError("Cannot be blank.") } | ||
NotBlankTrimmedString(raw.trim()) | ||
}) | ||
} | ||
|
||
sealed interface UsernameError { | ||
object Invalid : UsernameError | ||
data class Offensive(val username: String) : UsernameError | ||
class NotBlankString private constructor(val value: String) { | ||
companion object : Exact<String, NotBlankString> { | ||
override fun Raise<ExactError>.spec(raw: String): NotBlankString { | ||
ensure(raw.isNotBlank()) { ExactError("Cannot be blank.") } | ||
return NotBlankString(raw) | ||
} | ||
} | ||
} | ||
|
||
@JvmInline | ||
value class Username private constructor(val value: String) { | ||
companion object : ExactEither<UsernameError, String, Username> by exactEither({ | ||
val username = | ||
ensure(NotBlankTrimmedString) { | ||
UsernameError.Invalid | ||
}.value | ||
ensure(username.length < 100) { UsernameError.Invalid } | ||
ensure(username !in listOf("offensive")) { UsernameError.Offensive(username) } | ||
Username(username) | ||
}) | ||
value class NotBlankTrimmedString private constructor(val value: String) { | ||
companion object : Exact<String, NotBlankTrimmedString> { | ||
override fun Raise<ExactError>.spec(raw: String): NotBlankTrimmedString { | ||
ensure(raw, NotBlankString) | ||
return NotBlankTrimmedString(raw.trim()) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// This file was automatically generated from Exact.kt by Knit tool. Do not edit. | ||
package arrow.exact.knit.example.exampleExact04 | ||
|
||
import arrow.core.raise.Raise | ||
import arrow.core.raise.ensure | ||
import arrow.exact.Exact | ||
import arrow.exact.ExactEither | ||
import arrow.exact.ExactError | ||
import arrow.exact.ensure | ||
|
||
@JvmInline | ||
value class NotBlankTrimmedString private constructor(val value: String) { | ||
companion object : Exact<String, NotBlankTrimmedString> { | ||
override fun Raise<ExactError>.spec(raw: String): NotBlankTrimmedString { | ||
ensure(raw.isNotBlank()) { ExactError("Cannot be blank.") } | ||
return NotBlankTrimmedString(raw.trim()) | ||
} | ||
} | ||
} | ||
|
||
sealed interface UsernameError { | ||
object Invalid : UsernameError | ||
data class Offensive(val username: String) : UsernameError | ||
} | ||
|
||
@JvmInline | ||
value class Username private constructor(val value: String) { | ||
companion object : ExactEither<UsernameError, String, Username> { | ||
override fun Raise<UsernameError>.spec(raw: String): Username { | ||
val username = | ||
ensure(raw, NotBlankTrimmedString) { | ||
UsernameError.Invalid | ||
}.value | ||
ensure(username.length < 100) { UsernameError.Invalid } | ||
ensure(username !in listOf("offensive")) { UsernameError.Offensive(username) } | ||
return Username(username) | ||
} | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// This file was automatically generated from README.md by Knit tool. Do not edit. | ||
package arrow.exact.knit.example.exampleReadme03 | ||
|
||
import arrow.core.raise.Raise | ||
import arrow.core.raise.ensure | ||
import arrow.exact.Exact | ||
import arrow.exact.ExactError | ||
import arrow.exact.ensure | ||
|
||
@JvmInline | ||
value class NotBlankString private constructor(val value: String) { | ||
companion object : Exact<String, NotBlankString> { | ||
override fun Raise<ExactError>.spec(raw: String): NotBlankString { | ||
ensure(raw.isNotBlank()) { ExactError("Cannot be blank.") } | ||
return NotBlankString(raw) | ||
} | ||
} | ||
} | ||
|
||
@JvmInline | ||
value class NotBlankTrimmedString private constructor(val value: String) { | ||
companion object : Exact<String, NotBlankTrimmedString> { | ||
override fun Raise<ExactError>.spec(raw: String): NotBlankTrimmedString { | ||
ensure(raw, NotBlankString) | ||
return NotBlankTrimmedString(raw.trim()) | ||
} | ||
} | ||
} |
Oops, something went wrong.