This repository has been archived by the owner on Mar 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 316
Int
pNre edited this page Jun 14, 2014
·
5 revisions
- Instance methods
- Class methods
#Instance methods ##Iteration
times <T> (call: () -> T)
times (call: () -> ())
Iterates
call
,self
times.
times <T> (call: (Int) -> T)
Iterates
call
, with anInt
index argument,self
times.
5.times { println("Hi") }
/* Prints → */
// → Hi
// → Hi
// → Hi
// → Hi
// → Hi
upTo (limit: Int, call: (Int) -> ())
Iterates
call
, passing in integer values fromself
up to and includinglimit
.
5.upTo(7, { println($0) })
/* Prints → */
// → 5
// → 6
// → 7
downTo (limit: Int, call: (Int) -> ())
Iterates
call
, passing in integer values fromself
down to and includinglimit
.
7.downTo(5, { println($0) })
/* Prints → */
// → 7
// → 6
// → 5
##Math
isEven () -> Bool
Returns
true
ifself
is even.
4.isEven()
// → true
isOdd () -> Bool
Returns
true
ifself
is odd.
3.isOdd()
// → true
clamp (range: Range<Int>) -> Int
clamp (min: Int, max: Int) -> Int
Computes the value of self clamped to a range defined by
range
(ormin...max
).
5.clamp(0...4)
// → 4
1.clamp(2...4)
// → 2