Title: Break A Sequence Into Groups
Slug: break_a_sequence_into_groups
Summary: Break A Sequence Into Groups Using Scala.
Date: 2017-01-03 12:00
Category: Scala
Tags: Basics
Authors: Chris Albon
If you want to learn more, check out Scala Cookbook and Programming in Scala.
In [15]:
// Create an array that contains arrays with first and last names
val ages = List(42,25,28,38,58,63,23,458,2569,584,25,25,878)
In [16]:
// If an element is even, return True, if not, return False
val isEven = ages.groupBy(_ % 2 == 0)
In [17]:
// View group that is evens
evensOdds(true)
Out[17]:
In [18]:
// View group that is odds
evensOdds(false)
Out[18]: