given_BSONDocumentReader_EventWithRootRef

fmgp.did.method.prism.mongo.DataModels.given_BSONDocumentReader_EventWithRootRef
object given_BSONDocumentReader_EventWithRootRef extends BSONDocumentReader[EventWithRootRef]

Attributes

Graph
Supertypes
trait BSONDocumentReader[EventWithRootRef]
trait BSONReader[EventWithRootRef]
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

override def readDocument(doc: BSONDocument): Try[EventWithRootRef]

Tries to produce an instance of T from the document.

Tries to produce an instance of T from the document.

import scala.util.Try
import reactivemongo.api.bson.{ BSONDocument, BSONDocumentReader }

def fromBSON[T](document: BSONDocument)(
 implicit r: BSONDocumentReader[T]): Try[T] = r.readTry(document)

Attributes

Definition Classes
BSONDocumentReader

Inherited methods

final override def afterRead[U](f: EventWithRootRef => U): BSONDocumentReader[U]

Prepares a BSONReader that returns the result of applying f on the result of this reader.

Prepares a BSONReader that returns the result of applying f on the result of this reader.

import scala.util.Try
import reactivemongo.api.bson.{ BSONReader, BSONValue }

// Try to return an integer + 1,
// from any T that can be read from BSON
// and is a numeric type
def fromBSON[T](bson: BSONValue)(
 implicit r: BSONReader[T], n: Numeric[T]): Try[Int] = {
 val r2: BSONReader[Int] = r.afterRead { v => n.toInt(v) + 1 }
 r2.readTry(bson)
}

Value parameters

f

the function to apply

Attributes

Definition Classes
BSONDocumentReader -> BSONReader
Inherited from:
BSONDocumentReader
def beforeRead(f: BSONDocument => BSONDocument): BSONDocumentReader[EventWithRootRef]

Attributes

Inherited from:
BSONDocumentReader
def beforeRead(f: PartialFunction[BSONValue, BSONValue]): BSONReader[EventWithRootRef]

Prepares a BSONReader that transforms the input BSON value, using the given f function, before passing the transformed BSON value to the current reader.

Prepares a BSONReader that transforms the input BSON value, using the given f function, before passing the transformed BSON value to the current reader.

import reactivemongo.api.bson.{
 BSONReader, BSONInteger, BSONNull, BSONString
}

val normalizingReader: BSONReader[Int] =
 implicitly[BSONReader[Int]].beforeRead {
   case BSONNull => BSONInteger(-1)
   case BSONString(s) => BSONInteger(s.size)
   // other values are unchanged
 }

normalizingReader.readOpt(BSONNull) // Some(-1)
normalizingReader.readTry(BSONString("foo")) // Success(3)
normalizingReader.readOpt(BSONInteger(4)) // unchanged: Some(4)

Attributes

Inherited from:
BSONReader
def beforeReadTry(f: BSONDocument => Try[BSONDocument]): BSONDocumentReader[EventWithRootRef]

Attributes

Inherited from:
BSONDocumentReader
def beforeReadTry(f: BSONValue => Try[BSONValue]): BSONReader[EventWithRootRef]

Prepares a BSONReader that transforms the input BSON value, using the given f function, before passing the transformed BSON value to the current reader.

Prepares a BSONReader that transforms the input BSON value, using the given f function, before passing the transformed BSON value to the current reader.

Attributes

Inherited from:
BSONReader
def collect[U](read: PartialFunction[EventWithRootRef, U]): BSONReader[U]

'''EXPERIMENTAL:''' (API may change without notice)

'''EXPERIMENTAL:''' (API may change without notice)

Attributes

Inherited from:
BSONReader
def readOpt(bson: BSONValue): Option[EventWithRootRef]

Tries to produce an instance of T from the bson value, returns None if an error occurred.

Tries to produce an instance of T from the bson value, returns None if an error occurred.

import reactivemongo.api.bson.{ BSONReader, BSONValue }

def fromBSON[T](bson: BSONValue)(implicit r: BSONReader[T]): Option[T] =
 r.readOpt(bson)

Attributes

Inherited from:
BSONReader
def readOrElse(bson: BSONValue, default: => EventWithRootRef): EventWithRootRef

Tries to produce an instance of T from the bson value, returns the default value if an error occurred.

Tries to produce an instance of T from the bson value, returns the default value if an error occurred.

import reactivemongo.api.bson.{ BSONReader, BSONValue }

def fromBSON[T](bson: BSONValue, v: T)(implicit r: BSONReader[T]): T =
 r.readOrElse(bson, v)

Attributes

Inherited from:
BSONReader
final def readTry(bson: BSONValue): Try[EventWithRootRef]

Tries to produce an instance of T from the bson value.

Tries to produce an instance of T from the bson value.

import scala.util.Try
import reactivemongo.api.bson.{ BSONReader, BSONValue }

def fromBSON[T](bson: BSONValue)(implicit r: BSONReader[T]): Try[T] =
 r.readTry(bson)

Attributes

Inherited from:
BSONDocumentReader
override def widen[U >: EventWithRootRef]: BSONDocumentReader[U]

Widens this reader for a compatible type U.

Widens this reader for a compatible type U.

import reactivemongo.api.bson.BSONReader

val listReader: BSONReader[List[String]] =
 implicitly[BSONReader[List[String]]]

val widenAsSeqReader: BSONReader[Seq[String]] =
 listReader.widen[Seq[String]]
 // as Seq[String] >: List[String]

Type parameters

U

must be a super-type of T

Attributes

Definition Classes
BSONDocumentReader -> BSONReader
Inherited from:
BSONDocumentReader