ToState
Given any set of values (for example: an object) invoke a function if the values are valid. The function to be invoked can be a constructor, resulting in another object with more strict nullability and immutability.
See the ToState documentation for more information.
Why Use ToState?
There are a couple of reasons why ToState is better than doing the check of the parameters yourself:
- The code is less verbose, so easier to read and understand.
- No exceptions are used, so handling incorrect state is less cumbersome. ToState uses the Kotlin idiom of 'or
null'.
Use Cases
Below are some situations where this library can be useful:
Disadvantages
ToState is not a solution for every situation. Check Disadvantages to determine if it is a fit for your needs.
Using ToState
API Documentation
The API documentation of all versions of ToState is available online.
Dependency
Add ToState to your project by adding a repository and declaring a dependency.
Repository
You have to add the Zybber artifact repository to the list of repositories. See the documentation of the releases at the Zybber artifacts for instructions.
Dependency Declaration
Add the dependency for ToState. See below for instructions for specific build systems.
Gradle
Using Kotlin scripts:
implementation("com.zybber:zybber-to-state:1")
Using Groovy scripts:
implementation 'com.zybber:zybber-to-state:1'
Where needed, use a version catalog, and an appropriate dependency configuration.
Maven
<dependency>
<groupId>com.zybber</groupId>
<artifactId>zybber-to-state</artifactId>
<version>1</version>
</dependency>
Where needed, use dependency management, and an appropriate scope.
Versioning Scheme
ToState is a small and very simple library, so uses a very simple versioning scheme: a single number. Whenever there is a release, the number is incremented by 1. No distinction is made between minor features, fixes and vulnerability fixes.
If the need arises to break the API, the code will be moved to another package, and another artifact name will be used. For example: package com.zybber.to_state2 and artifact zybber-to-state2-1.jar
Examples
Examples can be found in the Dokka documentation. And here are some additional examples: