Question: I am trying to compare averages to each other via Haskell. I've got a list of lists of doubles and a list of doubles. What I want is to compare the average of each list of doubles (from the list of lists of doubles) to the average of the other list of doubles. When the average is higher, I want to return that list of Doubles.

I don't know how to do this in Haskell. Does anybody know how to get me started? Do I need some sort of iteration or can I do this with map? Thanks!

Edit:
I have a function to calculate the average of an array:

```
calculateAverage :: [Double] -> Double
calculateAverage xs = sum xs / fromIntegral (length xs)

```

And this is what I've tried, I know it doesn't make much sense but I don't know how to combine if or where with map: 

```
listsGreaterThenAverage :: [[Double]] -> [Double] -> [[Double]]
listsGreaterThenAverage x y = map (if map calculateAverage x > calculateAverage y then x)

```

I will get a list of lists of doubles and compare the average of every list of doubles to the average of the second argument, a list of doubles. If the average of the list of doubles (from the list of lists of doubles) is greater then the average of the second list of doubles, it will add the list of doubles to the return value.

Answer: 
SwiftHTTP, like NSURLSession, is async by design. Meaning that you can not just return from the method. 

```
import SwiftHTTP

func splitSentenceIntoWordsUsingTextAnalysis (string: String, finished:((String) -> Void)) {
    var request = HTTPTask()
    var params = ["text": "这是中文测试"] //: Dictionary<String,AnyObject>
    //request.requestSerializer = JSONRequestSerializer()
    request.requestSerializer.headers["X-Mashape-Key"] = "My-API-Key"
    request.requestSerializer.headers["Content-Type"] = "application/x-www-form-urlencoded"
    request.responseSerializer = JSONResponseSerializer()
    request.POST("https://textanalysis.p.mashape.com/segmenter", parameters: params, success: {
        (response: HTTPResponse) in
        if let res: AnyObject = response.responseObject {
            // decode res as string.
            let resString = res as String
            finished(resString)
        }
        }, failure: {(error: NSError, response: HTTPResponse?) in
            println(" error \(error)")
    })
}

```

Then you would use it like this.

```
splitSentenceIntoWordsUsingTextAnalysis("textToSplit", {(str:String) in
    println(str)
    // do stuff with str here.
})

```

Also see this Github issue as well.

<https://github.com/daltoniam/SwiftHTTP/issues/30>
In this code i have made an HTTP request and gets JSON data from my sample php file:

```
        // Making the HTTP request

        var post:NSString = "data=\(data)"

        NSLog("PostData: %@",post)

        var url:NSURL = NSURL(string: "http://domain.com/jsontest.php")!

        var postData:NSData = post.dataUsingEncoding(NSASCIIStringEncoding)!

        var postLength:NSString = String( postData.length )

        var request:NSMutableURLRequest = NSMutableURLRequest(URL: url)
        request.HTTPMethod = "POST"
        request.HTTPBody = postData
        request.setValue(postLength, forHTTPHeaderField: "Content-Length")
        request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
        request.setValue("application/json", forHTTPHeaderField: "Accept")

        var reponseError: NSError?
        var response: NSURLResponse?

        var urlData: NSData? = NSURLConnection.sendSynchronousRequest(request, returningResponse:&response, error:&reponseError)

        if ( urlData != nil ) {
            let res = response as NSHTTPURLResponse!

            NSLog("Response code: %ld", res.statusCode)

            if (res.statusCode >= 200 && res.statusCode < 300)
            {
                var responseData:NSString  = NSString(data:urlData!, encoding:NSUTF8StringEncoding)!

                NSLog("Response ==> %@", responseData)

                var error: NSError?

                // Here i make the JSON dictionary

                let jsonData:NSDictionary = NSJSONSerialization.JSONObjectWithData(urlData!, options:NSJSONReadingOptions.MutableContainers , error: &error) as NSDictionary

                // Like this you can access the values of the JSON dictionary as string

                name.text = jsonData.valueForKey("name") as NSString
                last.text = jsonData.valueForKey("last") as NSString

            }
        }

```

Hope it helps :)