Is there a way to specify a Daml Set value directly using the generated TypeScript and Java code?

By “directly” I mean without first creating a Map<T, Unit> or similar.

So far I was only able to do this indirectly:


let attributesMap : damlTypes.Map<BookAttribute, {}> = damlTypes.emptyMap();

let pages: BookAttribute = {tag: "Pages", value: "104"};
attributesMap = attributesMap.set(pages, {});

let authors: BookAttribute = {tag: "Authors", value: ["Lewis Carroll", "John Tenniel"]};
attributesMap = attributesMap.set(authors, {});

let title: BookAttribute = {tag: "Title", value: "Alice's Adventures in Wonderland"};
attributesMap = attributesMap.set(title, {});

let published: BookAttribute = {tag: "Published", value: {year: "1865", publisher: "Macmillan"}};
attributesMap = attributesMap.set(published, {});

let attributes : Set<BookAttribute> = { map : attributesMap };


Pages pages = new Pages(104L);
Authors authors = new Authors(List.of("Lewis Carroll", "John Tenniel"));
Title title = new Title("Alice's Adventures in Wonderland");
Published published = new Published(1865L, "Macmillan");
Isbn isbn = new Isbn("9780440000754");
Map<BookAttribute, Unit> attribuesMap = Map.of(
        pages, Unit.getInstance(),
        authors, Unit.getInstance(),
        title, Unit.getInstance(),
        published, Unit.getInstance(),
        isbn, Unit.getInstance()
Set<BookAttribute> attributes = new Set<>(attribuesMap);

Am I missing something?

A Set is not a builtin-type, it’s a wrapper around a Map defined in the standard library. So you cannot avoid constructing a map first.

1 Like

Thank you!