package main

import "fmt"

type wordLength struct {
	word   string
	length int
}

func concurrentLengths(words []string) map[string]int {
	results := make(chan wordLength, len(words))

	for _, word := range words {
		word := word
		go func() {
			results <- wordLength{word: word, length: len(word)}
		}()
	}

	lengths := make(map[string]int, len(words))
	for range words {
		result := <-results
		lengths[result.word] = result.length
	}
	return lengths
}

func main() {
	lengths := concurrentLengths([]string{"go", "channel", "mutex"})
	fmt.Println(lengths["go"], lengths["channel"], lengths["mutex"])
}
