collect

Scala Vector transformer methods (syntax, examples)

This page contains a large collection of examples of how to use Scala Vector class transformer methods.

Transformer methods

A transformer method is a method that constructs a new collection from an existing collection.

Scala best practice: How to use the Option/Some/None pattern

Table of Contents1 - Problem2 - Solution3 - Returning an Option from a method4 - Getting the value from an Option5 - Using Option with Scala collections6 - Using Option with other frameworks7 - Using Try, Success, and Failure8 - Using Either, Left, and Right9 - Discussion10 - Don’t use the get method with Option11 - See Also12 - The Scala Cookbook

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 20.6, “Scala best practice: How to use the Option/Some/None pattern.”

Back to top

Problem

For a variety of reasons, including removing null values from your Scala code, you want to use what I call the Option/Some/None pattern. Or, if you’re interested in a problem (exception) that occurred while processing code, you may want to return Try/Success/Failure from a method instead of Option/Some/None.

How to use the ‘filter’ method to filter a Scala collection

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 10.17, “How to use filter to Filter a Scala Collection”

Problem

You want to filter the items in a collection to create a new collection that contains only the elements that match your filtering criteria.