# yield

One of my favorite road signs in Alaska alvin July 17, 2019 - 5:25pm

One of my favorite road signs in Alaska - “Caution: Yield to All Aircraft.” Seems like great advice. You can find this sign somewhere around Lake Hood, in Anchorage, Alaska.

## How to create a Scala “for comprehension” (for/yield loop)

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 3.4, “How to create a "for comprehension" (for/yield loop).”

## Problem

You want to create a new collection from an existing collection by applying an algorithm (and potentially one or more guards) to each element in the original collection.

## Solution

Use a `yield` statement with a `for` loop and your algorithm to create a new collection from an existing collection.

## How to transform one Scala collection to another with the ‘map’ function (method)

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 10.14, “How to Transform One Scala Collection to Another With the `map` function (method)”

## Problem

Like the previous recipe, you want to transform one collection into another by applying an algorithm to every element in the original collection.

## How to transform Scala collections with for/yield

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 10.13, “How to Transform One Scala Collection to Another with for/yield”

## Problem

You want to create a new collection from an existing collection by transforming the elements with an algorithm.