Map with concurrent access

Multiple readers, no writers is okay: https://groups.google.com/d/msg/golang-nuts/HpLWnGTp-n8/hyUYmnWJqiQJ One writer, no readers is okay. (Maps wouldn’t be much good otherwise.) Otherwise, if there is at least one writer and at least one more either writer or reader, then all readers and writers must use synchronization to access the map. A mutex works fine for this.

How to convert List to Map in Kotlin?

You have two choices: The first and most performant is to use associateBy function that takes two lambdas for generating the key and value, and inlines the creation of the map: val map = friends.associateBy({it.facebookId}, {it.points}) The second, less performant, is to use the standard map function to create a list of Pair which can … Read more

Iterating Through a Dictionary in Swift

Dictionaries in Swift (and other languages) are not ordered. When you iterate through the dictionary, there’s no guarantee that the order will match the initialization order. In this example, Swift processes the “Square” key before the others. You can see this by adding a print statement to the loop. 25 is the 5th element of … Read more

Swagger: map of

Using additionalPropertiesis the proper way to describe hashmap with OpenAPI (fka. Swagger) Specification but Swagger UI do not render them for now. The issue is tracked here https://github.com/swagger-api/swagger-ui/issues/1248 Meanwhile you can use this trick: define a non required property (defaultin the example below) of the same type of the map’s objects and give some hint … Read more