nike-inc / fawcett   0.4.0

BSD 3-clause "New" or "Revised" License GitHub

A collection of Monocle lenses for navigating Amazon's API models.

Scala versions: 2.13 2.12 2.11


Fawcett logo

A collection of Monocle lenses for navigating Amazon's API models.


Include the following in your build.sbt. If you're using AWS Java SDK version 1 change the awsSdkVersion to "v1".

val awsSdkVersion = "v2"
resolvers += Resolver.bintrayRepo("nike", "maven"),
libraryDependencies += "" %% s"fawcett-sqs-$awsSdkVersion" % "0.4.0",


The lenses for Amazon's models are contained in an object of the same name with "Lens" appended. For instance, if we need to operate on a SendMessageBatchRequest we have lenses defined on the object SendMessageBatchRequestLens.

Example of getting all the message bodies from a


val messageBodies: List[String] = ReceiveMessageResultLens.allBodies(receiveMessageResult)

Example of setting random de-duplication identifiers on messages in a Here we start with an existing SendMessageBatchRequest, originalRequest, and then modify all the existing or unset de-duplication ids and get a new SendMessageBatchRequestLens, updatedRequest. It's important to note these are two completely different values, originalRequest has not been modified.

import java.util.UUID

val updatedRequest: SendMessageBatchRequest =
  SendMessageBatchRequestLens.allMessageDeduplicationIds.modify(_ => UUID.randomUUID.toString)(originalRequest)

If we define a Getter from Monocle, we can start composing lenses. Here we create a function to extract notes from our message results.

import monocle.Getter
import monocle.functions.all._

case class Note(body: String)

val noteGetter: Getter[Message, Note] = Getter(message => Note(message.getBody))

val getNotes: ReceiveMessageResult => List[Note] =
  ReceiveMessageResultLens.messages composeTraversal each composeGetter noteGetter getAll _


See our contributing guidelines before you start.

Adding Lenses

You can reduce the amount of typing required by using the giter8 scaffolding provided for lenses. Inside of sbt run g8Scaffold lens from the root project. Or just from the command line sbt "g8Scaffold lens"

This will create the basic lens trait and test structure for you.


Release notes


Fawcett is released under the BSD-3 clause license.