//: Playground - noun: a place where people can play

import UIKit

// 

func prod(a : Int, b : Int) -> Int{
    return a * b
}

func prod(a : Double, b : Double) -> Double {
    return a * b
}

prod(a: 10, b: 12)
prod(a: 11.2, b: 12.3)

// 
class ItemHolder<T> {
    var items : [T]
    init(items : [T]) {
        self.items = items
    }
    
    func randomeItem() -> T {
        let index = Int(arc4random_uniform(UInt32(items.count)))
        return items[index]
    }
}


var intarray = [12, 15, 18, -14, 19]

var doublearray = [12.4, 12.7, 10.5, 11, -4.5]

var holder1 = ItemHolder(items : intarray)

print(holder1.randomeItem())

print(holder1.randomeItem())

//

var holder2 = ItemHolder<Double>(items: doublearray)
print(holder2.randomeItem())

// 
struct UserInfo {
    var firstname : String
    var lastname : String
    var age : Int
    
    init(_ firstname : String,_ lastname : String,_ age : Int) {
        self.firstname = firstname
        self.lastname = lastname
        self.age = age
    }
}

var users = [UserInfo("Mohammad", "Alizadeh", 24), UserInfo("Hamid", "Aslani", 17),
             UserInfo("Javad", "Ahmadi", 19)]

var holder = ItemHolder(items: users)

print(holder.randomeItem().firstname)


// function

func randomItemFrom<T> (_ items : [T]) -> T {
    let index = Int(arc4random_uniform(UInt32(items.count)))
    return items[index]
}

print("--------------------")
print(randomItemFrom(intarray))
print(randomItemFrom(doublearray))
print(randomItemFrom(users).lastname)




