add: type switch

This commit is contained in:
Inanc Gumus
2019-08-25 08:57:53 +03:00
parent 39aed37a88
commit 0f07e4814e
27 changed files with 355 additions and 130 deletions

View File

@@ -0,0 +1,19 @@
package main
// usually: include the time method in the list.go
// it is here for clarity
// TODO: NEW
// you could include a time method in the book and game instead.
// but sometimes it is not possible to do so.
func (l list) time() (total int) {
for _, it := range l {
switch it := it.(type) {
case *game:
total += it.playTime
case book:
total += it.readTime
}
}
return total
}