fun test(elements: Array<Object>): Try<ByteArray> =
Try.withResources { ByteArrayOutputStream() }
.of { output ->
Try.withResources { SomeObjectOutputStream(output) }
.of { someOutput ->
someOutput.writeObject(elements)
output.toByteArray()
}
}.flatMap { it }
Czy da się to ładniej rozwiązać niż flatMap { it }
?
Czy może jest jakaś opcja, żeby całość lepiej zapisać?