However KotlinTest also has some Arrow specific ma...
# arrow
s
However KotlinTest also has some Arrow specific matchers https://github.com/kotlintest/kotlintest/blob/master/doc/reference.md#arrow
s
Thanks, I'll take a look at that. Although I'm looking for more granular approach to assertions on the contained object itself which is usually a complex object. So essentially to be able to do assertions on contained value without explicitly casting the Option to Some and extracting it as a value.
For now I extended Strikt to do something like this, but I was wondering if there's a more standardized way to do these assertions
s
Ah, most data types expose combinators like.
Option#forall
or
Option#exists
which checks the inner value with a
Predicate<A>
These methods are available for every data type that implements
Foldable
so with the next release they will also be available for every time that does if they are missing atm.
Since it’s available on types with a
Foldable
instance you can implement assertions based on
Foldable
. i.e.
fun Kind<F, A>.shouldBe(a: A, FF: Foldable<F>): Boolean = FF.run { this@shouldBe.exits {  this == a} }
s
Sounds interesting, I'll try these approaches as well
👍🏼 1
r
@sandjelkovic if you also have a sample code of what you would like the assertion to look like we can try to reverse engineer that to a function with Arrow and KotlinTest that fits your needs, should not be hard to come up with the help of other people in this channel
s
I was more interested to check if there's a recommended way to do this for Arrow types and in general more Functional approach to assertion, otherwise currently I'm using adapted approach with the example looking like
Copy code
val option = service.findByUUID(uuidString)

        expectThat(option).isDefined {
            get { uuid }.isEqualTo(uuidString)
            get { name }.isEqualTo("Name")
}
Although not yet functional, it works like this for now, but I'm starting to like some of the suggestions better, especially the assertion library independent ones 🙂