import { commit , modify } from '@collectable/core' ; import { HashMap , has , remove , size } from '@collectable/map' ; import { HashSetStructure , isIterable } from '../internals' ; export function subtract < T > ( other , main ) { var outputSet = modify ( main ) ; var outputMap = outputSet . _map ; if ( Array . isArray ( other ) ) { subtractArray ( main . _map , other , outputMap ) ; } else if ( other && typeof other === 'object' ) { if ( isIterable < T > ( other ) ) { subtractIterable < T > ( main . _map , other [ Symbol . iterator ] ( ) , outputMap ) ; } } commit ( outputSet ) ; if ( size ( outputMap ) === size ( main . _map ) ) { return main ; } outputSet . _map = outputMap ; return outputSet ; } function subtractArray < T > ( inputMap , omissions , outputMap ) { for ( var i = 0 ; i < omissions . length ; i ++ ) { if ( has ( omissions [ i ] , inputMap ) ) { remove ( omissions [ i ] , outputMap ) ; } } } function subtractIterable < T > ( inputMap , omissions , outputMap ) { var current ; while ( ! ( current = omissions . next ( ) ) . done ) { if ( has ( current . value , inputMap ) ) { remove ( current . value , outputMap ) ; } } }