This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object LetterCounter extends App{ | |
| val filters = args.lift(1).getOrElse("aeiou").toList | |
| val grouped = args(0).groupBy(l=>l).collect{case (l,g) => (l, g.length)} | |
| val groupCount = filters.map(v => grouped.find(x=> x._1==v).getOrElse((v,0))) | |
| val output = groupCount.foldLeft("")((result, pair) => result+pair._1 + ": "+pair._2+" ") | |
| println(output) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func Stitcher(hello_url string, worldURL string) string { | |
| return "" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Stitcher calls the Hello and World APIs to create a very useful string | |
| func Stitcher(helloURL string, worldURL string) string { | |
| return "" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "net/http" | |
| "net/http/httptest" | |
| "testing" | |
| ) | |
| func Test_it_calls_the_services_and_concatenates_the_results(t *testing.T) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "io/ioutil" | |
| "net/http" | |
| ) | |
| // Stitcher calls the Hello and World APIs to create a very useful string | |
| func Stitcher(helloURL string, worldURL string) string { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func Benchmark_the_stitcher(b *testing.B) { | |
| slowHelloAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
| time.Sleep(500 * time.Millisecond) | |
| fmt.Fprint(w, "Hello") | |
| })) | |
| slowWorldAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
| time.Sleep(500 * time.Millisecond) | |
| fmt.Fprint(w, "world") | |
| })) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Stitcher calls the Hello and World APIs to create a very useful string | |
| func Stitcher(helloURL string, worldURL string) string { | |
| helloChannel := make(chan []byte, 1) | |
| worldChannel := make(chan []byte, 1) | |
| go func() { | |
| helloResponse, _ := http.Get(helloURL) | |
| defer helloResponse.Body.Close() | |
| helloContent, _ := ioutil.ReadAll(helloResponse.Body) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const wordSeparator = ", " | |
| // Stitcher calls the Hello and World APIs to create a very useful string | |
| func Stitcher(helloURL string, worldURL string) string { | |
| helloChannel := make(chan []byte, 1) | |
| worldChannel := make(chan []byte, 1) | |
| go getStringFromAPI(helloChannel, helloURL) | |
| go getStringFromAPI(worldChannel, worldURL) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func Test_it_handles_non_ok_from_hello_api(t *testing.T) { | |
| helloAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
| http.Error(w, "oops", http.StatusInternalServerError) | |
| })) | |
| worldAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
| fmt.Fprint(w, "world") | |
| })) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const wordSeparator = ", " | |
| const errorMsg = "ALL OTHER SOFTWARE TEAMS ARE USELESS, OUTSOURCING IS A SHAM" | |
| type apiResult struct { | |
| content string | |
| err error | |
| } | |
| // Stitcher calls the Hello and World APIs to create a very useful string | |
| func Stitcher(helloURL string, worldURL string) string { |