What Scala type to use for a list of meeting participants

I want to store a number of participants for a meeting. The order of them is not important. The only thing I want to make sure is, that I will be able to add and remove participants, use filter functions (and alike) and get their number. Also duplicates are not allowed.
I started using List for the method signature, but now I wonder if I should accept a more abstract type. I saw types like Traversable, TraversableLike, Iterable and IterableLike.

The number of participants will be rather low, usually below 100. Changes will be made occasionally. The participants are immutable (but they have mutable properties e.g. a List of actions they performed for that meeting).

What would be the appropriate abstraction level for my case?

3

You mentioned in your comments that your requirements include that:

  • A) You must be able to add and remove elements from the collection.
  • B) The order of the elements is not important.
  • C) Duplicate entries are not allowed.

I would suggest using an immutable Set. It should have effectively constant time additions, removals, and lookups, and will automatically prevent the addition of duplicates. This is probably a better fit than a List, which in Scala requires linear time to update, append to, or lookup in, as it is singly linked and can only be accessed starting from the head.

The syntax for adding and removing from an immutable set is fairly nice as well.

val xs = Set(alice, bob)
val xs2 = xs + carl              // Set(alice, bob, carl)
val xs3 = xs2 -- Set(alice, bob) // Set(carl)

You also get all your typical set operations, like unions, intersects, etc.

As with anything, if you have a large enough set of data that performance really matters, benchmark your results.

Reference: Performance Characteristcs of Scala Collections

Scala has a lot of collection types that are pretty much only there to allow clever optimizations in the implementation (see Is the scala 2.8 collections library a case of the longest suicide note in history?). The ones you actually want to use only have an [A] and nothing else, and generally don’t have suffixes like “Like.”

If you want something more abstract than a List, try a Seq if you need to index by a number, an Iterable for when you need to create an iterator or take elements from the right, and a Traversable if you don’t.

However, generally you would use a concrete type for “internal” storage, where you would be adding and removing elements. In those cases, you select one based on its performance characteristics, for which a List is most likely just fine in your case. The more abstract types are more for accepting a collection from other code.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

What Scala type to use for a list of meeting participants

I want to store a number of participants for a meeting. The order of them is not important. The only thing I want to make sure is, that I will be able to add and remove participants, use filter functions (and alike) and get their number. Also duplicates are not allowed.
I started using List for the method signature, but now I wonder if I should accept a more abstract type. I saw types like Traversable, TraversableLike, Iterable and IterableLike.

The number of participants will be rather low, usually below 100. Changes will be made occasionally. The participants are immutable (but they have mutable properties e.g. a List of actions they performed for that meeting).

What would be the appropriate abstraction level for my case?

3

You mentioned in your comments that your requirements include that:

  • A) You must be able to add and remove elements from the collection.
  • B) The order of the elements is not important.
  • C) Duplicate entries are not allowed.

I would suggest using an immutable Set. It should have effectively constant time additions, removals, and lookups, and will automatically prevent the addition of duplicates. This is probably a better fit than a List, which in Scala requires linear time to update, append to, or lookup in, as it is singly linked and can only be accessed starting from the head.

The syntax for adding and removing from an immutable set is fairly nice as well.

val xs = Set(alice, bob)
val xs2 = xs + carl              // Set(alice, bob, carl)
val xs3 = xs2 -- Set(alice, bob) // Set(carl)

You also get all your typical set operations, like unions, intersects, etc.

As with anything, if you have a large enough set of data that performance really matters, benchmark your results.

Reference: Performance Characteristcs of Scala Collections

Scala has a lot of collection types that are pretty much only there to allow clever optimizations in the implementation (see Is the scala 2.8 collections library a case of the longest suicide note in history?). The ones you actually want to use only have an [A] and nothing else, and generally don’t have suffixes like “Like.”

If you want something more abstract than a List, try a Seq if you need to index by a number, an Iterable for when you need to create an iterator or take elements from the right, and a Traversable if you don’t.

However, generally you would use a concrete type for “internal” storage, where you would be adding and removing elements. In those cases, you select one based on its performance characteristics, for which a List is most likely just fine in your case. The more abstract types are more for accepting a collection from other code.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật