<commit_before>//
//  Channel.swift
//  PhoenixWebSocket
//
//  Created by <NAME> on 2/4/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

public class Channel {
    let topic: String
    
    public var onConnect: (Message -> ())?
    public var onDisconnect: (ErrorType? -> ())?
    
    private var bindings = [Binding]()
    
    public init(topic: String) {
        self.topic = topic
    }
    
    public func on(event: String, callback: Message -> ()) -> Self {
        bindings.append(Binding(event: event, callback: callback))
        return self
    }
    
    struct Binding {
        let event: String
        let callback: Message -> ()
    }
}

extension Channel: Equatable { }

@warn_unused_result
public func ==(lhs: Channel, rhs: Channel) -> Bool {
    return lhs.topic == rhs.topic
}

extension Channel: Hashable {
    public var hashValue: Int { return topic.hashValue }
}<commit_msg>send trigger to channel bindings<commit_after>//
//  Channel.swift
//  PhoenixWebSocket
//
//  Created by <NAME> on 2/4/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

public class Channel {
    let topic: String
    
    public var onConnect: (Message -> ())?
    public var onDisconnect: (ErrorType? -> ())?
    
    private var bindings = [Binding]()
    
    public init(topic: String) {
        self.topic = topic
    }
    
    public func on(event: String, callback: Message -> ()) -> Self {
        bindings.append(Binding(event: event, callback: callback))
        return self
    }
    
    func recieved(message: Message) {
        bindings.filter { $0.event == message.event }
            .forEach { $0.callback(message) }
    }
    
    struct Binding {
        let event: String
        let callback: Message -> ()
    }
}

extension Channel: Equatable { }

@warn_unused_result
public func ==(lhs: Channel, rhs: Channel) -> Bool {
    return lhs.topic == rhs.topic
}

extension Channel: Hashable {
    public var hashValue: Int { return topic.hashValue }
}
{'fraction_non_alphanumeric': 0.12315270935960591, 'fraction_numerical': 0.008866995073891626, 'mean_word_length': 2.385, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '5806133', 'n_tokens_mistral': 626, 'n_tokens_neox': 605, 'n_words': 180}