Package

org.taffy.core.container

Object Hierarchy
What is it?

A Pair is a container that contains two objects: left and right.

Quick Example
pair = [Pair left: 1 right: 100]



Table of Contents:

Constructing a Pair

A Pair is created by either the Pair#left:right: method, or by the new keyword and setLeft: and setRight:.

// create a pair via the Pair#left:right: method
pair = [Pair left: -1 right: 20]
==> #Pair<-1, 20>

// create a pair, and set its values later
// by default, left and right are nil
pair = new Pair
==> #Pair<nil, nil>

pair setLeft: "1"
==> #Pair<"1", nil>

pair setRight: "2"
==> #Pair<"1", "2">

The left and right values are arbitrary.

Setting and Getting

As seen above, the setLeft: and setRight: methods set values in a pair. Use left and right to get values:

pair = [Pair left: 'cow right: 'jumps]

pair left
==> 'cow

pair right
==> 'jumps

Iterating

The elements of an array can be iterated by using the each: method:

pair = [Pair left: 1 right: 2]

pair each: { <value>
    io putLine: value
}

==> 1
==> 2

Arithmetic

Since Pair inherits from LineContainer, it supports mean, min, max, range, variance and standardDeviation.

pair = [Pair left: 1 right: 2]

pair min
==> 1

pair max
==> 2

pair mean
==> 1.5

pair range
==> 1

pair variance
==> 0.25

pair standardDeviation
==> 0.5