Skip to content

Commit

Permalink
Merge pull request #134 from rstradling/Cats-1.0.0
Browse files Browse the repository at this point in the history
Cats 1.0.0-MF changes
  • Loading branch information
Phil Wills committed Sep 5, 2017
2 parents 2886956 + 1c292bd commit 21b4191
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
9 changes: 5 additions & 4 deletions build.sbt
Expand Up @@ -3,14 +3,14 @@ organization := "com.gu"

scalaVersion := "2.12.1"

crossScalaVersions := Seq("2.11.8", scalaVersion.value)
crossScalaVersions := Seq("2.11.11", scalaVersion.value)

resolvers += Resolver.sonatypeRepo("snapshots")

libraryDependencies ++= Seq(
"com.amazonaws" % "aws-java-sdk-dynamodb" % "1.11.154",
"com.chuusai" %% "shapeless" % "2.3.2",
"org.typelevel" %% "cats-free" % "0.9.0",
"org.typelevel" %% "cats-free" % "1.0.0-MF",
"com.github.mpilquist" %% "simulacrum" % "0.10.0",

// Use Joda for custom conversion example
Expand All @@ -36,7 +36,8 @@ scalacOptions := Seq(
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard"
"-Ywarn-value-discard",
"-Ypartial-unification"
)

dynamoDBLocalDownloadDir := file(".dynamodb-local")
Expand Down Expand Up @@ -120,4 +121,4 @@ micrositePalette := Map(
"gray-light" -> "#E3E2E3",
"gray-lighter" -> "#F4F3F4",
"white-color" -> "#FFFFFF"
)
)
2 changes: 1 addition & 1 deletion project/plugins.sbt
Expand Up @@ -12,4 +12,4 @@ addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.1")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.0")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.1.0")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.1.0")
10 changes: 5 additions & 5 deletions src/main/scala/com/gu/scanamo/DynamoFormat.scala
Expand Up @@ -276,7 +276,7 @@ object DynamoFormat extends EnumDynamoFormat {
*/
implicit def listFormat[T](implicit f: DynamoFormat[T]): DynamoFormat[List[T]] =
xmap[List[T], java.util.List[AttributeValue]](
_.asScala.toList.traverseU(f.read))(
_.asScala.toList.traverse(f.read))(
_.map(f.write).asJava
)(javaListFormat)

Expand All @@ -299,7 +299,7 @@ object DynamoFormat extends EnumDynamoFormat {
*/
implicit def vectorFormat[T](implicit f: DynamoFormat[T]): DynamoFormat[Vector[T]] =
xmap[Vector[T], java.util.List[AttributeValue]](
_.asScala.toVector.traverseU(f.read))(
_.asScala.toVector.traverse(f.read))(
_.map(f.write).asJava
)(javaListFormat)

Expand All @@ -312,15 +312,15 @@ object DynamoFormat extends EnumDynamoFormat {
*/
implicit def arrayFormat[T:ClassTag](implicit f: DynamoFormat[T]): DynamoFormat[Array[T]] =
xmap[Array[T], java.util.List[AttributeValue]](
_.asScala.toList.traverseU(f.read).map(_.toArray))(
_.asScala.toList.traverse(f.read).map(_.toArray))(
_.map(f.write).toList.asJava
)(javaListFormat)

private val javaNumSetFormat = attribute(_.getNS, "NS")(_.withNS)
private val javaStringSetFormat = attribute(_.getSS, "SS")(_.withSS)
private def setFormat[T](r: String => Either[DynamoReadError, T])(w: T => String)(df: DynamoFormat[java.util.List[String]]): DynamoFormat[Set[T]] =
xmap[Set[T], java.util.List[String]](
_.asScala.toList.traverseU(r).map(_.toSet))(
_.asScala.toList.traverse(r).map(_.toSet))(
_.map(w).toList.asJava
)(df)

Expand Down Expand Up @@ -383,7 +383,7 @@ object DynamoFormat extends EnumDynamoFormat {
*/
implicit def mapFormat[V](implicit f: DynamoFormat[V]): DynamoFormat[Map[String, V]] =
xmap[Map[String, V], java.util.Map[String, AttributeValue]](
_.asScala.toMap.traverseU(f.read))(
_.asScala.toMap.traverse(f.read))(
_.mapValues(f.write).asJava
)(javaMapFormat)

Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/com/gu/scanamo/ScanamoFree.scala
Expand Up @@ -20,7 +20,7 @@ object ScanamoFree {
ScanamoOps.put(ScanamoPutRequest(tableName, f.write(item), None))

def putAll[T](tableName: String)(items: Set[T])(implicit f: DynamoFormat[T]): ScanamoOps[List[BatchWriteItemResult]] =
items.grouped(batchSize).toList.traverseU(batch =>
items.grouped(batchSize).toList.traverse(batch =>
ScanamoOps.batchWrite(
new BatchWriteItemRequest().withRequestItems(Map(tableName -> batch.toList.map(i =>
new WriteRequest().withPutRequest(new PutRequest().withItem(f.write(i).getM))
Expand All @@ -29,7 +29,7 @@ object ScanamoFree {
)

def deleteAll(tableName: String)(items: UniqueKeys[_]): ScanamoOps[List[BatchWriteItemResult]] = {
items.asAVMap.grouped(batchSize).toList.traverseU { batch =>
items.asAVMap.grouped(batchSize).toList.traverse { batch =>
ScanamoOps.batchWrite(
new BatchWriteItemRequest().withRequestItems(
Map(tableName -> batch.toList
Expand All @@ -56,7 +56,7 @@ object ScanamoFree {
Option(res.getItem).map(read[T])

def getAll[T: DynamoFormat](tableName: String)(keys: UniqueKeys[_]): ScanamoOps[Set[Either[DynamoReadError, T]]] = {
keys.asAVMap.grouped(batchSize).toList.traverseU { batch =>
keys.asAVMap.grouped(batchSize).toList.traverse { batch =>
ScanamoOps.batchGet(
new BatchGetItemRequest().withRequestItems(Map(tableName ->
new KeysAndAttributes().withKeys(batch.map(_.asJava).asJava)
Expand Down

0 comments on commit 21b4191

Please sign in to comment.