<commit_before>import Foundation

extension MVitaLink
{
    //MARK: private
    
    //MARK: internal
    
    
}<commit_msg>Create generic fetch<commit_after>import Foundation

extension MVitaLink
{
    //MARK: private
    
    private func directoryAtEventPosition(
        database:Database,
        itemIndex:Int,
        sorters:[NSSortDescriptor],
        completion:@escaping((DVitaItemDirectory?) -> ()))
    {
        database.fetch(sorters:sorters)
        { (identifiers:[DVitaIdentifier]) in
            
            let totalIdentifiers:Int = identifiers.count
            
            guard
                
                totalIdentifiers > itemIndex
                
            else
            {
                completion(nil)
                
                return
            }
            
            let identifier:DVitaIdentifier = identifiers[itemIndex]
            let directory:DVitaItemDirectory? = identifier.items?.lastObject as? DVitaItemDirectory
            
            completion(directory)
        }
    }
    
    //MARK: internal
    
    func directoryAtEventPosition(
        event:MVitaPtpMessageInEvent,
        completion:@escaping((DVitaItemDirectory?) -> ()))
    {
        guard
        
            let database:Database = self.database,
            let unsignedItemIndex:UInt32 = event.parameters.first
        
        else
        {
            completion(nil)
            
            return
        }
        
        let itemIndex:Int = Int(unsignedItemIndex)
        let sorters:[NSSortDescriptor] = MVitaLink.factorySortersForIdentifier()
        
        directoryAtEventPosition(
            database:database,
            itemIndex:itemIndex,
            sorters:sorters,
            completion:completion)
    }
}
{'fraction_non_alphanumeric': 0.07098591549295774, 'fraction_numerical': 0.0011267605633802818, 'mean_word_length': 1.5155807365439093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5989422', 'n_tokens_mistral': 450, 'n_tokens_neox': 426, 'n_words': 71}