import { distinct, filter, identity, map } from "rxjs";
/** Saves all events to an event store and filters out invalid events */
export function mapEventsToStore(store, removeDuplicates = true) {
    return (source) => source.pipe(
    // Map all events to the store
    // NOTE: map is used here because we want to return the single cononical version of the event so that distinct() can be used later
    map((event) => store.add(event)), 
    // Ignore invalid events
    filter((e) => e !== null), 
    // Remove duplicates if requested
    removeDuplicates ? distinct() : identity);
}
