import { commit , modify } from '@collectable/core' ; import { HashMap , set as setValue , size } from '@collectable/map' ; import { HashSetStructure , isIterable } from '../internals' ; export function union < T > ( other , main ) { var outputSet = modify ( main ) ; var outputMap = outputSet . _map ; if ( Array . isArray ( other ) ) { unionArray ( main . _map , other , outputMap ) ; } else if ( other && typeof other === 'object' ) { if ( isIterable < T > ( other ) ) { unionIterable < T > ( main . _map , other [ Symbol . iterator ] ( ) , outputMap ) ; } } commit ( outputSet ) ; if ( size ( outputMap ) === size ( main . _map ) ) { return main ; } outputSet . _map = outputMap ; return outputSet ; } function unionArray < T > ( inputMap , array , outputMap ) { for ( var i = 0 ; i < array . length ; i ++ ) { setValue ( array [ i ] , null , outputMap ) ; } } function unionIterable < T > ( inputMap , it , outputMap ) { var current ; while ( ! ( current = it . next ( ) ) . done ) { setValue ( current . value , null , outputMap ) ; } }