Commit Graph

18 Commits

Author SHA1 Message Date
Michael Bull 410563b621 Add toResultOr
Acts as a factory function to convert nullable types to Result types
2018-01-24 18:20:39 +00:00
Michael Bull 631f81d8ae Fix mis-ordered modifier keywords
https://kotlinlang.org/docs/reference/coding-conventions.html#modifiers
2018-01-19 14:21:32 +00:00
Michael Bull 76870ef78a Catch Exception instead of Throwable in Result.of 2018-01-11 18:31:10 +00:00
Michael Bull c2fc72d0cb Add zip functions 2018-01-11 18:28:31 +00:00
Michael Bull c5a11a914e Simplify doc comments according to Kotlin Coding Conventions
https://kotlinlang.org/docs/reference/coding-conventions.html#documentation-comments
2018-01-10 16:04:40 +00:00
Michael Bull c6be93142d Add lazy variants for {and,or,getOr,getErrorOr} 2018-01-10 13:27:02 +00:00
Michael Bull 44a4467595 Alias flatMap function to andThen 2017-12-17 00:16:03 +00:00
Michael Bull b2d29d62b7 Improve javadoc 2017-12-17 00:14:27 +00:00
Michael Bull 3e3b649193 Mark on{Success,Failure} as infix 2017-12-16 22:30:04 +00:00
Kevin Herron 47fa20ca34 Inline the onSuccess() and onFailure() functions 2017-12-16 14:12:07 -08:00
Michael Bull e455be2cc8 Make lambda return type of expect{Err} return Any
When constructing the exception message the toString method will be
implicitly called on the result of the lambda.

Takes inspiration from Kotlin's require function [1].

[1]: https://github.com/JetBrains/kotlin/blob/v1.2.0/libraries/stdlib/src/kotlin/util/Preconditions.kt#L26
2017-11-28 18:23:36 +00:00
Michael Bull 5d5195af9d Add getErrorOrElse
Matches getOrElse signature with respect to the error.
2017-11-22 23:25:28 +00:00
Michael Bull ad7adacf39 Lazily evaluate message argument in expect/expectError 2017-11-22 23:25:28 +00:00
Michael Bull af13c9ee7c Rename Error class to Err
Avoids naming conflict with the stdlib's Error class, also now matches
Rust's naming.
2017-10-22 16:08:26 +01:00
Michael Bull 1933c9f845 Use filterIsInstance in getAll methods 2017-10-22 16:07:24 +01:00
Michael Bull f0fb536516 Add Result.of factory method
Inspired by result4k, invokes a callback within a try/catch block,
returning an Error if an exception was thrown and Ok otherwise.
2017-10-22 16:07:24 +01:00
Michael Bull dc4101b8ef Remove factory methods and expose Ok/Error constructors
Also converts them to data classes.
2017-10-22 16:07:24 +01:00
Michael Bull bf3aaee77b Move to new package name 2017-10-22 00:59:16 +01:00