Skip to content
This repository has been archived by the owner on Mar 29, 2018. It is now read-only.
pNre edited this page Jun 14, 2014 · 5 revisions

Contents

#Instance methods ##Iteration

times

  • times <T> (call: () -> T)
  • times (call: () -> ())

Iterates call, self times.

  • times <T> (call: (Int) -> T)

Iterates call, with an Int index argument, self times.

Example

5.times { println("Hi") }
/* Prints → */
// → Hi
// → Hi
// → Hi
// → Hi
// → Hi

upTo

  • upTo (limit: Int, call: (Int) -> ())

Iterates call, passing in integer values from self up to and including limit.

Example

5.upTo(7, { println($0) })
/* Prints → */
// → 5
// → 6
// → 7

downTo

  • downTo (limit: Int, call: (Int) -> ())

Iterates call, passing in integer values from self down to and including limit.

Example

7.downTo(5, { println($0) })
/* Prints → */
// → 7
// → 6
// → 5

##Math

isEven

  • isEven () -> Bool

Returns true if self is even.

Example

4.isEven()
// → true

isOdd

  • isOdd () -> Bool

Returns true if self is odd.

Example

3.isOdd()
// → true

clamp

  • clamp (range: Range<Int>) -> Int
  • clamp (min: Int, max: Int) -> Int

Computes the value of self clamped to a range defined by range (or min...max).

Example

5.clamp(0...4)
// → 4

1.clamp(2...4)
// → 2
Clone this wiki locally