nesk / akkurate

The expressive validation library for Kotlin
https://akkurate.dev
Apache License 2.0
225 stars 9 forks source link

Provide some conditional helpers #21

Open nesk opened 8 months ago

nesk commented 8 months ago

We could provide some conditional helpers :

Instead of:

if (prop.unwrap() != null) prop { // this: Validatable<SomeClass?>
    constrain { it?.someBool == true }
}

we could write:

prop.ifNotNull { // this: Validatable<SomeClass>
    constrain { it.someBool }
}

We avoid calling unwrap, the receiver is automatically defined, and it's no longer nullable.

Some helpers unrelated to type casting could be useful too: