You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Added a resolve function to Either.
* Processed some review comments.
* Added docs for catch and resolve functions.
* Improved docs for the resolve function.
* Inlined catch and resolve functions.
* Changed the implementation of the resolve function to not use default values for function parameters so that all function parameters can be inlined.
* Changed the handleItSafely function into catchAndFlatten.
* Made small improvement to tests.
* Sometimes you do need to interact with code that can potentially throw exceptions. In such cases, you should mitigate the possibility that an exception can be thrown. You can do so by using the `catch` function.
320
+
*
321
+
* Example:
322
+
*
323
+
* ```kotlin:ank:playground
324
+
* import arrow.core.Either
325
+
*
326
+
* //sampleStart
327
+
* fun potentialThrowingCode(): String = throw RuntimeException("Blow up!")
328
+
*
329
+
* suspend fun makeSureYourLogicDoesNotHaveSideEffects(): Either<Error, String> =
* In some cases you can not use Either as a value. For instance, when you need to respond to an HTTP request. To resolve Either into one type of value, you can use the resolve function.
343
+
* In the case of an HTTP endpoint you most often need to return some (framework specific) response object which holds the result of the request. The result can be expected and positive, this is the success flow.
344
+
* Or the result can be expected but negative, this is the error flow. Or the result can be unexpected and negative, in this case an unhandled exception was thrown.
345
+
* In all three cases, you want to use the same kind of response object. But probably you want to respond slightly different in each case. This can be achieved by providing specific functions for the success, error and throwable cases.
346
+
*
347
+
* Example:
348
+
*
349
+
* ```kotlin:ank:playground
350
+
* import arrow.core.Either
351
+
* import arrow.core.flatMap
352
+
* import arrow.core.left
353
+
* import arrow.core.right
354
+
*
355
+
* //sampleStart
356
+
* suspend fun httpEndpoint(request: String = "Hello?") =
357
+
* Either.resolve(
358
+
* f = {
359
+
* if (request == "Hello?") "HELLO WORLD!".right()
360
+
* else Error.SpecificError.left()
361
+
* },
362
+
* success = { a -> handleSuccess({ a: Any -> log(Level.INFO, "This is a: $a") }, a) },
363
+
* error = { e -> handleError({ e: Any -> log(Level.WARN, "This is e: $e") }, e) },
0 commit comments