<commit_before>//
//  Optionals.swift
//  Unilib
//
//  Created by <NAME> on 5/31/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

public protocol OptionalType {
    associatedtype Wrapped
    var optional:Wrapped? { get }
}

extension Optional : OptionalType {
    public var optional:Wrapped? { return self }
}
<commit_msg>Optional "as", and comment about aliasing map/flatMap.<commit_after>//
//  Optionals.swift
//  Unilib
//
//  Created by <NAME> on 5/31/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

public protocol OptionalType {
    associatedtype Wrapped
    var optional:Wrapped? { get }
}

extension Optional : OptionalType {
    public var optional:Wrapped? { return self }
}

public extension Optional {
    /// Cast an optional to a type or nil
    func `as`<T>(_:T.Type) -> T? {
        return flatMap { $0 as? T }
    }

    // NOTE: Before you're tempted to alias map/flatMap, consider that they
    // are probably the best names at the moment.
    // - map() is good because it maps an optional to something non-nil
    //   (i.e. the closure must return a non-nil value).
    // - flatMap() is not so good. It's still a mapping operation. However,
    //   it can return nil (i.e. in case the mapping is not possible).
    //   The prefix "flat" does not signify this, but I couldn't find
    //   a suitable alternative. So, since map/flatMap are well known terms
    //   of art, perhaps it's better to keep them as-is.
    //   (I tried "wrap" or "unwrap" but neither convey "mapping".)
    
}

{'fraction_non_alphanumeric': 0.1116751269035533, 'fraction_numerical': 0.012055837563451776, 'mean_word_length': 2.5518018018018016, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, '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': '3602569', 'n_tokens_mistral': 492, 'n_tokens_neox': 469, 'n_words': 190}