List<YamlMetaType> (YamlMetaType... types) { if (types.length == 0) { throw new IllegalArgumentException("Nothing to compose"); } List<YamlMetaType> flattenedTypes = new SmartList<>(); Set<YamlMetaType> cerber = new ReferenceOpenHashSet<>(); for (YamlMetaType next : types) { if (!cerber.add(next)) { continue; } if (next instanceof YamlScalarType) { flattenedTypes.add(next); } else if (next instanceof YamlComposedTypeBase that) { flattenedTypes.addAll(that.myTypes); } else { flattenedTypes.add(next); } } return flattenedTypes; }