This is a small trick I use to compose complex accessibility labels/values when, for a UI component, some elements might not be in all its instances. An array of optional Strings, compact map, and join all elements by a separator, like a comma.

A tweet from Sebastiaan de With as an example. A tweet accessibility label is composed of many elements: Some tweets in home start with why you are seeing the tweet (Received new replies, someone liked it, based on your likes, someone retweeted, etc); the profile image is skipped; the user name is always part of the label; some users are verified; the user handle is not part of the label by default (but it can be enabled in Twitter's settings); the date is always there; and so is the text of the tweet; the tweets can have attachments (like a link, video or image with alt text); and a tweet can be a promoted one. Then we could compose the tweet value with the number of reactions (replies, likes and retweets), if any. We can create an array of optional strings where we'll be storing all these strings. Then we can do compactMap to remove nils, we could filter to check for empty strings and remove them too, and then we can join all these components by a separator character.