avatar

Andres Jaimes

Parsing Json with the Play Framework

This article discusses different common scenarios for JSON parsing and conversion, useful when working with the Play Framework library. All the examples in the article, use one or more of the following library imports:

1import …

Scala Lectures

A curated list of Scala lectures on functional programming and design patterns.

Functional programming design patterns

In …

Using Cats Effect IO with the Play Framework

Cats Effect IO operations have to be performed at the highest level possible. So when working with the Play Framework the solution is to execute unsafeToFuture() in the controller methods.

1def get = Action.async { implicit request =>
2  service. …

Quick notes on functors

Functors

A functor is a design pattern that allows us to apply a function to a contextualized (wrapped) type. This is accomplished by implementing the map function:

1fmap :: (a -> b) -> f a -> f b

Notes on lazy evaluation

Lazy evaluation is a strategy that delays expression evaluation until their value is needed. It also avoids repeated evaluations by returning previously computed results by storing them in a lookup table.

Why isn’t lazy evaluation used …

Future Either

This implementation is based on the work of Malcolm, and exists because it provides the cleanest use of similar monads.

The base monad wraps an Either class in a Future class:

 1import scala.concurrent.{ExecutionContext, Future}
 2import scala.util.{ …

Generate a random string using the console

Generate a random string using the command line:

1cat /dev/urandom | tr -cd [:graph:] | head -c 32

On OSX, the previous command might return a tr: Illegal byte sequence error, so try:

1export LC_ALL=C; cat /dev/urandom | tr -cd [:graph:] | head -c 32 …

AES Encryption with Base64 encoding

We start by adding our imports.

1import java.nio.charset.StandardCharsets
2import java.security.Key
3import java.util.Base64
4import javax.crypto.Cipher
5import javax.crypto.spec.SecretKeySpec

For this example we’re going to use the CBC (Cipher …