<commit_before>//
//  JsonTools.swift
//  iAsync_restkit
//
//  Created by <NAME> on 01.09.15.
//  Copyright (c) 2015 EmbeddedSources. All rights reserved.
//

import Foundation

import iAsync_async
import iAsync_utils
import iAsync_reactiveKit

import ReactiveKit

public struct JsonTools {

    public static func jsonLoader(data: NSData, context: CustomStringConvertible) -> AsyncTypes<AnyObject, NSError>.Async {

        return asyncStreamWithJob { (progress: AnyObject -> Void) -> Result<AnyObject, NSError> in

            do {
                let jsonObj = try NSJSONSerialization.JSONObjectWithData(data, options: [.AllowFragments])
                return .Success(jsonObj)
            } catch let error as NSError {
                let resError = ParseJsonDataError(data: data, jsonError: error, context: context)
                return .Failure(resError)
            } catch {
                return .Failure(Error(description: "unexpected system state 2"))
            }
        }.toAsync()
    }
}<commit_msg>refactor with using of reactiveKit<commit_after>//
//  JsonTools.swift
//  iAsync_restkit
//
//  Created by <NAME> on 01.09.15.
//  Copyright (c) 2015 EmbeddedSources. All rights reserved.
//

import Foundation

import iAsync_utils
import iAsync_reactiveKit

import ReactiveKit

public struct JsonTools {

    public static func jsonLoader(data: NSData, context: CustomStringConvertible) -> AsyncStream<AnyObject, AnyObject, NSError> {

        return asyncStreamWithJob { (progress: AnyObject -> Void) -> Result<AnyObject, NSError> in

            do {
                let jsonObj = try NSJSONSerialization.JSONObjectWithData(data, options: [.AllowFragments])
                return .Success(jsonObj)
            } catch let error as NSError {
                let resError = ParseJsonDataError(data: data, jsonError: error, context: context)
                return .Failure(resError)
            } catch {
                return .Failure(Error(description: "unexpected system state 2"))
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.09064184223419892, 'fraction_numerical': 0.010779029887310143, 'mean_word_length': 2.4965753424657535, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4415396', 'n_tokens_mistral': 602, 'n_tokens_neox': 554, 'n_words': 156}