<commit_before>/*
 |  _   ____   ____   _
 | | |‾|  ⚈ |-| ⚈  |‾| |
 | | |  ‾‾‾‾| |‾‾‾‾  | |
 |  ‾        ‾        ‾
 */

import Foundation
import Reactor
import CloudKit

public struct DiscoverCurrentUserIdentity<U: State>: Command {
    
    public init() { }
    
    public func execute(state: U, core: Core<U>) {
        core.fire(command: FetchCurrentUserID { recordID in
            guard let recordID = recordID else { return }
            CKContainer.default().discoverUserIdentity(withUserRecordID: recordID) { identity, error in
                if let error = error {
                    core.fire(event: CloudKitRecordFetchError(error: error))
                } else if let identity = identity {
                    core.fire(event: CloudKitCurrentUserIdentityRetrieved(identity: identity))
                } else {
                    core.fire(event: CloudKitRecordFetchError(error: CloudKitFetchError.unknown))
                }
            }
        })
    }
    
}<commit_msg>Use operation for discover current user<commit_after>/*
 |  _   ____   ____   _
 | | |‾|  ⚈ |-| ⚈  |‾| |
 | | |  ‾‾‾‾| |‾‾‾‾  | |
 |  ‾        ‾        ‾
 */

import Foundation
import Reactor
import CloudKit

public struct DiscoverCurrentUserIdentity<U: State>: Command {
    
    public init() { }
    
    public func execute(state: U, core: Core<U>) {
        core.fire(command: FetchCurrentUserID { recordID in
            guard let recordID = recordID else { return }
            let lookupInfo = CKUserIdentityLookupInfo(userRecordID: recordID)
            let operation = CKDiscoverUserIdentitiesOperation(userIdentityLookupInfos: [lookupInfo])
            operation.userIdentityDiscoveredBlock = { identity, lookupInfo in
                core.fire(event: CloudKitCurrentUserIdentityRetrieved(identity: identity))
            }
            operation.discoverUserIdentitiesCompletionBlock = { error in
                if let error = error {
                    core.fire(event: CloudKitRecordFetchError(error: error))
                }
            }
            operation.queuePriority = .veryHigh
            CKContainer.default().add(operation)
        })
    }
    
}
{'fraction_non_alphanumeric': 0.10285977859778597, 'fraction_numerical': 0.0, 'mean_word_length': 2.0125, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2753301', 'n_tokens_mistral': 673, 'n_tokens_neox': 620, 'n_words': 135}