if want to write a custom assertions for something...
# strikt
m
if want to write a custom assertions for something like
Option<T>
where it is either a
Some
or
None
type, what is the best way to rite those? for example, would it be better to have something like
Copy code
fun Assertion.Builder<Option<T>>.isSome(asserts: Assertion.Builder<T>.() -> Unit)
or is there a better way to "chain" it where it short circuits the following assertions if it a
None
?
Copy code
fun Assertion.Builder<Option<T>>.isSome(): Assertion.Builder<T>
s
Can't you do both?
Copy code
fun <T> Assertion.Builder<Option<T>>.isSome(valueAssertions: Assertion.Builder<T>.() -> Unit = {}): Assertion.Builder<T>
Should cover both cases. If you're using Arrow Datatypes I already tried it like this for some of Datatypes, you can check it out at https://github.com/sandjelkovic/kombinator/blob/master/kombinator-spring-mvc/src/test/kotlin/com/sandjelkovic/kombinator/test/StriktExtensions.kt It works great
m
hah awesome, it is for arrow thanks for the example, i didnt think of doing the chaining like you did
Copy code
.isA<Some<T>>()
        .get { t }
        .and(valueAssertions)