-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
maybeFound
convenience extension method (#376)
- Loading branch information
Showing
3 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package zio.dynamodb | ||
|
||
import zio.ZIO | ||
|
||
object syntax { | ||
implicit class MaybeFound[R, A](zio: ZIO[R, DynamoDBError, Either[DynamoDBError.ItemError, A]]) { | ||
|
||
/** | ||
* Moves Left[ItemError.DecodingError] to the error channel and returns Some(a) if the item is found else None | ||
* eg {{{ DynamoDBQuery.get("table")(Person.id.partitionKey === 1).execute.maybeFound }}} | ||
*/ | ||
def maybeFound: ZIO[R, DynamoDBError, Option[A]] = | ||
zio.flatMap { | ||
case Left(e @ DynamoDBError.ItemError.DecodingError(_)) => ZIO.fail(e) | ||
case Left(DynamoDBError.ItemError.ValueNotFound(_)) => ZIO.succeed(None) | ||
case Right(a) => ZIO.succeed(Some(a)) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters