Created
July 12, 2017 04:09
-
-
Save tranhieutt/7933a19db16507eebcbf441b8a9b847e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func herd<Animal: Cat> (_ cats: [Animal]) { | |
cats.forEach { | |
print("Here,cat, \($0.name)! come here") | |
} | |
} | |
func herd<Animal: Dog> (_ dogs: [Animal]) { | |
dogs.forEach { | |
print("Here, dog, \($0.name)! come here") | |
} | |
} | |
// extension array | |
extension Array where Element: Cat { | |
func meow() { | |
forEach { | |
print(" \($0.name) says meows") | |
} | |
} | |
} | |
func herd<Animal: Pet> (_ animal: [Animal]) { | |
animal.forEach { | |
print("Animal here \($0.name)") | |
} | |
} | |
func herd<T:Cat, U:Dog>(_ cats:[T], _ dogs: [U]) { | |
cats.forEach { | |
print("Here cats: \($0.name)") | |
} | |
dogs.forEach { | |
print("Here dogs: \($0.name)") | |
} | |
} | |
herd(cats, dogs) | |
cats.meow() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment