Skip to content

Commit

Permalink
Add utility methods to BsonKeyDecoder & BsonKeyEncoder
Browse files Browse the repository at this point in the history
  • Loading branch information
danslapman committed Jan 4, 2025
1 parent 93c6191 commit 905862c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions oolong-bson/src/main/scala/oolong/bson/BsonKeyDecoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ import scala.util.Try
trait BsonKeyDecoder[T]:
def decode(value: String): Try[T]

def emapTry[H](f: T => Try[H]): BsonKeyDecoder[H] =
(value: String) => this.decode(value).flatMap(f)

object BsonKeyDecoder:
def apply[T](using bkd: BsonKeyDecoder[T]) = bkd
3 changes: 3 additions & 0 deletions oolong-bson/src/main/scala/oolong/bson/BsonKeyEncoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ package oolong.bson
trait BsonKeyEncoder[T]:
def encode(t: T): String

def beforeWrite[H](f: H => T): BsonKeyEncoder[H] =
(value: H) => this.encode(f(value))

object BsonKeyEncoder:
def apply[T](using bke: BsonKeyEncoder[T]) = bke

0 comments on commit 905862c

Please sign in to comment.