Pair and tuple

Pair

A pair include 2 elements that is written (x, y) in Scala

Pairs can also be used as patterns: val (label, value) = pair 

Tuple

A tuple includes more than 2 elements

The fields of a tuple can be accessed with names _1, _2, …

Example

Write a function merge sort using pair and pair pattern

 

You May Also Like

About the Author: Phuong Ta Thi Thao

Leave a Reply

avatar
  Subscribe  
Notify of