0

I'm calling an API using Akka-HTTP and Json4s, but the question could apply for any HTTP client/JSON parser. The API returns a short collection of items, should I use Seq or Set when parsing a response? Due to the small size of the collection, performance is not really a concern. From a logical/readability perspective Set makes more sense to me since the collections are unordered, and should have no duplicates. However, I usually see people use collections.

Just as an example, the object I would be deserializing is:

case class(name: String, tags: Seq[String], filters: Seq[Filter])  
EugeneMi
  • 3,475
  • 3
  • 38
  • 57

1 Answers1

0

The question could apply not only to any HTTP client / JSON parser, but to any situation when you are making choice to use certain data structure. The key here is access patterns to your data and what kind of operations are you going to perform on your data in future. In most cases you will probably iterate over all the collection performing some transformation or if we are talking about UI related application - render your data in form of list view. In these cases you do not need quick access to particular element (major advantage of Set). And since Seq in general consumes less memory and allows faster iteration over all the elements - people prefer to use Seq.