prop> import org.scalacheck._ prop> implicit def arbNonEmptySet[T: Arbitrary] = Arbitrary(Gen.nonEmptyContainerOf[Set, T](Arbitrary.arbitrary[T])) prop> (s: Set[BigDecimal]) => | val av = DynamoValue.fromNumbers(s) | DynamoFormat[Set[BigDecimal]].write(s) == av && | DynamoFormat[Set[BigDecimal]].read(av) == Right(s) >>> DynamoFormat[Set[BigDecimal]].write(Set.empty).isNull true
prop> (a: Array[String]) => | DynamoFormat[Array[String]].read(DynamoFormat[Array[String]].write(a)).right.getOrElse(Array("error")).toList == | a.toList
prop> (d: BigDecimal) =>
| DynamoFormat[BigDecimal].read(DynamoFormat[BigDecimal].write(d)) == Right(d)
prop> (b: Boolean) => | DynamoFormat[Boolean].read(DynamoFormat[Boolean].write(b)) == Right(b)
prop> (ab:Array[Byte]) => | DynamoFormat[Array[Byte]].read(DynamoFormat[Array[Byte]].write(ab)) == Right(ab)
prop> (b: Byte) => | DynamoFormat[Byte].read(DynamoFormat[Byte].write(b)) == Right(b)
Returns a DynamoFormat for the case where A
can always be converted B
,
with write
, but read
may throw an exception for some value of B
Returns a DynamoFormat for the case where A
can always be converted B
,
with write
, but read
may throw an exception for some value of B
>>> import org.joda.time._ >>> val jodaStringFormat = DynamoFormat.coercedXmap[LocalDate, String, IllegalArgumentException]( ... LocalDate.parse ... )( ... _.toString ... ) >>> jodaStringFormat.read(jodaStringFormat.write(new LocalDate(2007, 8, 18))) Right(2007-08-18) >>> jodaStringFormat.read(DynamoValue.fromString("Togtogdenoggleplop")) Left(TypeCoercionError(java.lang.IllegalArgumentException: Invalid format: "Togtogdenoggleplop"))
prop> (d: Double) => | DynamoFormat[Double].read(DynamoFormat[Double].write(d)) == Right(d)
prop> import org.scalacheck._ prop> implicit def arbNonEmptySet[T: Arbitrary] = Arbitrary(Gen.nonEmptyContainerOf[Set, T](Arbitrary.arbitrary[T])) prop> (s: Set[Double]) => | val av = DynamoValue.fromNumbers(s) | DynamoFormat[Set[Double]].write(s) == av && | DynamoFormat[Set[Double]].read(av) == Right(s) >>> DynamoFormat[Set[Double]].write(Set.empty).isNull true
prop> (d: Float) => | DynamoFormat[Float].read(DynamoFormat[Float].write(d)) == Right(d)
prop> import org.scalacheck._ prop> implicit def arbNonEmptySet[T: Arbitrary] = Arbitrary(Gen.nonEmptyContainerOf[Set, T](Arbitrary.arbitrary[T])) prop> (s: Set[Float]) => | val av = DynamoValue.fromNumbers(s) | DynamoFormat[Set[Float]].write(s) == av && | DynamoFormat[Set[Float]].read(av) == Right(s) >>> DynamoFormat[Set[Float]].write(Set.empty).isNull true
prop> (s: Set[Boolean]) => | DynamoFormat[Set[Boolean]].read(DynamoFormat[Set[Boolean]].write(s)) == | Right(s)
Format for dealing with points in time stored as the number of milliseconds since Epoch.
Format for dealing with points in time stored as the number of milliseconds since Epoch.
prop> import org.scanamo.DynamoFormat prop> import java.time.Instant prop> import org.scanamo.TimeGenerators.instantAsLongArb prop> (x: Instant) => | DynamoFormat[Instant].read(DynamoFormat[Instant].write(x)) == Right(x)
prop> (i: Int) => | DynamoFormat[Int].read(DynamoFormat[Int].write(i)) == Right(i)
prop> import org.scalacheck._ prop> implicit def arbNonEmptySet[T: Arbitrary] = Arbitrary(Gen.nonEmptyContainerOf[Set, T](Arbitrary.arbitrary[T])) prop> (s: Set[Int]) => | val av = DynamoValue.fromNumbers(s) | DynamoFormat[Set[Int]].write(s) == av && | DynamoFormat[Set[Int]].read(av) == Right(s) >>> DynamoFormat[Set[Int]].write(Set.empty).isNull true
Returns a DynamoFormat for the case where A
and B
are isomorphic,
i.e.
Returns a DynamoFormat for the case where A
and B
are isomorphic,
i.e. an A
can always be converted to a B
and vice versa.
If there are some values of B
that have no corresponding value in A
,
use DynamoFormat.xmap or DynamoFormat.coercedXmap.
>>> case class UserId(value: String) >>> implicit val userIdFormat = ... DynamoFormat.iso[UserId, String](UserId.apply)(_.value) >>> DynamoFormat[UserId].read(DynamoValue.fromString("Eric")) Right(UserId(Eric))
prop> (l: List[String]) => | DynamoFormat[List[String]].read(DynamoFormat[List[String]].write(l)) == | Right(l)
prop> (l: Long) => | DynamoFormat[Long].read(DynamoFormat[Long].write(l)) == Right(l)
prop> import org.scalacheck._ prop> implicit def arbNonEmptySet[T: Arbitrary] = Arbitrary(Gen.nonEmptyContainerOf[Set, T](Arbitrary.arbitrary[T])) prop> (s: Set[Long]) => | val av = DynamoValue.fromNumbers(s) | DynamoFormat[Set[Long]].write(s) == av && | DynamoFormat[Set[Long]].read(av) == Right(s) >>> DynamoFormat[Set[Long]].write(Set.empty).isNull true
prop> (m: Map[String, Int]) => | DynamoFormat[Map[String, Int]].read(DynamoFormat[Map[String, Int]].write(m)) == | Right(m)
Format for dealing with date-times with an offset from UTC.
Format for dealing with date-times with an offset from UTC.
prop> import org.scanamo.DynamoFormat prop> import java.time.OffsetDateTime prop> import org.scanamo.TimeGenerators.offsetDateTimeArb prop> (x: OffsetDateTime) => | DynamoFormat[OffsetDateTime].read(DynamoFormat[OffsetDateTime].write(x)) == Right(x)
prop> (o: Option[Long]) => | DynamoFormat[Option[Long]].read(DynamoFormat[Option[Long]].write(o)) == | Right(o) >>> DynamoFormat[Option[Long]].read(DynamoValue.nil) Right(None) >>> DynamoFormat[Option[Long]].write(None).isNull true
prop> (sq: Seq[String]) => | DynamoFormat[Seq[String]].read(DynamoFormat[Seq[String]].write(sq)) == | Right(sq)
prop> (s: Short) => | DynamoFormat[Short].read(DynamoFormat[Short].write(s)) == Right(s)
This ensures that if, for instance, you specify an update with Some(5) rather
than making the type of Option
explicit, it doesn't fall back to auto-derivation
prop> (s: String) => | DynamoFormat[String].read(DynamoFormat[String].write(s)) == Right(s)
prop> import org.scalacheck._ prop> implicit val arbSet = Arbitrary(Gen.nonEmptyContainerOf[Set, String](Arbitrary.arbitrary[String])) prop> (s: Set[String]) => | val av = DynamoValue.fromStrings(s) | DynamoFormat[Set[String]].write(s) == av && | DynamoFormat[Set[String]].read(av) == Right(s) >>> DynamoFormat[Set[String]].write(Set.empty).isNull true
prop> (uuid: java.util.UUID) =>
| DynamoFormat[java.util.UUID].read(DynamoFormat[java.util.UUID].write(uuid)) ==
| Right(uuid)
prop> (v: Vector[String]) => | DynamoFormat[Vector[String]].read(DynamoFormat[Vector[String]].write(v)) == | Right(v)
>>> import org.joda.time._ >>> implicit val jodaLongFormat = DynamoFormat.xmap[DateTime, Long]( ... l => Right(new DateTime(l).withZone(DateTimeZone.UTC)) ... )( ... _.withZone(DateTimeZone.UTC).getMillis ... ) >>> DynamoFormat[DateTime].read(DynamoValue.fromNumber(0L)) Right(1970-01-01T00:00:00.000Z)
Format for dealing with date-times with a time zone in the ISO-8601 calendar system.
Format for dealing with date-times with a time zone in the ISO-8601 calendar system.
prop> import org.scanamo.DynamoFormat prop> import java.time.ZonedDateTime prop> import org.scanamo.TimeGenerators.zonedDateTimeArb prop> (x: ZonedDateTime) => | DynamoFormat[ZonedDateTime].read(DynamoFormat[ZonedDateTime].write(x)) == Right(x)