map versus mapM behavior

As I understand it, the function “executes” each element in the list which must be an “action” (IO monad). That’s true for IO, but in your code example you don’t use the IO monad, you use the list monad (the function you give to mapM returns a list ([x]), not an IO). mapM is defined … Read more

maps – deleting data

Deletion of map elements The built-in function delete removes the element with key k from a map m. delete(m, k) // remove element m[k] from map m For example, package main import “fmt” func main() { m := map[string]string{“key1”: “val1”, “key2”: “val2”} fmt.Println(m) delete(m, “key1”) fmt.Println(m) } Output: map[key1:val1 key2:val2] map[key2:val2]

Separate word lists for nouns, verbs, adjectives, etc

If you download just the database files from wordnet.princeton.edu/download/current-version you can extract the words by running these commands: egrep -o “^[0-9]{8}\s[0-9]{2}\s[a-z]\s[0-9]{2}\s[a-zA-Z_]*\s” data.adj | cut -d ‘ ‘ -f 5 > conv.data.adj egrep -o “^[0-9]{8}\s[0-9]{2}\s[a-z]\s[0-9]{2}\s[a-zA-Z_]*\s” data.adv | cut -d ‘ ‘ -f 5 > conv.data.adv egrep -o “^[0-9]{8}\s[0-9]{2}\s[a-z]\s[0-9]{2}\s[a-zA-Z_]*\s” data.noun | cut -d ‘ ‘ -f 5 … Read more

How to access a Dictionary passed via NSNotification, using Swift

As notification.userInfo type is AnyObject ayou must downcast it to appropriate dictionary type. After exact type of dictionary is known you don’t need to downcast values you get from it. But you may want to check if values are actually present in dictionary before using them: // First try to cast user info to expected … Read more

How to reverse a Map in Kotlin?

Since the Map consists of Entrys and it is not Iterable you can use Map#entries instead. It will be mapped to Map#entrySet to create a backed view of Set<Entry>, for example: val reversed = map.entries.associateBy({ it.value }) { it.key } OR use Iterable#associate, which will create additional Pairs. val reversed = map.entries.associate{(k,v)-> v to k} … Read more