automerge-classic icon indicating copy to clipboard operation
automerge-classic copied to clipboard

Lack of a set type, best to use map?

Open jeffa5 opened this issue 3 years ago • 2 comments

There isn't a set type in automerge at the moment. I suppose we can implement this by using a map with null values. Is this the intended method or is there a plan to add a set type?

jeffa5 avatar Apr 26 '21 14:04 jeffa5

Yes, if you have a set of strings (or values that can be converted into strings), using a map with null values should work. If you have an unordered collection of objects, you could use the Automerge.Table datatype.

It might be worth adding an explicit set datatype further down the line; so far we haven't really had a strong need for it, but I'd be curious to hear more about your use case. A set containing primitive values should be fairly straightforward. A set of objects would be harder, since Automerge objects are mutable, and so it's not clear how one would enforce the property that a set should not contain the same element more than once. Automerge.Table is essentially a multiset in which each occurrence of an element is identified by a primary key.

ept avatar Apr 30 '21 12:04 ept

My use case for this is a tagging system where users can attach a set of strings to an object to help with filtering those objects. Using a Map with null values seems to work fine at the moment.

raffomania avatar Jul 22 '22 09:07 raffomania