Skip to content
IT Courses
Courses
Blog
Search
/
VI
Quiz: generics · Go từ cơ bản đến nâng cao
Curriculum
›
7. Generics và iterator
Quiz: generics
Mark as completed
← Previous
Next →
Comments
Question 1.
`any`
`comparable`
`cmp.Ordered`
`fmt.Stringer`
Question 2.
Phủ định: mọi kiểu trừ int
Mọi kiểu có kiểu nền (underlying type) là `int`
Số nguyên xấp xỉ
Con trỏ tới int
Question 3.
`func F[T any](x T) T`
`type Box[T any] struct{ v T }`
`func (b Box[T]) Get() T`
`func (b Box[T]) Map[U any]() Box[U]`
Question 4.
`return nil`
`var zero T; return zero`
`return T{}`
`return 0`
Question 5.
`func(yield func(V) bool)`
`chan V`
`func() (V, bool)`
`interface{ Next() V }`
Question 6.
Go tự dừng goroutine đang chạy iterator
Lần gọi `yield` hiện tại trả về `false`; iterator phải `return` ngay — gọi `yield` thêm lần nữa sẽ panic
`yield` trả về `true` và các phần tử còn lại bị bỏ qua tự động
Không được dùng `break` với range-over-func
Question 7.
Khi muốn duyệt `seq` nhanh hơn `for range`
Khi muốn chuyển `seq` thành slice
Khi cần lấy từng phần tử theo nhu cầu, ví dụ duyệt song song hai iterator (Zip); nhớ gọi `stop()` khi xong
Khi muốn chạy iterator trên nhiều goroutine song song
Question 8.
Select all correct answers.
`slices.Values(s)`
`maps.Keys(m)`
`slices.Collect(seq)`
`slices.Sorted(maps.Keys(m))`
Check
Go từ cơ bản đến nâng cao
Comments