O'Reilly logo

Scala Functional Programming Patterns by Atul S. Khot

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A validation problem

We need to validate incoming data. Consider an online banking application. Users have already registered and their passwords are with the bank.

The bank security team changed their requirements, so each password must now have at least six characters and a mix of upper and lowercase letters. We need to pull out the already existing passwords and see if these qualify with the new rules.

So, given a list of password strings, we need to compute a corresponding list of Booleans that will return true if the password qualifies, and otherwise false. In other words, given this list of password strings, we need a Tuple2(List[String], List[Boolean]).

Setting the stage

The following is the example list of passwords:

scala> val passwords ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required