<commit_before>//
//  OptionalConvertible.swift
//  SwiftySwift
//
//  Created by <NAME> on 5/18/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

// MARK: - OptionalConvertible

/// A type that can be represented as an `Optional`
public protocol OptionalConvertible {
    associatedtype SomeValue
    
    var optionalValue: SomeValue? { get }
}

extension Optional: OptionalConvertible {
    public var optionalValue: Wrapped? { return self }
}

// MARK: - SequenceType + OptionalConvertible

extension Sequence where Element : OptionalConvertible {
    /// return an `Array` containing the non-nil values in `self`
    @available(*, deprecated)
    public func flatMap() -> [Element.SomeValue] {
        return removingNilValues()
    }
    
    /// return an `Array` containing the non-nil values in `self`
    public func removingNilValues() -> [Iterator.Element.SomeValue] {
        var result: [Iterator.Element.SomeValue] = []
        for element in self {
            if let value = element.optionalValue {
                result.append(value)
            }
        }
        return result
    }
}<commit_msg>Deprecated `removingNilValues`, replaced with `compact` method<commit_after>//
//  OptionalConvertible.swift
//  SwiftySwift
//
//  Created by <NAME> on 5/18/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

// MARK: - OptionalConvertible

/// A type that can be represented as an `Optional`
public protocol OptionalConvertible {
    associatedtype SomeValue
    
    var optionalValue: SomeValue? { get }
}

extension Optional: OptionalConvertible {
    public var optionalValue: Wrapped? { return self }
}

// MARK: - SequenceType + OptionalConvertible

extension Sequence where Element : OptionalConvertible {
    /// return an `Array` containing the non-nil values in `self`
    /// DEPRECATED: use `compact`
    @available(*, deprecated)
    public func flatMap() -> [Element.SomeValue] {
        return removingNilValues()
    }
    
    /// return an `Array` containing the non-nil values in `self`
    /// DEPRECATED: use `compact`
    @available(*, deprecated)
    public func removingNilValues() -> [Element.SomeValue] {
        var result: [Element.SomeValue] = []
        for element in self {
            if let value = element.optionalValue {
                result.append(value)
            }
        }
        return result
    }
    
    public func compact() -> [Element.SomeValue] {
        return compactMap { $0.optionalValue }
    }
}
{'fraction_non_alphanumeric': 0.10722891566265061, 'fraction_numerical': 0.007630522088353414, 'mean_word_length': 2.538352272727273, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, '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': '653253', 'n_tokens_mistral': 709, 'n_tokens_neox': 672, 'n_words': 212}