From b6aeaac96c4b129c9b5cf82ab23c20914184374e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sat, 7 Mar 2026 22:42:22 +0100 Subject: [PATCH] docs(compat-arrow): Include resources in the module-level documentation --- compat/compat-arrow/README.md | 39 +++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/compat/compat-arrow/README.md b/compat/compat-arrow/README.md index f62b930..318c908 100644 --- a/compat/compat-arrow/README.md +++ b/compat/compat-arrow/README.md @@ -1,10 +1,12 @@ # Module Compatibility with Arrow -Helpers to fail tests when a function raises. +Helpers to fail tests when a function raises and to use resources. -### Example +# Package opensavvy.prepared.compat.arrow.core + +Helpers to integrate Arrow's Raise DSL into tests. Let's assume we want to test a function which raises when it receives a negative number: @@ -43,3 +45,36 @@ test("√-1 raises") { } } ``` + +# Package opensavvy.prepared.compat.arrow.coroutines + +Helpers to use Arrow's Resource DSL in tests. + +Let's assume that we want to test a service we own that is already encapsulated in a resource within your production code: + +```kotlin +val userProcessor: Resource = resource({ + UserProcessor().also { it.start() } +}) { p, _ -> p.shutdown() } + +val dataSource: Resource = resource({ + DataSource().also { it.connect() } +}) { ds, exitCase -> + println("Releasing $ds with exit: $exitCase") + withContext(Dispatchers.IO) { ds.close() } +} + +val service: Resource = resource { + Service(dataSource.bind(), userProcessor.bind()) +} +``` + +We can use [asPrepared][opensavvy.prepared.compat.arrow.coroutines.asPrepared] to convert that resource into Prepared's native [prepared values][opensavvy.prepared.suite.Prepared]: + +```kotlin +val preparedService by service.asPrepared() + +test("create() should not return null") { + check(preparedService().create() != null) +} +``` -- 2.51.2