immutable.es.js 155 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931
  1. /**
  2. * MIT License
  3. *
  4. * Copyright (c) 2014-present, Lee Byron and other contributors.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. */
  24. var DELETE = 'delete';
  25. // Constants describing the size of trie nodes.
  26. var SHIFT = 5; // Resulted in best performance after ______?
  27. var SIZE = 1 << SHIFT;
  28. var MASK = SIZE - 1;
  29. // A consistent shared value representing "not set" which equals nothing other
  30. // than itself, and nothing that could be provided externally.
  31. var NOT_SET = {};
  32. // Boolean references, Rough equivalent of `bool &`.
  33. function MakeRef() {
  34. return { value: false };
  35. }
  36. function SetRef(ref) {
  37. if (ref) {
  38. ref.value = true;
  39. }
  40. }
  41. // A function which returns a value representing an "owner" for transient writes
  42. // to tries. The return value will only ever equal itself, and will not equal
  43. // the return of any subsequent call of this function.
  44. function OwnerID() {}
  45. function ensureSize(iter) {
  46. if (iter.size === undefined) {
  47. iter.size = iter.__iterate(returnTrue);
  48. }
  49. return iter.size;
  50. }
  51. function wrapIndex(iter, index) {
  52. // This implements "is array index" which the ECMAString spec defines as:
  53. //
  54. // A String property name P is an array index if and only if
  55. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  56. // to 2^32−1.
  57. //
  58. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  59. if (typeof index !== 'number') {
  60. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  61. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  62. return NaN;
  63. }
  64. index = uint32Index;
  65. }
  66. return index < 0 ? ensureSize(iter) + index : index;
  67. }
  68. function returnTrue() {
  69. return true;
  70. }
  71. function wholeSlice(begin, end, size) {
  72. return (
  73. ((begin === 0 && !isNeg(begin)) ||
  74. (size !== undefined && begin <= -size)) &&
  75. (end === undefined || (size !== undefined && end >= size))
  76. );
  77. }
  78. function resolveBegin(begin, size) {
  79. return resolveIndex(begin, size, 0);
  80. }
  81. function resolveEnd(end, size) {
  82. return resolveIndex(end, size, size);
  83. }
  84. function resolveIndex(index, size, defaultIndex) {
  85. // Sanitize indices using this shorthand for ToInt32(argument)
  86. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  87. return index === undefined
  88. ? defaultIndex
  89. : isNeg(index)
  90. ? size === Infinity
  91. ? size
  92. : Math.max(0, size + index) | 0
  93. : size === undefined || size === index
  94. ? index
  95. : Math.min(size, index) | 0;
  96. }
  97. function isNeg(value) {
  98. // Account for -0 which is negative, but not less than 0.
  99. return value < 0 || (value === 0 && 1 / value === -Infinity);
  100. }
  101. var IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
  102. function isCollection(maybeCollection) {
  103. return Boolean(maybeCollection && maybeCollection[IS_COLLECTION_SYMBOL]);
  104. }
  105. var IS_KEYED_SYMBOL = '@@__IMMUTABLE_KEYED__@@';
  106. function isKeyed(maybeKeyed) {
  107. return Boolean(maybeKeyed && maybeKeyed[IS_KEYED_SYMBOL]);
  108. }
  109. var IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';
  110. function isIndexed(maybeIndexed) {
  111. return Boolean(maybeIndexed && maybeIndexed[IS_INDEXED_SYMBOL]);
  112. }
  113. function isAssociative(maybeAssociative) {
  114. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  115. }
  116. var Collection = function Collection(value) {
  117. return isCollection(value) ? value : Seq(value);
  118. };
  119. var KeyedCollection = /*@__PURE__*/(function (Collection) {
  120. function KeyedCollection(value) {
  121. return isKeyed(value) ? value : KeyedSeq(value);
  122. }
  123. if ( Collection ) KeyedCollection.__proto__ = Collection;
  124. KeyedCollection.prototype = Object.create( Collection && Collection.prototype );
  125. KeyedCollection.prototype.constructor = KeyedCollection;
  126. return KeyedCollection;
  127. }(Collection));
  128. var IndexedCollection = /*@__PURE__*/(function (Collection) {
  129. function IndexedCollection(value) {
  130. return isIndexed(value) ? value : IndexedSeq(value);
  131. }
  132. if ( Collection ) IndexedCollection.__proto__ = Collection;
  133. IndexedCollection.prototype = Object.create( Collection && Collection.prototype );
  134. IndexedCollection.prototype.constructor = IndexedCollection;
  135. return IndexedCollection;
  136. }(Collection));
  137. var SetCollection = /*@__PURE__*/(function (Collection) {
  138. function SetCollection(value) {
  139. return isCollection(value) && !isAssociative(value) ? value : SetSeq(value);
  140. }
  141. if ( Collection ) SetCollection.__proto__ = Collection;
  142. SetCollection.prototype = Object.create( Collection && Collection.prototype );
  143. SetCollection.prototype.constructor = SetCollection;
  144. return SetCollection;
  145. }(Collection));
  146. Collection.Keyed = KeyedCollection;
  147. Collection.Indexed = IndexedCollection;
  148. Collection.Set = SetCollection;
  149. var IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
  150. function isSeq(maybeSeq) {
  151. return Boolean(maybeSeq && maybeSeq[IS_SEQ_SYMBOL]);
  152. }
  153. var IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
  154. function isRecord(maybeRecord) {
  155. return Boolean(maybeRecord && maybeRecord[IS_RECORD_SYMBOL]);
  156. }
  157. function isImmutable(maybeImmutable) {
  158. return isCollection(maybeImmutable) || isRecord(maybeImmutable);
  159. }
  160. var IS_ORDERED_SYMBOL = '@@__IMMUTABLE_ORDERED__@@';
  161. function isOrdered(maybeOrdered) {
  162. return Boolean(maybeOrdered && maybeOrdered[IS_ORDERED_SYMBOL]);
  163. }
  164. var ITERATE_KEYS = 0;
  165. var ITERATE_VALUES = 1;
  166. var ITERATE_ENTRIES = 2;
  167. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  168. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  169. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  170. var Iterator = function Iterator(next) {
  171. this.next = next;
  172. };
  173. Iterator.prototype.toString = function toString () {
  174. return '[Iterator]';
  175. };
  176. Iterator.KEYS = ITERATE_KEYS;
  177. Iterator.VALUES = ITERATE_VALUES;
  178. Iterator.ENTRIES = ITERATE_ENTRIES;
  179. Iterator.prototype.inspect = Iterator.prototype.toSource = function () {
  180. return this.toString();
  181. };
  182. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  183. return this;
  184. };
  185. function iteratorValue(type, k, v, iteratorResult) {
  186. var value = type === 0 ? k : type === 1 ? v : [k, v];
  187. iteratorResult
  188. ? (iteratorResult.value = value)
  189. : (iteratorResult = {
  190. value: value,
  191. done: false,
  192. });
  193. return iteratorResult;
  194. }
  195. function iteratorDone() {
  196. return { value: undefined, done: true };
  197. }
  198. function hasIterator(maybeIterable) {
  199. if (Array.isArray(maybeIterable)) {
  200. // IE11 trick as it does not support `Symbol.iterator`
  201. return true;
  202. }
  203. return !!getIteratorFn(maybeIterable);
  204. }
  205. function isIterator(maybeIterator) {
  206. return maybeIterator && typeof maybeIterator.next === 'function';
  207. }
  208. function getIterator(iterable) {
  209. var iteratorFn = getIteratorFn(iterable);
  210. return iteratorFn && iteratorFn.call(iterable);
  211. }
  212. function getIteratorFn(iterable) {
  213. var iteratorFn =
  214. iterable &&
  215. ((REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  216. iterable[FAUX_ITERATOR_SYMBOL]);
  217. if (typeof iteratorFn === 'function') {
  218. return iteratorFn;
  219. }
  220. }
  221. function isEntriesIterable(maybeIterable) {
  222. var iteratorFn = getIteratorFn(maybeIterable);
  223. return iteratorFn && iteratorFn === maybeIterable.entries;
  224. }
  225. function isKeysIterable(maybeIterable) {
  226. var iteratorFn = getIteratorFn(maybeIterable);
  227. return iteratorFn && iteratorFn === maybeIterable.keys;
  228. }
  229. var hasOwnProperty = Object.prototype.hasOwnProperty;
  230. function isArrayLike(value) {
  231. if (Array.isArray(value) || typeof value === 'string') {
  232. return true;
  233. }
  234. return (
  235. value &&
  236. typeof value === 'object' &&
  237. Number.isInteger(value.length) &&
  238. value.length >= 0 &&
  239. (value.length === 0
  240. ? // Only {length: 0} is considered Array-like.
  241. Object.keys(value).length === 1
  242. : // An object is only Array-like if it has a property where the last value
  243. // in the array-like may be found (which could be undefined).
  244. value.hasOwnProperty(value.length - 1))
  245. );
  246. }
  247. var Seq = /*@__PURE__*/(function (Collection) {
  248. function Seq(value) {
  249. return value === undefined || value === null
  250. ? emptySequence()
  251. : isImmutable(value)
  252. ? value.toSeq()
  253. : seqFromValue(value);
  254. }
  255. if ( Collection ) Seq.__proto__ = Collection;
  256. Seq.prototype = Object.create( Collection && Collection.prototype );
  257. Seq.prototype.constructor = Seq;
  258. Seq.prototype.toSeq = function toSeq () {
  259. return this;
  260. };
  261. Seq.prototype.toString = function toString () {
  262. return this.__toString('Seq {', '}');
  263. };
  264. Seq.prototype.cacheResult = function cacheResult () {
  265. if (!this._cache && this.__iterateUncached) {
  266. this._cache = this.entrySeq().toArray();
  267. this.size = this._cache.length;
  268. }
  269. return this;
  270. };
  271. // abstract __iterateUncached(fn, reverse)
  272. Seq.prototype.__iterate = function __iterate (fn, reverse) {
  273. var cache = this._cache;
  274. if (cache) {
  275. var size = cache.length;
  276. var i = 0;
  277. while (i !== size) {
  278. var entry = cache[reverse ? size - ++i : i++];
  279. if (fn(entry[1], entry[0], this) === false) {
  280. break;
  281. }
  282. }
  283. return i;
  284. }
  285. return this.__iterateUncached(fn, reverse);
  286. };
  287. // abstract __iteratorUncached(type, reverse)
  288. Seq.prototype.__iterator = function __iterator (type, reverse) {
  289. var cache = this._cache;
  290. if (cache) {
  291. var size = cache.length;
  292. var i = 0;
  293. return new Iterator(function () {
  294. if (i === size) {
  295. return iteratorDone();
  296. }
  297. var entry = cache[reverse ? size - ++i : i++];
  298. return iteratorValue(type, entry[0], entry[1]);
  299. });
  300. }
  301. return this.__iteratorUncached(type, reverse);
  302. };
  303. return Seq;
  304. }(Collection));
  305. var KeyedSeq = /*@__PURE__*/(function (Seq) {
  306. function KeyedSeq(value) {
  307. return value === undefined || value === null
  308. ? emptySequence().toKeyedSeq()
  309. : isCollection(value)
  310. ? isKeyed(value)
  311. ? value.toSeq()
  312. : value.fromEntrySeq()
  313. : isRecord(value)
  314. ? value.toSeq()
  315. : keyedSeqFromValue(value);
  316. }
  317. if ( Seq ) KeyedSeq.__proto__ = Seq;
  318. KeyedSeq.prototype = Object.create( Seq && Seq.prototype );
  319. KeyedSeq.prototype.constructor = KeyedSeq;
  320. KeyedSeq.prototype.toKeyedSeq = function toKeyedSeq () {
  321. return this;
  322. };
  323. return KeyedSeq;
  324. }(Seq));
  325. var IndexedSeq = /*@__PURE__*/(function (Seq) {
  326. function IndexedSeq(value) {
  327. return value === undefined || value === null
  328. ? emptySequence()
  329. : isCollection(value)
  330. ? isKeyed(value)
  331. ? value.entrySeq()
  332. : value.toIndexedSeq()
  333. : isRecord(value)
  334. ? value.toSeq().entrySeq()
  335. : indexedSeqFromValue(value);
  336. }
  337. if ( Seq ) IndexedSeq.__proto__ = Seq;
  338. IndexedSeq.prototype = Object.create( Seq && Seq.prototype );
  339. IndexedSeq.prototype.constructor = IndexedSeq;
  340. IndexedSeq.of = function of (/*...values*/) {
  341. return IndexedSeq(arguments);
  342. };
  343. IndexedSeq.prototype.toIndexedSeq = function toIndexedSeq () {
  344. return this;
  345. };
  346. IndexedSeq.prototype.toString = function toString () {
  347. return this.__toString('Seq [', ']');
  348. };
  349. return IndexedSeq;
  350. }(Seq));
  351. var SetSeq = /*@__PURE__*/(function (Seq) {
  352. function SetSeq(value) {
  353. return (
  354. isCollection(value) && !isAssociative(value) ? value : IndexedSeq(value)
  355. ).toSetSeq();
  356. }
  357. if ( Seq ) SetSeq.__proto__ = Seq;
  358. SetSeq.prototype = Object.create( Seq && Seq.prototype );
  359. SetSeq.prototype.constructor = SetSeq;
  360. SetSeq.of = function of (/*...values*/) {
  361. return SetSeq(arguments);
  362. };
  363. SetSeq.prototype.toSetSeq = function toSetSeq () {
  364. return this;
  365. };
  366. return SetSeq;
  367. }(Seq));
  368. Seq.isSeq = isSeq;
  369. Seq.Keyed = KeyedSeq;
  370. Seq.Set = SetSeq;
  371. Seq.Indexed = IndexedSeq;
  372. Seq.prototype[IS_SEQ_SYMBOL] = true;
  373. // #pragma Root Sequences
  374. var ArraySeq = /*@__PURE__*/(function (IndexedSeq) {
  375. function ArraySeq(array) {
  376. this._array = array;
  377. this.size = array.length;
  378. }
  379. if ( IndexedSeq ) ArraySeq.__proto__ = IndexedSeq;
  380. ArraySeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  381. ArraySeq.prototype.constructor = ArraySeq;
  382. ArraySeq.prototype.get = function get (index, notSetValue) {
  383. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  384. };
  385. ArraySeq.prototype.__iterate = function __iterate (fn, reverse) {
  386. var array = this._array;
  387. var size = array.length;
  388. var i = 0;
  389. while (i !== size) {
  390. var ii = reverse ? size - ++i : i++;
  391. if (fn(array[ii], ii, this) === false) {
  392. break;
  393. }
  394. }
  395. return i;
  396. };
  397. ArraySeq.prototype.__iterator = function __iterator (type, reverse) {
  398. var array = this._array;
  399. var size = array.length;
  400. var i = 0;
  401. return new Iterator(function () {
  402. if (i === size) {
  403. return iteratorDone();
  404. }
  405. var ii = reverse ? size - ++i : i++;
  406. return iteratorValue(type, ii, array[ii]);
  407. });
  408. };
  409. return ArraySeq;
  410. }(IndexedSeq));
  411. var ObjectSeq = /*@__PURE__*/(function (KeyedSeq) {
  412. function ObjectSeq(object) {
  413. var keys = Object.keys(object).concat(
  414. Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : []
  415. );
  416. this._object = object;
  417. this._keys = keys;
  418. this.size = keys.length;
  419. }
  420. if ( KeyedSeq ) ObjectSeq.__proto__ = KeyedSeq;
  421. ObjectSeq.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
  422. ObjectSeq.prototype.constructor = ObjectSeq;
  423. ObjectSeq.prototype.get = function get (key, notSetValue) {
  424. if (notSetValue !== undefined && !this.has(key)) {
  425. return notSetValue;
  426. }
  427. return this._object[key];
  428. };
  429. ObjectSeq.prototype.has = function has (key) {
  430. return hasOwnProperty.call(this._object, key);
  431. };
  432. ObjectSeq.prototype.__iterate = function __iterate (fn, reverse) {
  433. var object = this._object;
  434. var keys = this._keys;
  435. var size = keys.length;
  436. var i = 0;
  437. while (i !== size) {
  438. var key = keys[reverse ? size - ++i : i++];
  439. if (fn(object[key], key, this) === false) {
  440. break;
  441. }
  442. }
  443. return i;
  444. };
  445. ObjectSeq.prototype.__iterator = function __iterator (type, reverse) {
  446. var object = this._object;
  447. var keys = this._keys;
  448. var size = keys.length;
  449. var i = 0;
  450. return new Iterator(function () {
  451. if (i === size) {
  452. return iteratorDone();
  453. }
  454. var key = keys[reverse ? size - ++i : i++];
  455. return iteratorValue(type, key, object[key]);
  456. });
  457. };
  458. return ObjectSeq;
  459. }(KeyedSeq));
  460. ObjectSeq.prototype[IS_ORDERED_SYMBOL] = true;
  461. var CollectionSeq = /*@__PURE__*/(function (IndexedSeq) {
  462. function CollectionSeq(collection) {
  463. this._collection = collection;
  464. this.size = collection.length || collection.size;
  465. }
  466. if ( IndexedSeq ) CollectionSeq.__proto__ = IndexedSeq;
  467. CollectionSeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  468. CollectionSeq.prototype.constructor = CollectionSeq;
  469. CollectionSeq.prototype.__iterateUncached = function __iterateUncached (fn, reverse) {
  470. if (reverse) {
  471. return this.cacheResult().__iterate(fn, reverse);
  472. }
  473. var collection = this._collection;
  474. var iterator = getIterator(collection);
  475. var iterations = 0;
  476. if (isIterator(iterator)) {
  477. var step;
  478. while (!(step = iterator.next()).done) {
  479. if (fn(step.value, iterations++, this) === false) {
  480. break;
  481. }
  482. }
  483. }
  484. return iterations;
  485. };
  486. CollectionSeq.prototype.__iteratorUncached = function __iteratorUncached (type, reverse) {
  487. if (reverse) {
  488. return this.cacheResult().__iterator(type, reverse);
  489. }
  490. var collection = this._collection;
  491. var iterator = getIterator(collection);
  492. if (!isIterator(iterator)) {
  493. return new Iterator(iteratorDone);
  494. }
  495. var iterations = 0;
  496. return new Iterator(function () {
  497. var step = iterator.next();
  498. return step.done ? step : iteratorValue(type, iterations++, step.value);
  499. });
  500. };
  501. return CollectionSeq;
  502. }(IndexedSeq));
  503. // # pragma Helper functions
  504. var EMPTY_SEQ;
  505. function emptySequence() {
  506. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  507. }
  508. function keyedSeqFromValue(value) {
  509. var seq = maybeIndexedSeqFromValue(value);
  510. if (seq) {
  511. return seq.fromEntrySeq();
  512. }
  513. if (typeof value === 'object') {
  514. return new ObjectSeq(value);
  515. }
  516. throw new TypeError(
  517. 'Expected Array or collection object of [k, v] entries, or keyed object: ' +
  518. value
  519. );
  520. }
  521. function indexedSeqFromValue(value) {
  522. var seq = maybeIndexedSeqFromValue(value);
  523. if (seq) {
  524. return seq;
  525. }
  526. throw new TypeError(
  527. 'Expected Array or collection object of values: ' + value
  528. );
  529. }
  530. function seqFromValue(value) {
  531. var seq = maybeIndexedSeqFromValue(value);
  532. if (seq) {
  533. return isEntriesIterable(value)
  534. ? seq.fromEntrySeq()
  535. : isKeysIterable(value)
  536. ? seq.toSetSeq()
  537. : seq;
  538. }
  539. if (typeof value === 'object') {
  540. return new ObjectSeq(value);
  541. }
  542. throw new TypeError(
  543. 'Expected Array or collection object of values, or keyed object: ' + value
  544. );
  545. }
  546. function maybeIndexedSeqFromValue(value) {
  547. return isArrayLike(value)
  548. ? new ArraySeq(value)
  549. : hasIterator(value)
  550. ? new CollectionSeq(value)
  551. : undefined;
  552. }
  553. var IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
  554. function isMap(maybeMap) {
  555. return Boolean(maybeMap && maybeMap[IS_MAP_SYMBOL]);
  556. }
  557. function isOrderedMap(maybeOrderedMap) {
  558. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  559. }
  560. function isValueObject(maybeValue) {
  561. return Boolean(
  562. maybeValue &&
  563. typeof maybeValue.equals === 'function' &&
  564. typeof maybeValue.hashCode === 'function'
  565. );
  566. }
  567. /**
  568. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  569. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  570. *
  571. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  572. * value, which is different from the algorithm described by
  573. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  574. *
  575. * This is extended further to allow Objects to describe the values they
  576. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  577. *
  578. * Note: because of this extension, the key equality of Immutable.Map and the
  579. * value equality of Immutable.Set will differ from ES6 Map and Set.
  580. *
  581. * ### Defining custom values
  582. *
  583. * The easiest way to describe the value an object represents is by implementing
  584. * `valueOf`. For example, `Date` represents a value by returning a unix
  585. * timestamp for `valueOf`:
  586. *
  587. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  588. * var date2 = new Date(1234567890000);
  589. * date1.valueOf(); // 1234567890000
  590. * assert( date1 !== date2 );
  591. * assert( Immutable.is( date1, date2 ) );
  592. *
  593. * Note: overriding `valueOf` may have other implications if you use this object
  594. * where JavaScript expects a primitive, such as implicit string coercion.
  595. *
  596. * For more complex types, especially collections, implementing `valueOf` may
  597. * not be performant. An alternative is to implement `equals` and `hashCode`.
  598. *
  599. * `equals` takes another object, presumably of similar type, and returns true
  600. * if it is equal. Equality is symmetrical, so the same result should be
  601. * returned if this and the argument are flipped.
  602. *
  603. * assert( a.equals(b) === b.equals(a) );
  604. *
  605. * `hashCode` returns a 32bit integer number representing the object which will
  606. * be used to determine how to store the value object in a Map or Set. You must
  607. * provide both or neither methods, one must not exist without the other.
  608. *
  609. * Also, an important relationship between these methods must be upheld: if two
  610. * values are equal, they *must* return the same hashCode. If the values are not
  611. * equal, they might have the same hashCode; this is called a hash collision,
  612. * and while undesirable for performance reasons, it is acceptable.
  613. *
  614. * if (a.equals(b)) {
  615. * assert( a.hashCode() === b.hashCode() );
  616. * }
  617. *
  618. * All Immutable collections are Value Objects: they implement `equals()`
  619. * and `hashCode()`.
  620. */
  621. function is(valueA, valueB) {
  622. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  623. return true;
  624. }
  625. if (!valueA || !valueB) {
  626. return false;
  627. }
  628. if (
  629. typeof valueA.valueOf === 'function' &&
  630. typeof valueB.valueOf === 'function'
  631. ) {
  632. valueA = valueA.valueOf();
  633. valueB = valueB.valueOf();
  634. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  635. return true;
  636. }
  637. if (!valueA || !valueB) {
  638. return false;
  639. }
  640. }
  641. return !!(
  642. isValueObject(valueA) &&
  643. isValueObject(valueB) &&
  644. valueA.equals(valueB)
  645. );
  646. }
  647. var imul =
  648. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2
  649. ? Math.imul
  650. : function imul(a, b) {
  651. a |= 0; // int
  652. b |= 0; // int
  653. var c = a & 0xffff;
  654. var d = b & 0xffff;
  655. // Shift by 0 fixes the sign on the high part.
  656. return (c * d + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0)) | 0; // int
  657. };
  658. // v8 has an optimization for storing 31-bit signed numbers.
  659. // Values which have either 00 or 11 as the high order bits qualify.
  660. // This function drops the highest order bit in a signed number, maintaining
  661. // the sign bit.
  662. function smi(i32) {
  663. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xbfffffff);
  664. }
  665. var defaultValueOf = Object.prototype.valueOf;
  666. function hash(o) {
  667. if (o == null) {
  668. return hashNullish(o);
  669. }
  670. if (typeof o.hashCode === 'function') {
  671. // Drop any high bits from accidentally long hash codes.
  672. return smi(o.hashCode(o));
  673. }
  674. var v = valueOf(o);
  675. if (v == null) {
  676. return hashNullish(v);
  677. }
  678. switch (typeof v) {
  679. case 'boolean':
  680. // The hash values for built-in constants are a 1 value for each 5-byte
  681. // shift region expect for the first, which encodes the value. This
  682. // reduces the odds of a hash collision for these common values.
  683. return v ? 0x42108421 : 0x42108420;
  684. case 'number':
  685. return hashNumber(v);
  686. case 'string':
  687. return v.length > STRING_HASH_CACHE_MIN_STRLEN
  688. ? cachedHashString(v)
  689. : hashString(v);
  690. case 'object':
  691. case 'function':
  692. return hashJSObj(v);
  693. case 'symbol':
  694. return hashSymbol(v);
  695. default:
  696. if (typeof v.toString === 'function') {
  697. return hashString(v.toString());
  698. }
  699. throw new Error('Value type ' + typeof v + ' cannot be hashed.');
  700. }
  701. }
  702. function hashNullish(nullish) {
  703. return nullish === null ? 0x42108422 : /* undefined */ 0x42108423;
  704. }
  705. // Compress arbitrarily large numbers into smi hashes.
  706. function hashNumber(n) {
  707. if (n !== n || n === Infinity) {
  708. return 0;
  709. }
  710. var hash = n | 0;
  711. if (hash !== n) {
  712. hash ^= n * 0xffffffff;
  713. }
  714. while (n > 0xffffffff) {
  715. n /= 0xffffffff;
  716. hash ^= n;
  717. }
  718. return smi(hash);
  719. }
  720. function cachedHashString(string) {
  721. var hashed = stringHashCache[string];
  722. if (hashed === undefined) {
  723. hashed = hashString(string);
  724. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  725. STRING_HASH_CACHE_SIZE = 0;
  726. stringHashCache = {};
  727. }
  728. STRING_HASH_CACHE_SIZE++;
  729. stringHashCache[string] = hashed;
  730. }
  731. return hashed;
  732. }
  733. // http://jsperf.com/hashing-strings
  734. function hashString(string) {
  735. // This is the hash from JVM
  736. // The hash code for a string is computed as
  737. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  738. // where s[i] is the ith character of the string and n is the length of
  739. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  740. // (exclusive) by dropping high bits.
  741. var hashed = 0;
  742. for (var ii = 0; ii < string.length; ii++) {
  743. hashed = (31 * hashed + string.charCodeAt(ii)) | 0;
  744. }
  745. return smi(hashed);
  746. }
  747. function hashSymbol(sym) {
  748. var hashed = symbolMap[sym];
  749. if (hashed !== undefined) {
  750. return hashed;
  751. }
  752. hashed = nextHash();
  753. symbolMap[sym] = hashed;
  754. return hashed;
  755. }
  756. function hashJSObj(obj) {
  757. var hashed;
  758. if (usingWeakMap) {
  759. hashed = weakMap.get(obj);
  760. if (hashed !== undefined) {
  761. return hashed;
  762. }
  763. }
  764. hashed = obj[UID_HASH_KEY];
  765. if (hashed !== undefined) {
  766. return hashed;
  767. }
  768. if (!canDefineProperty) {
  769. hashed = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  770. if (hashed !== undefined) {
  771. return hashed;
  772. }
  773. hashed = getIENodeHash(obj);
  774. if (hashed !== undefined) {
  775. return hashed;
  776. }
  777. }
  778. hashed = nextHash();
  779. if (usingWeakMap) {
  780. weakMap.set(obj, hashed);
  781. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  782. throw new Error('Non-extensible objects are not allowed as keys.');
  783. } else if (canDefineProperty) {
  784. Object.defineProperty(obj, UID_HASH_KEY, {
  785. enumerable: false,
  786. configurable: false,
  787. writable: false,
  788. value: hashed,
  789. });
  790. } else if (
  791. obj.propertyIsEnumerable !== undefined &&
  792. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable
  793. ) {
  794. // Since we can't define a non-enumerable property on the object
  795. // we'll hijack one of the less-used non-enumerable properties to
  796. // save our hash on it. Since this is a function it will not show up in
  797. // `JSON.stringify` which is what we want.
  798. obj.propertyIsEnumerable = function () {
  799. return this.constructor.prototype.propertyIsEnumerable.apply(
  800. this,
  801. arguments
  802. );
  803. };
  804. obj.propertyIsEnumerable[UID_HASH_KEY] = hashed;
  805. } else if (obj.nodeType !== undefined) {
  806. // At this point we couldn't get the IE `uniqueID` to use as a hash
  807. // and we couldn't use a non-enumerable property to exploit the
  808. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  809. // itself.
  810. obj[UID_HASH_KEY] = hashed;
  811. } else {
  812. throw new Error('Unable to set a non-enumerable property on object.');
  813. }
  814. return hashed;
  815. }
  816. // Get references to ES5 object methods.
  817. var isExtensible = Object.isExtensible;
  818. // True if Object.defineProperty works as expected. IE8 fails this test.
  819. var canDefineProperty = (function () {
  820. try {
  821. Object.defineProperty({}, '@', {});
  822. return true;
  823. } catch (e) {
  824. return false;
  825. }
  826. })();
  827. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  828. // and avoid memory leaks from the IE cloneNode bug.
  829. function getIENodeHash(node) {
  830. if (node && node.nodeType > 0) {
  831. switch (node.nodeType) {
  832. case 1: // Element
  833. return node.uniqueID;
  834. case 9: // Document
  835. return node.documentElement && node.documentElement.uniqueID;
  836. }
  837. }
  838. }
  839. function valueOf(obj) {
  840. return obj.valueOf !== defaultValueOf && typeof obj.valueOf === 'function'
  841. ? obj.valueOf(obj)
  842. : obj;
  843. }
  844. function nextHash() {
  845. var nextHash = ++_objHashUID;
  846. if (_objHashUID & 0x40000000) {
  847. _objHashUID = 0;
  848. }
  849. return nextHash;
  850. }
  851. // If possible, use a WeakMap.
  852. var usingWeakMap = typeof WeakMap === 'function';
  853. var weakMap;
  854. if (usingWeakMap) {
  855. weakMap = new WeakMap();
  856. }
  857. var symbolMap = Object.create(null);
  858. var _objHashUID = 0;
  859. var UID_HASH_KEY = '__immutablehash__';
  860. if (typeof Symbol === 'function') {
  861. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  862. }
  863. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  864. var STRING_HASH_CACHE_MAX_SIZE = 255;
  865. var STRING_HASH_CACHE_SIZE = 0;
  866. var stringHashCache = {};
  867. var ToKeyedSequence = /*@__PURE__*/(function (KeyedSeq) {
  868. function ToKeyedSequence(indexed, useKeys) {
  869. this._iter = indexed;
  870. this._useKeys = useKeys;
  871. this.size = indexed.size;
  872. }
  873. if ( KeyedSeq ) ToKeyedSequence.__proto__ = KeyedSeq;
  874. ToKeyedSequence.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
  875. ToKeyedSequence.prototype.constructor = ToKeyedSequence;
  876. ToKeyedSequence.prototype.get = function get (key, notSetValue) {
  877. return this._iter.get(key, notSetValue);
  878. };
  879. ToKeyedSequence.prototype.has = function has (key) {
  880. return this._iter.has(key);
  881. };
  882. ToKeyedSequence.prototype.valueSeq = function valueSeq () {
  883. return this._iter.valueSeq();
  884. };
  885. ToKeyedSequence.prototype.reverse = function reverse () {
  886. var this$1$1 = this;
  887. var reversedSequence = reverseFactory(this, true);
  888. if (!this._useKeys) {
  889. reversedSequence.valueSeq = function () { return this$1$1._iter.toSeq().reverse(); };
  890. }
  891. return reversedSequence;
  892. };
  893. ToKeyedSequence.prototype.map = function map (mapper, context) {
  894. var this$1$1 = this;
  895. var mappedSequence = mapFactory(this, mapper, context);
  896. if (!this._useKeys) {
  897. mappedSequence.valueSeq = function () { return this$1$1._iter.toSeq().map(mapper, context); };
  898. }
  899. return mappedSequence;
  900. };
  901. ToKeyedSequence.prototype.__iterate = function __iterate (fn, reverse) {
  902. var this$1$1 = this;
  903. return this._iter.__iterate(function (v, k) { return fn(v, k, this$1$1); }, reverse);
  904. };
  905. ToKeyedSequence.prototype.__iterator = function __iterator (type, reverse) {
  906. return this._iter.__iterator(type, reverse);
  907. };
  908. return ToKeyedSequence;
  909. }(KeyedSeq));
  910. ToKeyedSequence.prototype[IS_ORDERED_SYMBOL] = true;
  911. var ToIndexedSequence = /*@__PURE__*/(function (IndexedSeq) {
  912. function ToIndexedSequence(iter) {
  913. this._iter = iter;
  914. this.size = iter.size;
  915. }
  916. if ( IndexedSeq ) ToIndexedSequence.__proto__ = IndexedSeq;
  917. ToIndexedSequence.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  918. ToIndexedSequence.prototype.constructor = ToIndexedSequence;
  919. ToIndexedSequence.prototype.includes = function includes (value) {
  920. return this._iter.includes(value);
  921. };
  922. ToIndexedSequence.prototype.__iterate = function __iterate (fn, reverse) {
  923. var this$1$1 = this;
  924. var i = 0;
  925. reverse && ensureSize(this);
  926. return this._iter.__iterate(
  927. function (v) { return fn(v, reverse ? this$1$1.size - ++i : i++, this$1$1); },
  928. reverse
  929. );
  930. };
  931. ToIndexedSequence.prototype.__iterator = function __iterator (type, reverse) {
  932. var this$1$1 = this;
  933. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  934. var i = 0;
  935. reverse && ensureSize(this);
  936. return new Iterator(function () {
  937. var step = iterator.next();
  938. return step.done
  939. ? step
  940. : iteratorValue(
  941. type,
  942. reverse ? this$1$1.size - ++i : i++,
  943. step.value,
  944. step
  945. );
  946. });
  947. };
  948. return ToIndexedSequence;
  949. }(IndexedSeq));
  950. var ToSetSequence = /*@__PURE__*/(function (SetSeq) {
  951. function ToSetSequence(iter) {
  952. this._iter = iter;
  953. this.size = iter.size;
  954. }
  955. if ( SetSeq ) ToSetSequence.__proto__ = SetSeq;
  956. ToSetSequence.prototype = Object.create( SetSeq && SetSeq.prototype );
  957. ToSetSequence.prototype.constructor = ToSetSequence;
  958. ToSetSequence.prototype.has = function has (key) {
  959. return this._iter.includes(key);
  960. };
  961. ToSetSequence.prototype.__iterate = function __iterate (fn, reverse) {
  962. var this$1$1 = this;
  963. return this._iter.__iterate(function (v) { return fn(v, v, this$1$1); }, reverse);
  964. };
  965. ToSetSequence.prototype.__iterator = function __iterator (type, reverse) {
  966. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  967. return new Iterator(function () {
  968. var step = iterator.next();
  969. return step.done
  970. ? step
  971. : iteratorValue(type, step.value, step.value, step);
  972. });
  973. };
  974. return ToSetSequence;
  975. }(SetSeq));
  976. var FromEntriesSequence = /*@__PURE__*/(function (KeyedSeq) {
  977. function FromEntriesSequence(entries) {
  978. this._iter = entries;
  979. this.size = entries.size;
  980. }
  981. if ( KeyedSeq ) FromEntriesSequence.__proto__ = KeyedSeq;
  982. FromEntriesSequence.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
  983. FromEntriesSequence.prototype.constructor = FromEntriesSequence;
  984. FromEntriesSequence.prototype.entrySeq = function entrySeq () {
  985. return this._iter.toSeq();
  986. };
  987. FromEntriesSequence.prototype.__iterate = function __iterate (fn, reverse) {
  988. var this$1$1 = this;
  989. return this._iter.__iterate(function (entry) {
  990. // Check if entry exists first so array access doesn't throw for holes
  991. // in the parent iteration.
  992. if (entry) {
  993. validateEntry(entry);
  994. var indexedCollection = isCollection(entry);
  995. return fn(
  996. indexedCollection ? entry.get(1) : entry[1],
  997. indexedCollection ? entry.get(0) : entry[0],
  998. this$1$1
  999. );
  1000. }
  1001. }, reverse);
  1002. };
  1003. FromEntriesSequence.prototype.__iterator = function __iterator (type, reverse) {
  1004. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  1005. return new Iterator(function () {
  1006. while (true) {
  1007. var step = iterator.next();
  1008. if (step.done) {
  1009. return step;
  1010. }
  1011. var entry = step.value;
  1012. // Check if entry exists first so array access doesn't throw for holes
  1013. // in the parent iteration.
  1014. if (entry) {
  1015. validateEntry(entry);
  1016. var indexedCollection = isCollection(entry);
  1017. return iteratorValue(
  1018. type,
  1019. indexedCollection ? entry.get(0) : entry[0],
  1020. indexedCollection ? entry.get(1) : entry[1],
  1021. step
  1022. );
  1023. }
  1024. }
  1025. });
  1026. };
  1027. return FromEntriesSequence;
  1028. }(KeyedSeq));
  1029. ToIndexedSequence.prototype.cacheResult =
  1030. ToKeyedSequence.prototype.cacheResult =
  1031. ToSetSequence.prototype.cacheResult =
  1032. FromEntriesSequence.prototype.cacheResult =
  1033. cacheResultThrough;
  1034. function flipFactory(collection) {
  1035. var flipSequence = makeSequence(collection);
  1036. flipSequence._iter = collection;
  1037. flipSequence.size = collection.size;
  1038. flipSequence.flip = function () { return collection; };
  1039. flipSequence.reverse = function () {
  1040. var reversedSequence = collection.reverse.apply(this); // super.reverse()
  1041. reversedSequence.flip = function () { return collection.reverse(); };
  1042. return reversedSequence;
  1043. };
  1044. flipSequence.has = function (key) { return collection.includes(key); };
  1045. flipSequence.includes = function (key) { return collection.has(key); };
  1046. flipSequence.cacheResult = cacheResultThrough;
  1047. flipSequence.__iterateUncached = function (fn, reverse) {
  1048. var this$1$1 = this;
  1049. return collection.__iterate(function (v, k) { return fn(k, v, this$1$1) !== false; }, reverse);
  1050. };
  1051. flipSequence.__iteratorUncached = function (type, reverse) {
  1052. if (type === ITERATE_ENTRIES) {
  1053. var iterator = collection.__iterator(type, reverse);
  1054. return new Iterator(function () {
  1055. var step = iterator.next();
  1056. if (!step.done) {
  1057. var k = step.value[0];
  1058. step.value[0] = step.value[1];
  1059. step.value[1] = k;
  1060. }
  1061. return step;
  1062. });
  1063. }
  1064. return collection.__iterator(
  1065. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  1066. reverse
  1067. );
  1068. };
  1069. return flipSequence;
  1070. }
  1071. function mapFactory(collection, mapper, context) {
  1072. var mappedSequence = makeSequence(collection);
  1073. mappedSequence.size = collection.size;
  1074. mappedSequence.has = function (key) { return collection.has(key); };
  1075. mappedSequence.get = function (key, notSetValue) {
  1076. var v = collection.get(key, NOT_SET);
  1077. return v === NOT_SET
  1078. ? notSetValue
  1079. : mapper.call(context, v, key, collection);
  1080. };
  1081. mappedSequence.__iterateUncached = function (fn, reverse) {
  1082. var this$1$1 = this;
  1083. return collection.__iterate(
  1084. function (v, k, c) { return fn(mapper.call(context, v, k, c), k, this$1$1) !== false; },
  1085. reverse
  1086. );
  1087. };
  1088. mappedSequence.__iteratorUncached = function (type, reverse) {
  1089. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  1090. return new Iterator(function () {
  1091. var step = iterator.next();
  1092. if (step.done) {
  1093. return step;
  1094. }
  1095. var entry = step.value;
  1096. var key = entry[0];
  1097. return iteratorValue(
  1098. type,
  1099. key,
  1100. mapper.call(context, entry[1], key, collection),
  1101. step
  1102. );
  1103. });
  1104. };
  1105. return mappedSequence;
  1106. }
  1107. function reverseFactory(collection, useKeys) {
  1108. var this$1$1 = this;
  1109. var reversedSequence = makeSequence(collection);
  1110. reversedSequence._iter = collection;
  1111. reversedSequence.size = collection.size;
  1112. reversedSequence.reverse = function () { return collection; };
  1113. if (collection.flip) {
  1114. reversedSequence.flip = function () {
  1115. var flipSequence = flipFactory(collection);
  1116. flipSequence.reverse = function () { return collection.flip(); };
  1117. return flipSequence;
  1118. };
  1119. }
  1120. reversedSequence.get = function (key, notSetValue) { return collection.get(useKeys ? key : -1 - key, notSetValue); };
  1121. reversedSequence.has = function (key) { return collection.has(useKeys ? key : -1 - key); };
  1122. reversedSequence.includes = function (value) { return collection.includes(value); };
  1123. reversedSequence.cacheResult = cacheResultThrough;
  1124. reversedSequence.__iterate = function (fn, reverse) {
  1125. var this$1$1 = this;
  1126. var i = 0;
  1127. reverse && ensureSize(collection);
  1128. return collection.__iterate(
  1129. function (v, k) { return fn(v, useKeys ? k : reverse ? this$1$1.size - ++i : i++, this$1$1); },
  1130. !reverse
  1131. );
  1132. };
  1133. reversedSequence.__iterator = function (type, reverse) {
  1134. var i = 0;
  1135. reverse && ensureSize(collection);
  1136. var iterator = collection.__iterator(ITERATE_ENTRIES, !reverse);
  1137. return new Iterator(function () {
  1138. var step = iterator.next();
  1139. if (step.done) {
  1140. return step;
  1141. }
  1142. var entry = step.value;
  1143. return iteratorValue(
  1144. type,
  1145. useKeys ? entry[0] : reverse ? this$1$1.size - ++i : i++,
  1146. entry[1],
  1147. step
  1148. );
  1149. });
  1150. };
  1151. return reversedSequence;
  1152. }
  1153. function filterFactory(collection, predicate, context, useKeys) {
  1154. var filterSequence = makeSequence(collection);
  1155. if (useKeys) {
  1156. filterSequence.has = function (key) {
  1157. var v = collection.get(key, NOT_SET);
  1158. return v !== NOT_SET && !!predicate.call(context, v, key, collection);
  1159. };
  1160. filterSequence.get = function (key, notSetValue) {
  1161. var v = collection.get(key, NOT_SET);
  1162. return v !== NOT_SET && predicate.call(context, v, key, collection)
  1163. ? v
  1164. : notSetValue;
  1165. };
  1166. }
  1167. filterSequence.__iterateUncached = function (fn, reverse) {
  1168. var this$1$1 = this;
  1169. var iterations = 0;
  1170. collection.__iterate(function (v, k, c) {
  1171. if (predicate.call(context, v, k, c)) {
  1172. iterations++;
  1173. return fn(v, useKeys ? k : iterations - 1, this$1$1);
  1174. }
  1175. }, reverse);
  1176. return iterations;
  1177. };
  1178. filterSequence.__iteratorUncached = function (type, reverse) {
  1179. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  1180. var iterations = 0;
  1181. return new Iterator(function () {
  1182. while (true) {
  1183. var step = iterator.next();
  1184. if (step.done) {
  1185. return step;
  1186. }
  1187. var entry = step.value;
  1188. var key = entry[0];
  1189. var value = entry[1];
  1190. if (predicate.call(context, value, key, collection)) {
  1191. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  1192. }
  1193. }
  1194. });
  1195. };
  1196. return filterSequence;
  1197. }
  1198. function countByFactory(collection, grouper, context) {
  1199. var groups = Map().asMutable();
  1200. collection.__iterate(function (v, k) {
  1201. groups.update(grouper.call(context, v, k, collection), 0, function (a) { return a + 1; });
  1202. });
  1203. return groups.asImmutable();
  1204. }
  1205. function groupByFactory(collection, grouper, context) {
  1206. var isKeyedIter = isKeyed(collection);
  1207. var groups = (isOrdered(collection) ? OrderedMap() : Map()).asMutable();
  1208. collection.__iterate(function (v, k) {
  1209. groups.update(
  1210. grouper.call(context, v, k, collection),
  1211. function (a) { return ((a = a || []), a.push(isKeyedIter ? [k, v] : v), a); }
  1212. );
  1213. });
  1214. var coerce = collectionClass(collection);
  1215. return groups.map(function (arr) { return reify(collection, coerce(arr)); }).asImmutable();
  1216. }
  1217. function sliceFactory(collection, begin, end, useKeys) {
  1218. var originalSize = collection.size;
  1219. if (wholeSlice(begin, end, originalSize)) {
  1220. return collection;
  1221. }
  1222. var resolvedBegin = resolveBegin(begin, originalSize);
  1223. var resolvedEnd = resolveEnd(end, originalSize);
  1224. // begin or end will be NaN if they were provided as negative numbers and
  1225. // this collection's size is unknown. In that case, cache first so there is
  1226. // a known size and these do not resolve to NaN.
  1227. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  1228. return sliceFactory(collection.toSeq().cacheResult(), begin, end, useKeys);
  1229. }
  1230. // Note: resolvedEnd is undefined when the original sequence's length is
  1231. // unknown and this slice did not supply an end and should contain all
  1232. // elements after resolvedBegin.
  1233. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  1234. var resolvedSize = resolvedEnd - resolvedBegin;
  1235. var sliceSize;
  1236. if (resolvedSize === resolvedSize) {
  1237. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  1238. }
  1239. var sliceSeq = makeSequence(collection);
  1240. // If collection.size is undefined, the size of the realized sliceSeq is
  1241. // unknown at this point unless the number of items to slice is 0
  1242. sliceSeq.size =
  1243. sliceSize === 0 ? sliceSize : (collection.size && sliceSize) || undefined;
  1244. if (!useKeys && isSeq(collection) && sliceSize >= 0) {
  1245. sliceSeq.get = function (index, notSetValue) {
  1246. index = wrapIndex(this, index);
  1247. return index >= 0 && index < sliceSize
  1248. ? collection.get(index + resolvedBegin, notSetValue)
  1249. : notSetValue;
  1250. };
  1251. }
  1252. sliceSeq.__iterateUncached = function (fn, reverse) {
  1253. var this$1$1 = this;
  1254. if (sliceSize === 0) {
  1255. return 0;
  1256. }
  1257. if (reverse) {
  1258. return this.cacheResult().__iterate(fn, reverse);
  1259. }
  1260. var skipped = 0;
  1261. var isSkipping = true;
  1262. var iterations = 0;
  1263. collection.__iterate(function (v, k) {
  1264. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  1265. iterations++;
  1266. return (
  1267. fn(v, useKeys ? k : iterations - 1, this$1$1) !== false &&
  1268. iterations !== sliceSize
  1269. );
  1270. }
  1271. });
  1272. return iterations;
  1273. };
  1274. sliceSeq.__iteratorUncached = function (type, reverse) {
  1275. if (sliceSize !== 0 && reverse) {
  1276. return this.cacheResult().__iterator(type, reverse);
  1277. }
  1278. // Don't bother instantiating parent iterator if taking 0.
  1279. if (sliceSize === 0) {
  1280. return new Iterator(iteratorDone);
  1281. }
  1282. var iterator = collection.__iterator(type, reverse);
  1283. var skipped = 0;
  1284. var iterations = 0;
  1285. return new Iterator(function () {
  1286. while (skipped++ < resolvedBegin) {
  1287. iterator.next();
  1288. }
  1289. if (++iterations > sliceSize) {
  1290. return iteratorDone();
  1291. }
  1292. var step = iterator.next();
  1293. if (useKeys || type === ITERATE_VALUES || step.done) {
  1294. return step;
  1295. }
  1296. if (type === ITERATE_KEYS) {
  1297. return iteratorValue(type, iterations - 1, undefined, step);
  1298. }
  1299. return iteratorValue(type, iterations - 1, step.value[1], step);
  1300. });
  1301. };
  1302. return sliceSeq;
  1303. }
  1304. function takeWhileFactory(collection, predicate, context) {
  1305. var takeSequence = makeSequence(collection);
  1306. takeSequence.__iterateUncached = function (fn, reverse) {
  1307. var this$1$1 = this;
  1308. if (reverse) {
  1309. return this.cacheResult().__iterate(fn, reverse);
  1310. }
  1311. var iterations = 0;
  1312. collection.__iterate(
  1313. function (v, k, c) { return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$1$1); }
  1314. );
  1315. return iterations;
  1316. };
  1317. takeSequence.__iteratorUncached = function (type, reverse) {
  1318. var this$1$1 = this;
  1319. if (reverse) {
  1320. return this.cacheResult().__iterator(type, reverse);
  1321. }
  1322. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  1323. var iterating = true;
  1324. return new Iterator(function () {
  1325. if (!iterating) {
  1326. return iteratorDone();
  1327. }
  1328. var step = iterator.next();
  1329. if (step.done) {
  1330. return step;
  1331. }
  1332. var entry = step.value;
  1333. var k = entry[0];
  1334. var v = entry[1];
  1335. if (!predicate.call(context, v, k, this$1$1)) {
  1336. iterating = false;
  1337. return iteratorDone();
  1338. }
  1339. return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
  1340. });
  1341. };
  1342. return takeSequence;
  1343. }
  1344. function skipWhileFactory(collection, predicate, context, useKeys) {
  1345. var skipSequence = makeSequence(collection);
  1346. skipSequence.__iterateUncached = function (fn, reverse) {
  1347. var this$1$1 = this;
  1348. if (reverse) {
  1349. return this.cacheResult().__iterate(fn, reverse);
  1350. }
  1351. var isSkipping = true;
  1352. var iterations = 0;
  1353. collection.__iterate(function (v, k, c) {
  1354. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  1355. iterations++;
  1356. return fn(v, useKeys ? k : iterations - 1, this$1$1);
  1357. }
  1358. });
  1359. return iterations;
  1360. };
  1361. skipSequence.__iteratorUncached = function (type, reverse) {
  1362. var this$1$1 = this;
  1363. if (reverse) {
  1364. return this.cacheResult().__iterator(type, reverse);
  1365. }
  1366. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  1367. var skipping = true;
  1368. var iterations = 0;
  1369. return new Iterator(function () {
  1370. var step;
  1371. var k;
  1372. var v;
  1373. do {
  1374. step = iterator.next();
  1375. if (step.done) {
  1376. if (useKeys || type === ITERATE_VALUES) {
  1377. return step;
  1378. }
  1379. if (type === ITERATE_KEYS) {
  1380. return iteratorValue(type, iterations++, undefined, step);
  1381. }
  1382. return iteratorValue(type, iterations++, step.value[1], step);
  1383. }
  1384. var entry = step.value;
  1385. k = entry[0];
  1386. v = entry[1];
  1387. skipping && (skipping = predicate.call(context, v, k, this$1$1));
  1388. } while (skipping);
  1389. return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
  1390. });
  1391. };
  1392. return skipSequence;
  1393. }
  1394. function concatFactory(collection, values) {
  1395. var isKeyedCollection = isKeyed(collection);
  1396. var iters = [collection]
  1397. .concat(values)
  1398. .map(function (v) {
  1399. if (!isCollection(v)) {
  1400. v = isKeyedCollection
  1401. ? keyedSeqFromValue(v)
  1402. : indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  1403. } else if (isKeyedCollection) {
  1404. v = KeyedCollection(v);
  1405. }
  1406. return v;
  1407. })
  1408. .filter(function (v) { return v.size !== 0; });
  1409. if (iters.length === 0) {
  1410. return collection;
  1411. }
  1412. if (iters.length === 1) {
  1413. var singleton = iters[0];
  1414. if (
  1415. singleton === collection ||
  1416. (isKeyedCollection && isKeyed(singleton)) ||
  1417. (isIndexed(collection) && isIndexed(singleton))
  1418. ) {
  1419. return singleton;
  1420. }
  1421. }
  1422. var concatSeq = new ArraySeq(iters);
  1423. if (isKeyedCollection) {
  1424. concatSeq = concatSeq.toKeyedSeq();
  1425. } else if (!isIndexed(collection)) {
  1426. concatSeq = concatSeq.toSetSeq();
  1427. }
  1428. concatSeq = concatSeq.flatten(true);
  1429. concatSeq.size = iters.reduce(function (sum, seq) {
  1430. if (sum !== undefined) {
  1431. var size = seq.size;
  1432. if (size !== undefined) {
  1433. return sum + size;
  1434. }
  1435. }
  1436. }, 0);
  1437. return concatSeq;
  1438. }
  1439. function flattenFactory(collection, depth, useKeys) {
  1440. var flatSequence = makeSequence(collection);
  1441. flatSequence.__iterateUncached = function (fn, reverse) {
  1442. if (reverse) {
  1443. return this.cacheResult().__iterate(fn, reverse);
  1444. }
  1445. var iterations = 0;
  1446. var stopped = false;
  1447. function flatDeep(iter, currentDepth) {
  1448. iter.__iterate(function (v, k) {
  1449. if ((!depth || currentDepth < depth) && isCollection(v)) {
  1450. flatDeep(v, currentDepth + 1);
  1451. } else {
  1452. iterations++;
  1453. if (fn(v, useKeys ? k : iterations - 1, flatSequence) === false) {
  1454. stopped = true;
  1455. }
  1456. }
  1457. return !stopped;
  1458. }, reverse);
  1459. }
  1460. flatDeep(collection, 0);
  1461. return iterations;
  1462. };
  1463. flatSequence.__iteratorUncached = function (type, reverse) {
  1464. if (reverse) {
  1465. return this.cacheResult().__iterator(type, reverse);
  1466. }
  1467. var iterator = collection.__iterator(type, reverse);
  1468. var stack = [];
  1469. var iterations = 0;
  1470. return new Iterator(function () {
  1471. while (iterator) {
  1472. var step = iterator.next();
  1473. if (step.done !== false) {
  1474. iterator = stack.pop();
  1475. continue;
  1476. }
  1477. var v = step.value;
  1478. if (type === ITERATE_ENTRIES) {
  1479. v = v[1];
  1480. }
  1481. if ((!depth || stack.length < depth) && isCollection(v)) {
  1482. stack.push(iterator);
  1483. iterator = v.__iterator(type, reverse);
  1484. } else {
  1485. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  1486. }
  1487. }
  1488. return iteratorDone();
  1489. });
  1490. };
  1491. return flatSequence;
  1492. }
  1493. function flatMapFactory(collection, mapper, context) {
  1494. var coerce = collectionClass(collection);
  1495. return collection
  1496. .toSeq()
  1497. .map(function (v, k) { return coerce(mapper.call(context, v, k, collection)); })
  1498. .flatten(true);
  1499. }
  1500. function interposeFactory(collection, separator) {
  1501. var interposedSequence = makeSequence(collection);
  1502. interposedSequence.size = collection.size && collection.size * 2 - 1;
  1503. interposedSequence.__iterateUncached = function (fn, reverse) {
  1504. var this$1$1 = this;
  1505. var iterations = 0;
  1506. collection.__iterate(
  1507. function (v) { return (!iterations || fn(separator, iterations++, this$1$1) !== false) &&
  1508. fn(v, iterations++, this$1$1) !== false; },
  1509. reverse
  1510. );
  1511. return iterations;
  1512. };
  1513. interposedSequence.__iteratorUncached = function (type, reverse) {
  1514. var iterator = collection.__iterator(ITERATE_VALUES, reverse);
  1515. var iterations = 0;
  1516. var step;
  1517. return new Iterator(function () {
  1518. if (!step || iterations % 2) {
  1519. step = iterator.next();
  1520. if (step.done) {
  1521. return step;
  1522. }
  1523. }
  1524. return iterations % 2
  1525. ? iteratorValue(type, iterations++, separator)
  1526. : iteratorValue(type, iterations++, step.value, step);
  1527. });
  1528. };
  1529. return interposedSequence;
  1530. }
  1531. function sortFactory(collection, comparator, mapper) {
  1532. if (!comparator) {
  1533. comparator = defaultComparator;
  1534. }
  1535. var isKeyedCollection = isKeyed(collection);
  1536. var index = 0;
  1537. var entries = collection
  1538. .toSeq()
  1539. .map(function (v, k) { return [k, v, index++, mapper ? mapper(v, k, collection) : v]; })
  1540. .valueSeq()
  1541. .toArray();
  1542. entries
  1543. .sort(function (a, b) { return comparator(a[3], b[3]) || a[2] - b[2]; })
  1544. .forEach(
  1545. isKeyedCollection
  1546. ? function (v, i) {
  1547. entries[i].length = 2;
  1548. }
  1549. : function (v, i) {
  1550. entries[i] = v[1];
  1551. }
  1552. );
  1553. return isKeyedCollection
  1554. ? KeyedSeq(entries)
  1555. : isIndexed(collection)
  1556. ? IndexedSeq(entries)
  1557. : SetSeq(entries);
  1558. }
  1559. function maxFactory(collection, comparator, mapper) {
  1560. if (!comparator) {
  1561. comparator = defaultComparator;
  1562. }
  1563. if (mapper) {
  1564. var entry = collection
  1565. .toSeq()
  1566. .map(function (v, k) { return [v, mapper(v, k, collection)]; })
  1567. .reduce(function (a, b) { return (maxCompare(comparator, a[1], b[1]) ? b : a); });
  1568. return entry && entry[0];
  1569. }
  1570. return collection.reduce(function (a, b) { return (maxCompare(comparator, a, b) ? b : a); });
  1571. }
  1572. function maxCompare(comparator, a, b) {
  1573. var comp = comparator(b, a);
  1574. // b is considered the new max if the comparator declares them equal, but
  1575. // they are not equal and b is in fact a nullish value.
  1576. return (
  1577. (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) ||
  1578. comp > 0
  1579. );
  1580. }
  1581. function zipWithFactory(keyIter, zipper, iters, zipAll) {
  1582. var zipSequence = makeSequence(keyIter);
  1583. var sizes = new ArraySeq(iters).map(function (i) { return i.size; });
  1584. zipSequence.size = zipAll ? sizes.max() : sizes.min();
  1585. // Note: this a generic base implementation of __iterate in terms of
  1586. // __iterator which may be more generically useful in the future.
  1587. zipSequence.__iterate = function (fn, reverse) {
  1588. /* generic:
  1589. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  1590. var step;
  1591. var iterations = 0;
  1592. while (!(step = iterator.next()).done) {
  1593. iterations++;
  1594. if (fn(step.value[1], step.value[0], this) === false) {
  1595. break;
  1596. }
  1597. }
  1598. return iterations;
  1599. */
  1600. // indexed:
  1601. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  1602. var step;
  1603. var iterations = 0;
  1604. while (!(step = iterator.next()).done) {
  1605. if (fn(step.value, iterations++, this) === false) {
  1606. break;
  1607. }
  1608. }
  1609. return iterations;
  1610. };
  1611. zipSequence.__iteratorUncached = function (type, reverse) {
  1612. var iterators = iters.map(
  1613. function (i) { return ((i = Collection(i)), getIterator(reverse ? i.reverse() : i)); }
  1614. );
  1615. var iterations = 0;
  1616. var isDone = false;
  1617. return new Iterator(function () {
  1618. var steps;
  1619. if (!isDone) {
  1620. steps = iterators.map(function (i) { return i.next(); });
  1621. isDone = zipAll ? steps.every(function (s) { return s.done; }) : steps.some(function (s) { return s.done; });
  1622. }
  1623. if (isDone) {
  1624. return iteratorDone();
  1625. }
  1626. return iteratorValue(
  1627. type,
  1628. iterations++,
  1629. zipper.apply(
  1630. null,
  1631. steps.map(function (s) { return s.value; })
  1632. )
  1633. );
  1634. });
  1635. };
  1636. return zipSequence;
  1637. }
  1638. // #pragma Helper Functions
  1639. function reify(iter, seq) {
  1640. return iter === seq ? iter : isSeq(iter) ? seq : iter.constructor(seq);
  1641. }
  1642. function validateEntry(entry) {
  1643. if (entry !== Object(entry)) {
  1644. throw new TypeError('Expected [K, V] tuple: ' + entry);
  1645. }
  1646. }
  1647. function collectionClass(collection) {
  1648. return isKeyed(collection)
  1649. ? KeyedCollection
  1650. : isIndexed(collection)
  1651. ? IndexedCollection
  1652. : SetCollection;
  1653. }
  1654. function makeSequence(collection) {
  1655. return Object.create(
  1656. (isKeyed(collection)
  1657. ? KeyedSeq
  1658. : isIndexed(collection)
  1659. ? IndexedSeq
  1660. : SetSeq
  1661. ).prototype
  1662. );
  1663. }
  1664. function cacheResultThrough() {
  1665. if (this._iter.cacheResult) {
  1666. this._iter.cacheResult();
  1667. this.size = this._iter.size;
  1668. return this;
  1669. }
  1670. return Seq.prototype.cacheResult.call(this);
  1671. }
  1672. function defaultComparator(a, b) {
  1673. if (a === undefined && b === undefined) {
  1674. return 0;
  1675. }
  1676. if (a === undefined) {
  1677. return 1;
  1678. }
  1679. if (b === undefined) {
  1680. return -1;
  1681. }
  1682. return a > b ? 1 : a < b ? -1 : 0;
  1683. }
  1684. function arrCopy(arr, offset) {
  1685. offset = offset || 0;
  1686. var len = Math.max(0, arr.length - offset);
  1687. var newArr = new Array(len);
  1688. for (var ii = 0; ii < len; ii++) {
  1689. newArr[ii] = arr[ii + offset];
  1690. }
  1691. return newArr;
  1692. }
  1693. function invariant(condition, error) {
  1694. if (!condition) { throw new Error(error); }
  1695. }
  1696. function assertNotInfinite(size) {
  1697. invariant(
  1698. size !== Infinity,
  1699. 'Cannot perform this action with an infinite size.'
  1700. );
  1701. }
  1702. function coerceKeyPath(keyPath) {
  1703. if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
  1704. return keyPath;
  1705. }
  1706. if (isOrdered(keyPath)) {
  1707. return keyPath.toArray();
  1708. }
  1709. throw new TypeError(
  1710. 'Invalid keyPath: expected Ordered Collection or Array: ' + keyPath
  1711. );
  1712. }
  1713. var toString = Object.prototype.toString;
  1714. function isPlainObject(value) {
  1715. // The base prototype's toString deals with Argument objects and native namespaces like Math
  1716. if (
  1717. !value ||
  1718. typeof value !== 'object' ||
  1719. toString.call(value) !== '[object Object]'
  1720. ) {
  1721. return false;
  1722. }
  1723. var proto = Object.getPrototypeOf(value);
  1724. if (proto === null) {
  1725. return true;
  1726. }
  1727. // Iteratively going up the prototype chain is needed for cross-realm environments (differing contexts, iframes, etc)
  1728. var parentProto = proto;
  1729. var nextProto = Object.getPrototypeOf(proto);
  1730. while (nextProto !== null) {
  1731. parentProto = nextProto;
  1732. nextProto = Object.getPrototypeOf(parentProto);
  1733. }
  1734. return parentProto === proto;
  1735. }
  1736. /**
  1737. * Returns true if the value is a potentially-persistent data structure, either
  1738. * provided by Immutable.js or a plain Array or Object.
  1739. */
  1740. function isDataStructure(value) {
  1741. return (
  1742. typeof value === 'object' &&
  1743. (isImmutable(value) || Array.isArray(value) || isPlainObject(value))
  1744. );
  1745. }
  1746. function quoteString(value) {
  1747. try {
  1748. return typeof value === 'string' ? JSON.stringify(value) : String(value);
  1749. } catch (_ignoreError) {
  1750. return JSON.stringify(value);
  1751. }
  1752. }
  1753. function has(collection, key) {
  1754. return isImmutable(collection)
  1755. ? collection.has(key)
  1756. : isDataStructure(collection) && hasOwnProperty.call(collection, key);
  1757. }
  1758. function get(collection, key, notSetValue) {
  1759. return isImmutable(collection)
  1760. ? collection.get(key, notSetValue)
  1761. : !has(collection, key)
  1762. ? notSetValue
  1763. : typeof collection.get === 'function'
  1764. ? collection.get(key)
  1765. : collection[key];
  1766. }
  1767. function shallowCopy(from) {
  1768. if (Array.isArray(from)) {
  1769. return arrCopy(from);
  1770. }
  1771. var to = {};
  1772. for (var key in from) {
  1773. if (hasOwnProperty.call(from, key)) {
  1774. to[key] = from[key];
  1775. }
  1776. }
  1777. return to;
  1778. }
  1779. function remove(collection, key) {
  1780. if (!isDataStructure(collection)) {
  1781. throw new TypeError(
  1782. 'Cannot update non-data-structure value: ' + collection
  1783. );
  1784. }
  1785. if (isImmutable(collection)) {
  1786. if (!collection.remove) {
  1787. throw new TypeError(
  1788. 'Cannot update immutable value without .remove() method: ' + collection
  1789. );
  1790. }
  1791. return collection.remove(key);
  1792. }
  1793. if (!hasOwnProperty.call(collection, key)) {
  1794. return collection;
  1795. }
  1796. var collectionCopy = shallowCopy(collection);
  1797. if (Array.isArray(collectionCopy)) {
  1798. collectionCopy.splice(key, 1);
  1799. } else {
  1800. delete collectionCopy[key];
  1801. }
  1802. return collectionCopy;
  1803. }
  1804. function set(collection, key, value) {
  1805. if (!isDataStructure(collection)) {
  1806. throw new TypeError(
  1807. 'Cannot update non-data-structure value: ' + collection
  1808. );
  1809. }
  1810. if (isImmutable(collection)) {
  1811. if (!collection.set) {
  1812. throw new TypeError(
  1813. 'Cannot update immutable value without .set() method: ' + collection
  1814. );
  1815. }
  1816. return collection.set(key, value);
  1817. }
  1818. if (hasOwnProperty.call(collection, key) && value === collection[key]) {
  1819. return collection;
  1820. }
  1821. var collectionCopy = shallowCopy(collection);
  1822. collectionCopy[key] = value;
  1823. return collectionCopy;
  1824. }
  1825. function updateIn$1(collection, keyPath, notSetValue, updater) {
  1826. if (!updater) {
  1827. updater = notSetValue;
  1828. notSetValue = undefined;
  1829. }
  1830. var updatedValue = updateInDeeply(
  1831. isImmutable(collection),
  1832. collection,
  1833. coerceKeyPath(keyPath),
  1834. 0,
  1835. notSetValue,
  1836. updater
  1837. );
  1838. return updatedValue === NOT_SET ? notSetValue : updatedValue;
  1839. }
  1840. function updateInDeeply(
  1841. inImmutable,
  1842. existing,
  1843. keyPath,
  1844. i,
  1845. notSetValue,
  1846. updater
  1847. ) {
  1848. var wasNotSet = existing === NOT_SET;
  1849. if (i === keyPath.length) {
  1850. var existingValue = wasNotSet ? notSetValue : existing;
  1851. var newValue = updater(existingValue);
  1852. return newValue === existingValue ? existing : newValue;
  1853. }
  1854. if (!wasNotSet && !isDataStructure(existing)) {
  1855. throw new TypeError(
  1856. 'Cannot update within non-data-structure value in path [' +
  1857. keyPath.slice(0, i).map(quoteString) +
  1858. ']: ' +
  1859. existing
  1860. );
  1861. }
  1862. var key = keyPath[i];
  1863. var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
  1864. var nextUpdated = updateInDeeply(
  1865. nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
  1866. nextExisting,
  1867. keyPath,
  1868. i + 1,
  1869. notSetValue,
  1870. updater
  1871. );
  1872. return nextUpdated === nextExisting
  1873. ? existing
  1874. : nextUpdated === NOT_SET
  1875. ? remove(existing, key)
  1876. : set(
  1877. wasNotSet ? (inImmutable ? emptyMap() : {}) : existing,
  1878. key,
  1879. nextUpdated
  1880. );
  1881. }
  1882. function setIn$1(collection, keyPath, value) {
  1883. return updateIn$1(collection, keyPath, NOT_SET, function () { return value; });
  1884. }
  1885. function setIn(keyPath, v) {
  1886. return setIn$1(this, keyPath, v);
  1887. }
  1888. function removeIn(collection, keyPath) {
  1889. return updateIn$1(collection, keyPath, function () { return NOT_SET; });
  1890. }
  1891. function deleteIn(keyPath) {
  1892. return removeIn(this, keyPath);
  1893. }
  1894. function update$1(collection, key, notSetValue, updater) {
  1895. return updateIn$1(collection, [key], notSetValue, updater);
  1896. }
  1897. function update(key, notSetValue, updater) {
  1898. return arguments.length === 1
  1899. ? key(this)
  1900. : update$1(this, key, notSetValue, updater);
  1901. }
  1902. function updateIn(keyPath, notSetValue, updater) {
  1903. return updateIn$1(this, keyPath, notSetValue, updater);
  1904. }
  1905. function merge$1() {
  1906. var iters = [], len = arguments.length;
  1907. while ( len-- ) iters[ len ] = arguments[ len ];
  1908. return mergeIntoKeyedWith(this, iters);
  1909. }
  1910. function mergeWith$1(merger) {
  1911. var iters = [], len = arguments.length - 1;
  1912. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  1913. if (typeof merger !== 'function') {
  1914. throw new TypeError('Invalid merger function: ' + merger);
  1915. }
  1916. return mergeIntoKeyedWith(this, iters, merger);
  1917. }
  1918. function mergeIntoKeyedWith(collection, collections, merger) {
  1919. var iters = [];
  1920. for (var ii = 0; ii < collections.length; ii++) {
  1921. var collection$1 = KeyedCollection(collections[ii]);
  1922. if (collection$1.size !== 0) {
  1923. iters.push(collection$1);
  1924. }
  1925. }
  1926. if (iters.length === 0) {
  1927. return collection;
  1928. }
  1929. if (
  1930. collection.toSeq().size === 0 &&
  1931. !collection.__ownerID &&
  1932. iters.length === 1
  1933. ) {
  1934. return collection.constructor(iters[0]);
  1935. }
  1936. return collection.withMutations(function (collection) {
  1937. var mergeIntoCollection = merger
  1938. ? function (value, key) {
  1939. update$1(collection, key, NOT_SET, function (oldVal) { return oldVal === NOT_SET ? value : merger(oldVal, value, key); }
  1940. );
  1941. }
  1942. : function (value, key) {
  1943. collection.set(key, value);
  1944. };
  1945. for (var ii = 0; ii < iters.length; ii++) {
  1946. iters[ii].forEach(mergeIntoCollection);
  1947. }
  1948. });
  1949. }
  1950. function merge(collection) {
  1951. var sources = [], len = arguments.length - 1;
  1952. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  1953. return mergeWithSources(collection, sources);
  1954. }
  1955. function mergeWith(merger, collection) {
  1956. var sources = [], len = arguments.length - 2;
  1957. while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
  1958. return mergeWithSources(collection, sources, merger);
  1959. }
  1960. function mergeDeep$1(collection) {
  1961. var sources = [], len = arguments.length - 1;
  1962. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  1963. return mergeDeepWithSources(collection, sources);
  1964. }
  1965. function mergeDeepWith$1(merger, collection) {
  1966. var sources = [], len = arguments.length - 2;
  1967. while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
  1968. return mergeDeepWithSources(collection, sources, merger);
  1969. }
  1970. function mergeDeepWithSources(collection, sources, merger) {
  1971. return mergeWithSources(collection, sources, deepMergerWith(merger));
  1972. }
  1973. function mergeWithSources(collection, sources, merger) {
  1974. if (!isDataStructure(collection)) {
  1975. throw new TypeError(
  1976. 'Cannot merge into non-data-structure value: ' + collection
  1977. );
  1978. }
  1979. if (isImmutable(collection)) {
  1980. return typeof merger === 'function' && collection.mergeWith
  1981. ? collection.mergeWith.apply(collection, [ merger ].concat( sources ))
  1982. : collection.merge
  1983. ? collection.merge.apply(collection, sources)
  1984. : collection.concat.apply(collection, sources);
  1985. }
  1986. var isArray = Array.isArray(collection);
  1987. var merged = collection;
  1988. var Collection = isArray ? IndexedCollection : KeyedCollection;
  1989. var mergeItem = isArray
  1990. ? function (value) {
  1991. // Copy on write
  1992. if (merged === collection) {
  1993. merged = shallowCopy(merged);
  1994. }
  1995. merged.push(value);
  1996. }
  1997. : function (value, key) {
  1998. var hasVal = hasOwnProperty.call(merged, key);
  1999. var nextVal =
  2000. hasVal && merger ? merger(merged[key], value, key) : value;
  2001. if (!hasVal || nextVal !== merged[key]) {
  2002. // Copy on write
  2003. if (merged === collection) {
  2004. merged = shallowCopy(merged);
  2005. }
  2006. merged[key] = nextVal;
  2007. }
  2008. };
  2009. for (var i = 0; i < sources.length; i++) {
  2010. Collection(sources[i]).forEach(mergeItem);
  2011. }
  2012. return merged;
  2013. }
  2014. function deepMergerWith(merger) {
  2015. function deepMerger(oldValue, newValue, key) {
  2016. return isDataStructure(oldValue) &&
  2017. isDataStructure(newValue) &&
  2018. areMergeable(oldValue, newValue)
  2019. ? mergeWithSources(oldValue, [newValue], deepMerger)
  2020. : merger
  2021. ? merger(oldValue, newValue, key)
  2022. : newValue;
  2023. }
  2024. return deepMerger;
  2025. }
  2026. /**
  2027. * It's unclear what the desired behavior is for merging two collections that
  2028. * fall into separate categories between keyed, indexed, or set-like, so we only
  2029. * consider them mergeable if they fall into the same category.
  2030. */
  2031. function areMergeable(oldDataStructure, newDataStructure) {
  2032. var oldSeq = Seq(oldDataStructure);
  2033. var newSeq = Seq(newDataStructure);
  2034. // This logic assumes that a sequence can only fall into one of the three
  2035. // categories mentioned above (since there's no `isSetLike()` method).
  2036. return (
  2037. isIndexed(oldSeq) === isIndexed(newSeq) &&
  2038. isKeyed(oldSeq) === isKeyed(newSeq)
  2039. );
  2040. }
  2041. function mergeDeep() {
  2042. var iters = [], len = arguments.length;
  2043. while ( len-- ) iters[ len ] = arguments[ len ];
  2044. return mergeDeepWithSources(this, iters);
  2045. }
  2046. function mergeDeepWith(merger) {
  2047. var iters = [], len = arguments.length - 1;
  2048. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  2049. return mergeDeepWithSources(this, iters, merger);
  2050. }
  2051. function mergeIn(keyPath) {
  2052. var iters = [], len = arguments.length - 1;
  2053. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  2054. return updateIn$1(this, keyPath, emptyMap(), function (m) { return mergeWithSources(m, iters); });
  2055. }
  2056. function mergeDeepIn(keyPath) {
  2057. var iters = [], len = arguments.length - 1;
  2058. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  2059. return updateIn$1(this, keyPath, emptyMap(), function (m) { return mergeDeepWithSources(m, iters); }
  2060. );
  2061. }
  2062. function withMutations(fn) {
  2063. var mutable = this.asMutable();
  2064. fn(mutable);
  2065. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  2066. }
  2067. function asMutable() {
  2068. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  2069. }
  2070. function asImmutable() {
  2071. return this.__ensureOwner();
  2072. }
  2073. function wasAltered() {
  2074. return this.__altered;
  2075. }
  2076. var Map = /*@__PURE__*/(function (KeyedCollection) {
  2077. function Map(value) {
  2078. return value === undefined || value === null
  2079. ? emptyMap()
  2080. : isMap(value) && !isOrdered(value)
  2081. ? value
  2082. : emptyMap().withMutations(function (map) {
  2083. var iter = KeyedCollection(value);
  2084. assertNotInfinite(iter.size);
  2085. iter.forEach(function (v, k) { return map.set(k, v); });
  2086. });
  2087. }
  2088. if ( KeyedCollection ) Map.__proto__ = KeyedCollection;
  2089. Map.prototype = Object.create( KeyedCollection && KeyedCollection.prototype );
  2090. Map.prototype.constructor = Map;
  2091. Map.of = function of () {
  2092. var keyValues = [], len = arguments.length;
  2093. while ( len-- ) keyValues[ len ] = arguments[ len ];
  2094. return emptyMap().withMutations(function (map) {
  2095. for (var i = 0; i < keyValues.length; i += 2) {
  2096. if (i + 1 >= keyValues.length) {
  2097. throw new Error('Missing value for key: ' + keyValues[i]);
  2098. }
  2099. map.set(keyValues[i], keyValues[i + 1]);
  2100. }
  2101. });
  2102. };
  2103. Map.prototype.toString = function toString () {
  2104. return this.__toString('Map {', '}');
  2105. };
  2106. // @pragma Access
  2107. Map.prototype.get = function get (k, notSetValue) {
  2108. return this._root
  2109. ? this._root.get(0, undefined, k, notSetValue)
  2110. : notSetValue;
  2111. };
  2112. // @pragma Modification
  2113. Map.prototype.set = function set (k, v) {
  2114. return updateMap(this, k, v);
  2115. };
  2116. Map.prototype.remove = function remove (k) {
  2117. return updateMap(this, k, NOT_SET);
  2118. };
  2119. Map.prototype.deleteAll = function deleteAll (keys) {
  2120. var collection = Collection(keys);
  2121. if (collection.size === 0) {
  2122. return this;
  2123. }
  2124. return this.withMutations(function (map) {
  2125. collection.forEach(function (key) { return map.remove(key); });
  2126. });
  2127. };
  2128. Map.prototype.clear = function clear () {
  2129. if (this.size === 0) {
  2130. return this;
  2131. }
  2132. if (this.__ownerID) {
  2133. this.size = 0;
  2134. this._root = null;
  2135. this.__hash = undefined;
  2136. this.__altered = true;
  2137. return this;
  2138. }
  2139. return emptyMap();
  2140. };
  2141. // @pragma Composition
  2142. Map.prototype.sort = function sort (comparator) {
  2143. // Late binding
  2144. return OrderedMap(sortFactory(this, comparator));
  2145. };
  2146. Map.prototype.sortBy = function sortBy (mapper, comparator) {
  2147. // Late binding
  2148. return OrderedMap(sortFactory(this, comparator, mapper));
  2149. };
  2150. Map.prototype.map = function map (mapper, context) {
  2151. var this$1$1 = this;
  2152. return this.withMutations(function (map) {
  2153. map.forEach(function (value, key) {
  2154. map.set(key, mapper.call(context, value, key, this$1$1));
  2155. });
  2156. });
  2157. };
  2158. // @pragma Mutability
  2159. Map.prototype.__iterator = function __iterator (type, reverse) {
  2160. return new MapIterator(this, type, reverse);
  2161. };
  2162. Map.prototype.__iterate = function __iterate (fn, reverse) {
  2163. var this$1$1 = this;
  2164. var iterations = 0;
  2165. this._root &&
  2166. this._root.iterate(function (entry) {
  2167. iterations++;
  2168. return fn(entry[1], entry[0], this$1$1);
  2169. }, reverse);
  2170. return iterations;
  2171. };
  2172. Map.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  2173. if (ownerID === this.__ownerID) {
  2174. return this;
  2175. }
  2176. if (!ownerID) {
  2177. if (this.size === 0) {
  2178. return emptyMap();
  2179. }
  2180. this.__ownerID = ownerID;
  2181. this.__altered = false;
  2182. return this;
  2183. }
  2184. return makeMap(this.size, this._root, ownerID, this.__hash);
  2185. };
  2186. return Map;
  2187. }(KeyedCollection));
  2188. Map.isMap = isMap;
  2189. var MapPrototype = Map.prototype;
  2190. MapPrototype[IS_MAP_SYMBOL] = true;
  2191. MapPrototype[DELETE] = MapPrototype.remove;
  2192. MapPrototype.removeAll = MapPrototype.deleteAll;
  2193. MapPrototype.setIn = setIn;
  2194. MapPrototype.removeIn = MapPrototype.deleteIn = deleteIn;
  2195. MapPrototype.update = update;
  2196. MapPrototype.updateIn = updateIn;
  2197. MapPrototype.merge = MapPrototype.concat = merge$1;
  2198. MapPrototype.mergeWith = mergeWith$1;
  2199. MapPrototype.mergeDeep = mergeDeep;
  2200. MapPrototype.mergeDeepWith = mergeDeepWith;
  2201. MapPrototype.mergeIn = mergeIn;
  2202. MapPrototype.mergeDeepIn = mergeDeepIn;
  2203. MapPrototype.withMutations = withMutations;
  2204. MapPrototype.wasAltered = wasAltered;
  2205. MapPrototype.asImmutable = asImmutable;
  2206. MapPrototype['@@transducer/init'] = MapPrototype.asMutable = asMutable;
  2207. MapPrototype['@@transducer/step'] = function (result, arr) {
  2208. return result.set(arr[0], arr[1]);
  2209. };
  2210. MapPrototype['@@transducer/result'] = function (obj) {
  2211. return obj.asImmutable();
  2212. };
  2213. // #pragma Trie Nodes
  2214. var ArrayMapNode = function ArrayMapNode(ownerID, entries) {
  2215. this.ownerID = ownerID;
  2216. this.entries = entries;
  2217. };
  2218. ArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  2219. var entries = this.entries;
  2220. for (var ii = 0, len = entries.length; ii < len; ii++) {
  2221. if (is(key, entries[ii][0])) {
  2222. return entries[ii][1];
  2223. }
  2224. }
  2225. return notSetValue;
  2226. };
  2227. ArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  2228. var removed = value === NOT_SET;
  2229. var entries = this.entries;
  2230. var idx = 0;
  2231. var len = entries.length;
  2232. for (; idx < len; idx++) {
  2233. if (is(key, entries[idx][0])) {
  2234. break;
  2235. }
  2236. }
  2237. var exists = idx < len;
  2238. if (exists ? entries[idx][1] === value : removed) {
  2239. return this;
  2240. }
  2241. SetRef(didAlter);
  2242. (removed || !exists) && SetRef(didChangeSize);
  2243. if (removed && entries.length === 1) {
  2244. return; // undefined
  2245. }
  2246. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  2247. return createNodes(ownerID, entries, key, value);
  2248. }
  2249. var isEditable = ownerID && ownerID === this.ownerID;
  2250. var newEntries = isEditable ? entries : arrCopy(entries);
  2251. if (exists) {
  2252. if (removed) {
  2253. idx === len - 1
  2254. ? newEntries.pop()
  2255. : (newEntries[idx] = newEntries.pop());
  2256. } else {
  2257. newEntries[idx] = [key, value];
  2258. }
  2259. } else {
  2260. newEntries.push([key, value]);
  2261. }
  2262. if (isEditable) {
  2263. this.entries = newEntries;
  2264. return this;
  2265. }
  2266. return new ArrayMapNode(ownerID, newEntries);
  2267. };
  2268. var BitmapIndexedNode = function BitmapIndexedNode(ownerID, bitmap, nodes) {
  2269. this.ownerID = ownerID;
  2270. this.bitmap = bitmap;
  2271. this.nodes = nodes;
  2272. };
  2273. BitmapIndexedNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  2274. if (keyHash === undefined) {
  2275. keyHash = hash(key);
  2276. }
  2277. var bit = 1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK);
  2278. var bitmap = this.bitmap;
  2279. return (bitmap & bit) === 0
  2280. ? notSetValue
  2281. : this.nodes[popCount(bitmap & (bit - 1))].get(
  2282. shift + SHIFT,
  2283. keyHash,
  2284. key,
  2285. notSetValue
  2286. );
  2287. };
  2288. BitmapIndexedNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  2289. if (keyHash === undefined) {
  2290. keyHash = hash(key);
  2291. }
  2292. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  2293. var bit = 1 << keyHashFrag;
  2294. var bitmap = this.bitmap;
  2295. var exists = (bitmap & bit) !== 0;
  2296. if (!exists && value === NOT_SET) {
  2297. return this;
  2298. }
  2299. var idx = popCount(bitmap & (bit - 1));
  2300. var nodes = this.nodes;
  2301. var node = exists ? nodes[idx] : undefined;
  2302. var newNode = updateNode(
  2303. node,
  2304. ownerID,
  2305. shift + SHIFT,
  2306. keyHash,
  2307. key,
  2308. value,
  2309. didChangeSize,
  2310. didAlter
  2311. );
  2312. if (newNode === node) {
  2313. return this;
  2314. }
  2315. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  2316. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  2317. }
  2318. if (
  2319. exists &&
  2320. !newNode &&
  2321. nodes.length === 2 &&
  2322. isLeafNode(nodes[idx ^ 1])
  2323. ) {
  2324. return nodes[idx ^ 1];
  2325. }
  2326. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  2327. return newNode;
  2328. }
  2329. var isEditable = ownerID && ownerID === this.ownerID;
  2330. var newBitmap = exists ? (newNode ? bitmap : bitmap ^ bit) : bitmap | bit;
  2331. var newNodes = exists
  2332. ? newNode
  2333. ? setAt(nodes, idx, newNode, isEditable)
  2334. : spliceOut(nodes, idx, isEditable)
  2335. : spliceIn(nodes, idx, newNode, isEditable);
  2336. if (isEditable) {
  2337. this.bitmap = newBitmap;
  2338. this.nodes = newNodes;
  2339. return this;
  2340. }
  2341. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  2342. };
  2343. var HashArrayMapNode = function HashArrayMapNode(ownerID, count, nodes) {
  2344. this.ownerID = ownerID;
  2345. this.count = count;
  2346. this.nodes = nodes;
  2347. };
  2348. HashArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  2349. if (keyHash === undefined) {
  2350. keyHash = hash(key);
  2351. }
  2352. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  2353. var node = this.nodes[idx];
  2354. return node
  2355. ? node.get(shift + SHIFT, keyHash, key, notSetValue)
  2356. : notSetValue;
  2357. };
  2358. HashArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  2359. if (keyHash === undefined) {
  2360. keyHash = hash(key);
  2361. }
  2362. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  2363. var removed = value === NOT_SET;
  2364. var nodes = this.nodes;
  2365. var node = nodes[idx];
  2366. if (removed && !node) {
  2367. return this;
  2368. }
  2369. var newNode = updateNode(
  2370. node,
  2371. ownerID,
  2372. shift + SHIFT,
  2373. keyHash,
  2374. key,
  2375. value,
  2376. didChangeSize,
  2377. didAlter
  2378. );
  2379. if (newNode === node) {
  2380. return this;
  2381. }
  2382. var newCount = this.count;
  2383. if (!node) {
  2384. newCount++;
  2385. } else if (!newNode) {
  2386. newCount--;
  2387. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  2388. return packNodes(ownerID, nodes, newCount, idx);
  2389. }
  2390. }
  2391. var isEditable = ownerID && ownerID === this.ownerID;
  2392. var newNodes = setAt(nodes, idx, newNode, isEditable);
  2393. if (isEditable) {
  2394. this.count = newCount;
  2395. this.nodes = newNodes;
  2396. return this;
  2397. }
  2398. return new HashArrayMapNode(ownerID, newCount, newNodes);
  2399. };
  2400. var HashCollisionNode = function HashCollisionNode(ownerID, keyHash, entries) {
  2401. this.ownerID = ownerID;
  2402. this.keyHash = keyHash;
  2403. this.entries = entries;
  2404. };
  2405. HashCollisionNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  2406. var entries = this.entries;
  2407. for (var ii = 0, len = entries.length; ii < len; ii++) {
  2408. if (is(key, entries[ii][0])) {
  2409. return entries[ii][1];
  2410. }
  2411. }
  2412. return notSetValue;
  2413. };
  2414. HashCollisionNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  2415. if (keyHash === undefined) {
  2416. keyHash = hash(key);
  2417. }
  2418. var removed = value === NOT_SET;
  2419. if (keyHash !== this.keyHash) {
  2420. if (removed) {
  2421. return this;
  2422. }
  2423. SetRef(didAlter);
  2424. SetRef(didChangeSize);
  2425. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  2426. }
  2427. var entries = this.entries;
  2428. var idx = 0;
  2429. var len = entries.length;
  2430. for (; idx < len; idx++) {
  2431. if (is(key, entries[idx][0])) {
  2432. break;
  2433. }
  2434. }
  2435. var exists = idx < len;
  2436. if (exists ? entries[idx][1] === value : removed) {
  2437. return this;
  2438. }
  2439. SetRef(didAlter);
  2440. (removed || !exists) && SetRef(didChangeSize);
  2441. if (removed && len === 2) {
  2442. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  2443. }
  2444. var isEditable = ownerID && ownerID === this.ownerID;
  2445. var newEntries = isEditable ? entries : arrCopy(entries);
  2446. if (exists) {
  2447. if (removed) {
  2448. idx === len - 1
  2449. ? newEntries.pop()
  2450. : (newEntries[idx] = newEntries.pop());
  2451. } else {
  2452. newEntries[idx] = [key, value];
  2453. }
  2454. } else {
  2455. newEntries.push([key, value]);
  2456. }
  2457. if (isEditable) {
  2458. this.entries = newEntries;
  2459. return this;
  2460. }
  2461. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  2462. };
  2463. var ValueNode = function ValueNode(ownerID, keyHash, entry) {
  2464. this.ownerID = ownerID;
  2465. this.keyHash = keyHash;
  2466. this.entry = entry;
  2467. };
  2468. ValueNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  2469. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  2470. };
  2471. ValueNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  2472. var removed = value === NOT_SET;
  2473. var keyMatch = is(key, this.entry[0]);
  2474. if (keyMatch ? value === this.entry[1] : removed) {
  2475. return this;
  2476. }
  2477. SetRef(didAlter);
  2478. if (removed) {
  2479. SetRef(didChangeSize);
  2480. return; // undefined
  2481. }
  2482. if (keyMatch) {
  2483. if (ownerID && ownerID === this.ownerID) {
  2484. this.entry[1] = value;
  2485. return this;
  2486. }
  2487. return new ValueNode(ownerID, this.keyHash, [key, value]);
  2488. }
  2489. SetRef(didChangeSize);
  2490. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  2491. };
  2492. // #pragma Iterators
  2493. ArrayMapNode.prototype.iterate = HashCollisionNode.prototype.iterate =
  2494. function (fn, reverse) {
  2495. var entries = this.entries;
  2496. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  2497. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  2498. return false;
  2499. }
  2500. }
  2501. };
  2502. BitmapIndexedNode.prototype.iterate = HashArrayMapNode.prototype.iterate =
  2503. function (fn, reverse) {
  2504. var nodes = this.nodes;
  2505. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  2506. var node = nodes[reverse ? maxIndex - ii : ii];
  2507. if (node && node.iterate(fn, reverse) === false) {
  2508. return false;
  2509. }
  2510. }
  2511. };
  2512. // eslint-disable-next-line no-unused-vars
  2513. ValueNode.prototype.iterate = function (fn, reverse) {
  2514. return fn(this.entry);
  2515. };
  2516. var MapIterator = /*@__PURE__*/(function (Iterator) {
  2517. function MapIterator(map, type, reverse) {
  2518. this._type = type;
  2519. this._reverse = reverse;
  2520. this._stack = map._root && mapIteratorFrame(map._root);
  2521. }
  2522. if ( Iterator ) MapIterator.__proto__ = Iterator;
  2523. MapIterator.prototype = Object.create( Iterator && Iterator.prototype );
  2524. MapIterator.prototype.constructor = MapIterator;
  2525. MapIterator.prototype.next = function next () {
  2526. var type = this._type;
  2527. var stack = this._stack;
  2528. while (stack) {
  2529. var node = stack.node;
  2530. var index = stack.index++;
  2531. var maxIndex = (void 0);
  2532. if (node.entry) {
  2533. if (index === 0) {
  2534. return mapIteratorValue(type, node.entry);
  2535. }
  2536. } else if (node.entries) {
  2537. maxIndex = node.entries.length - 1;
  2538. if (index <= maxIndex) {
  2539. return mapIteratorValue(
  2540. type,
  2541. node.entries[this._reverse ? maxIndex - index : index]
  2542. );
  2543. }
  2544. } else {
  2545. maxIndex = node.nodes.length - 1;
  2546. if (index <= maxIndex) {
  2547. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  2548. if (subNode) {
  2549. if (subNode.entry) {
  2550. return mapIteratorValue(type, subNode.entry);
  2551. }
  2552. stack = this._stack = mapIteratorFrame(subNode, stack);
  2553. }
  2554. continue;
  2555. }
  2556. }
  2557. stack = this._stack = this._stack.__prev;
  2558. }
  2559. return iteratorDone();
  2560. };
  2561. return MapIterator;
  2562. }(Iterator));
  2563. function mapIteratorValue(type, entry) {
  2564. return iteratorValue(type, entry[0], entry[1]);
  2565. }
  2566. function mapIteratorFrame(node, prev) {
  2567. return {
  2568. node: node,
  2569. index: 0,
  2570. __prev: prev,
  2571. };
  2572. }
  2573. function makeMap(size, root, ownerID, hash) {
  2574. var map = Object.create(MapPrototype);
  2575. map.size = size;
  2576. map._root = root;
  2577. map.__ownerID = ownerID;
  2578. map.__hash = hash;
  2579. map.__altered = false;
  2580. return map;
  2581. }
  2582. var EMPTY_MAP;
  2583. function emptyMap() {
  2584. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  2585. }
  2586. function updateMap(map, k, v) {
  2587. var newRoot;
  2588. var newSize;
  2589. if (!map._root) {
  2590. if (v === NOT_SET) {
  2591. return map;
  2592. }
  2593. newSize = 1;
  2594. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  2595. } else {
  2596. var didChangeSize = MakeRef();
  2597. var didAlter = MakeRef();
  2598. newRoot = updateNode(
  2599. map._root,
  2600. map.__ownerID,
  2601. 0,
  2602. undefined,
  2603. k,
  2604. v,
  2605. didChangeSize,
  2606. didAlter
  2607. );
  2608. if (!didAlter.value) {
  2609. return map;
  2610. }
  2611. newSize = map.size + (didChangeSize.value ? (v === NOT_SET ? -1 : 1) : 0);
  2612. }
  2613. if (map.__ownerID) {
  2614. map.size = newSize;
  2615. map._root = newRoot;
  2616. map.__hash = undefined;
  2617. map.__altered = true;
  2618. return map;
  2619. }
  2620. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  2621. }
  2622. function updateNode(
  2623. node,
  2624. ownerID,
  2625. shift,
  2626. keyHash,
  2627. key,
  2628. value,
  2629. didChangeSize,
  2630. didAlter
  2631. ) {
  2632. if (!node) {
  2633. if (value === NOT_SET) {
  2634. return node;
  2635. }
  2636. SetRef(didAlter);
  2637. SetRef(didChangeSize);
  2638. return new ValueNode(ownerID, keyHash, [key, value]);
  2639. }
  2640. return node.update(
  2641. ownerID,
  2642. shift,
  2643. keyHash,
  2644. key,
  2645. value,
  2646. didChangeSize,
  2647. didAlter
  2648. );
  2649. }
  2650. function isLeafNode(node) {
  2651. return (
  2652. node.constructor === ValueNode || node.constructor === HashCollisionNode
  2653. );
  2654. }
  2655. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  2656. if (node.keyHash === keyHash) {
  2657. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  2658. }
  2659. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  2660. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  2661. var newNode;
  2662. var nodes =
  2663. idx1 === idx2
  2664. ? [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)]
  2665. : ((newNode = new ValueNode(ownerID, keyHash, entry)),
  2666. idx1 < idx2 ? [node, newNode] : [newNode, node]);
  2667. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  2668. }
  2669. function createNodes(ownerID, entries, key, value) {
  2670. if (!ownerID) {
  2671. ownerID = new OwnerID();
  2672. }
  2673. var node = new ValueNode(ownerID, hash(key), [key, value]);
  2674. for (var ii = 0; ii < entries.length; ii++) {
  2675. var entry = entries[ii];
  2676. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  2677. }
  2678. return node;
  2679. }
  2680. function packNodes(ownerID, nodes, count, excluding) {
  2681. var bitmap = 0;
  2682. var packedII = 0;
  2683. var packedNodes = new Array(count);
  2684. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  2685. var node = nodes[ii];
  2686. if (node !== undefined && ii !== excluding) {
  2687. bitmap |= bit;
  2688. packedNodes[packedII++] = node;
  2689. }
  2690. }
  2691. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  2692. }
  2693. function expandNodes(ownerID, nodes, bitmap, including, node) {
  2694. var count = 0;
  2695. var expandedNodes = new Array(SIZE);
  2696. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  2697. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  2698. }
  2699. expandedNodes[including] = node;
  2700. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  2701. }
  2702. function popCount(x) {
  2703. x -= (x >> 1) & 0x55555555;
  2704. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  2705. x = (x + (x >> 4)) & 0x0f0f0f0f;
  2706. x += x >> 8;
  2707. x += x >> 16;
  2708. return x & 0x7f;
  2709. }
  2710. function setAt(array, idx, val, canEdit) {
  2711. var newArray = canEdit ? array : arrCopy(array);
  2712. newArray[idx] = val;
  2713. return newArray;
  2714. }
  2715. function spliceIn(array, idx, val, canEdit) {
  2716. var newLen = array.length + 1;
  2717. if (canEdit && idx + 1 === newLen) {
  2718. array[idx] = val;
  2719. return array;
  2720. }
  2721. var newArray = new Array(newLen);
  2722. var after = 0;
  2723. for (var ii = 0; ii < newLen; ii++) {
  2724. if (ii === idx) {
  2725. newArray[ii] = val;
  2726. after = -1;
  2727. } else {
  2728. newArray[ii] = array[ii + after];
  2729. }
  2730. }
  2731. return newArray;
  2732. }
  2733. function spliceOut(array, idx, canEdit) {
  2734. var newLen = array.length - 1;
  2735. if (canEdit && idx === newLen) {
  2736. array.pop();
  2737. return array;
  2738. }
  2739. var newArray = new Array(newLen);
  2740. var after = 0;
  2741. for (var ii = 0; ii < newLen; ii++) {
  2742. if (ii === idx) {
  2743. after = 1;
  2744. }
  2745. newArray[ii] = array[ii + after];
  2746. }
  2747. return newArray;
  2748. }
  2749. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  2750. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  2751. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  2752. var IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
  2753. function isList(maybeList) {
  2754. return Boolean(maybeList && maybeList[IS_LIST_SYMBOL]);
  2755. }
  2756. var List = /*@__PURE__*/(function (IndexedCollection) {
  2757. function List(value) {
  2758. var empty = emptyList();
  2759. if (value === undefined || value === null) {
  2760. return empty;
  2761. }
  2762. if (isList(value)) {
  2763. return value;
  2764. }
  2765. var iter = IndexedCollection(value);
  2766. var size = iter.size;
  2767. if (size === 0) {
  2768. return empty;
  2769. }
  2770. assertNotInfinite(size);
  2771. if (size > 0 && size < SIZE) {
  2772. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  2773. }
  2774. return empty.withMutations(function (list) {
  2775. list.setSize(size);
  2776. iter.forEach(function (v, i) { return list.set(i, v); });
  2777. });
  2778. }
  2779. if ( IndexedCollection ) List.__proto__ = IndexedCollection;
  2780. List.prototype = Object.create( IndexedCollection && IndexedCollection.prototype );
  2781. List.prototype.constructor = List;
  2782. List.of = function of (/*...values*/) {
  2783. return this(arguments);
  2784. };
  2785. List.prototype.toString = function toString () {
  2786. return this.__toString('List [', ']');
  2787. };
  2788. // @pragma Access
  2789. List.prototype.get = function get (index, notSetValue) {
  2790. index = wrapIndex(this, index);
  2791. if (index >= 0 && index < this.size) {
  2792. index += this._origin;
  2793. var node = listNodeFor(this, index);
  2794. return node && node.array[index & MASK];
  2795. }
  2796. return notSetValue;
  2797. };
  2798. // @pragma Modification
  2799. List.prototype.set = function set (index, value) {
  2800. return updateList(this, index, value);
  2801. };
  2802. List.prototype.remove = function remove (index) {
  2803. return !this.has(index)
  2804. ? this
  2805. : index === 0
  2806. ? this.shift()
  2807. : index === this.size - 1
  2808. ? this.pop()
  2809. : this.splice(index, 1);
  2810. };
  2811. List.prototype.insert = function insert (index, value) {
  2812. return this.splice(index, 0, value);
  2813. };
  2814. List.prototype.clear = function clear () {
  2815. if (this.size === 0) {
  2816. return this;
  2817. }
  2818. if (this.__ownerID) {
  2819. this.size = this._origin = this._capacity = 0;
  2820. this._level = SHIFT;
  2821. this._root = this._tail = this.__hash = undefined;
  2822. this.__altered = true;
  2823. return this;
  2824. }
  2825. return emptyList();
  2826. };
  2827. List.prototype.push = function push (/*...values*/) {
  2828. var values = arguments;
  2829. var oldSize = this.size;
  2830. return this.withMutations(function (list) {
  2831. setListBounds(list, 0, oldSize + values.length);
  2832. for (var ii = 0; ii < values.length; ii++) {
  2833. list.set(oldSize + ii, values[ii]);
  2834. }
  2835. });
  2836. };
  2837. List.prototype.pop = function pop () {
  2838. return setListBounds(this, 0, -1);
  2839. };
  2840. List.prototype.unshift = function unshift (/*...values*/) {
  2841. var values = arguments;
  2842. return this.withMutations(function (list) {
  2843. setListBounds(list, -values.length);
  2844. for (var ii = 0; ii < values.length; ii++) {
  2845. list.set(ii, values[ii]);
  2846. }
  2847. });
  2848. };
  2849. List.prototype.shift = function shift () {
  2850. return setListBounds(this, 1);
  2851. };
  2852. // @pragma Composition
  2853. List.prototype.concat = function concat (/*...collections*/) {
  2854. var arguments$1 = arguments;
  2855. var seqs = [];
  2856. for (var i = 0; i < arguments.length; i++) {
  2857. var argument = arguments$1[i];
  2858. var seq = IndexedCollection(
  2859. typeof argument !== 'string' && hasIterator(argument)
  2860. ? argument
  2861. : [argument]
  2862. );
  2863. if (seq.size !== 0) {
  2864. seqs.push(seq);
  2865. }
  2866. }
  2867. if (seqs.length === 0) {
  2868. return this;
  2869. }
  2870. if (this.size === 0 && !this.__ownerID && seqs.length === 1) {
  2871. return this.constructor(seqs[0]);
  2872. }
  2873. return this.withMutations(function (list) {
  2874. seqs.forEach(function (seq) { return seq.forEach(function (value) { return list.push(value); }); });
  2875. });
  2876. };
  2877. List.prototype.setSize = function setSize (size) {
  2878. return setListBounds(this, 0, size);
  2879. };
  2880. List.prototype.map = function map (mapper, context) {
  2881. var this$1$1 = this;
  2882. return this.withMutations(function (list) {
  2883. for (var i = 0; i < this$1$1.size; i++) {
  2884. list.set(i, mapper.call(context, list.get(i), i, this$1$1));
  2885. }
  2886. });
  2887. };
  2888. // @pragma Iteration
  2889. List.prototype.slice = function slice (begin, end) {
  2890. var size = this.size;
  2891. if (wholeSlice(begin, end, size)) {
  2892. return this;
  2893. }
  2894. return setListBounds(
  2895. this,
  2896. resolveBegin(begin, size),
  2897. resolveEnd(end, size)
  2898. );
  2899. };
  2900. List.prototype.__iterator = function __iterator (type, reverse) {
  2901. var index = reverse ? this.size : 0;
  2902. var values = iterateList(this, reverse);
  2903. return new Iterator(function () {
  2904. var value = values();
  2905. return value === DONE
  2906. ? iteratorDone()
  2907. : iteratorValue(type, reverse ? --index : index++, value);
  2908. });
  2909. };
  2910. List.prototype.__iterate = function __iterate (fn, reverse) {
  2911. var index = reverse ? this.size : 0;
  2912. var values = iterateList(this, reverse);
  2913. var value;
  2914. while ((value = values()) !== DONE) {
  2915. if (fn(value, reverse ? --index : index++, this) === false) {
  2916. break;
  2917. }
  2918. }
  2919. return index;
  2920. };
  2921. List.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  2922. if (ownerID === this.__ownerID) {
  2923. return this;
  2924. }
  2925. if (!ownerID) {
  2926. if (this.size === 0) {
  2927. return emptyList();
  2928. }
  2929. this.__ownerID = ownerID;
  2930. this.__altered = false;
  2931. return this;
  2932. }
  2933. return makeList(
  2934. this._origin,
  2935. this._capacity,
  2936. this._level,
  2937. this._root,
  2938. this._tail,
  2939. ownerID,
  2940. this.__hash
  2941. );
  2942. };
  2943. return List;
  2944. }(IndexedCollection));
  2945. List.isList = isList;
  2946. var ListPrototype = List.prototype;
  2947. ListPrototype[IS_LIST_SYMBOL] = true;
  2948. ListPrototype[DELETE] = ListPrototype.remove;
  2949. ListPrototype.merge = ListPrototype.concat;
  2950. ListPrototype.setIn = setIn;
  2951. ListPrototype.deleteIn = ListPrototype.removeIn = deleteIn;
  2952. ListPrototype.update = update;
  2953. ListPrototype.updateIn = updateIn;
  2954. ListPrototype.mergeIn = mergeIn;
  2955. ListPrototype.mergeDeepIn = mergeDeepIn;
  2956. ListPrototype.withMutations = withMutations;
  2957. ListPrototype.wasAltered = wasAltered;
  2958. ListPrototype.asImmutable = asImmutable;
  2959. ListPrototype['@@transducer/init'] = ListPrototype.asMutable = asMutable;
  2960. ListPrototype['@@transducer/step'] = function (result, arr) {
  2961. return result.push(arr);
  2962. };
  2963. ListPrototype['@@transducer/result'] = function (obj) {
  2964. return obj.asImmutable();
  2965. };
  2966. var VNode = function VNode(array, ownerID) {
  2967. this.array = array;
  2968. this.ownerID = ownerID;
  2969. };
  2970. // TODO: seems like these methods are very similar
  2971. VNode.prototype.removeBefore = function removeBefore (ownerID, level, index) {
  2972. if (index === level ? 1 << level : this.array.length === 0) {
  2973. return this;
  2974. }
  2975. var originIndex = (index >>> level) & MASK;
  2976. if (originIndex >= this.array.length) {
  2977. return new VNode([], ownerID);
  2978. }
  2979. var removingFirst = originIndex === 0;
  2980. var newChild;
  2981. if (level > 0) {
  2982. var oldChild = this.array[originIndex];
  2983. newChild =
  2984. oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  2985. if (newChild === oldChild && removingFirst) {
  2986. return this;
  2987. }
  2988. }
  2989. if (removingFirst && !newChild) {
  2990. return this;
  2991. }
  2992. var editable = editableVNode(this, ownerID);
  2993. if (!removingFirst) {
  2994. for (var ii = 0; ii < originIndex; ii++) {
  2995. editable.array[ii] = undefined;
  2996. }
  2997. }
  2998. if (newChild) {
  2999. editable.array[originIndex] = newChild;
  3000. }
  3001. return editable;
  3002. };
  3003. VNode.prototype.removeAfter = function removeAfter (ownerID, level, index) {
  3004. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  3005. return this;
  3006. }
  3007. var sizeIndex = ((index - 1) >>> level) & MASK;
  3008. if (sizeIndex >= this.array.length) {
  3009. return this;
  3010. }
  3011. var newChild;
  3012. if (level > 0) {
  3013. var oldChild = this.array[sizeIndex];
  3014. newChild =
  3015. oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  3016. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  3017. return this;
  3018. }
  3019. }
  3020. var editable = editableVNode(this, ownerID);
  3021. editable.array.splice(sizeIndex + 1);
  3022. if (newChild) {
  3023. editable.array[sizeIndex] = newChild;
  3024. }
  3025. return editable;
  3026. };
  3027. var DONE = {};
  3028. function iterateList(list, reverse) {
  3029. var left = list._origin;
  3030. var right = list._capacity;
  3031. var tailPos = getTailOffset(right);
  3032. var tail = list._tail;
  3033. return iterateNodeOrLeaf(list._root, list._level, 0);
  3034. function iterateNodeOrLeaf(node, level, offset) {
  3035. return level === 0
  3036. ? iterateLeaf(node, offset)
  3037. : iterateNode(node, level, offset);
  3038. }
  3039. function iterateLeaf(node, offset) {
  3040. var array = offset === tailPos ? tail && tail.array : node && node.array;
  3041. var from = offset > left ? 0 : left - offset;
  3042. var to = right - offset;
  3043. if (to > SIZE) {
  3044. to = SIZE;
  3045. }
  3046. return function () {
  3047. if (from === to) {
  3048. return DONE;
  3049. }
  3050. var idx = reverse ? --to : from++;
  3051. return array && array[idx];
  3052. };
  3053. }
  3054. function iterateNode(node, level, offset) {
  3055. var values;
  3056. var array = node && node.array;
  3057. var from = offset > left ? 0 : (left - offset) >> level;
  3058. var to = ((right - offset) >> level) + 1;
  3059. if (to > SIZE) {
  3060. to = SIZE;
  3061. }
  3062. return function () {
  3063. while (true) {
  3064. if (values) {
  3065. var value = values();
  3066. if (value !== DONE) {
  3067. return value;
  3068. }
  3069. values = null;
  3070. }
  3071. if (from === to) {
  3072. return DONE;
  3073. }
  3074. var idx = reverse ? --to : from++;
  3075. values = iterateNodeOrLeaf(
  3076. array && array[idx],
  3077. level - SHIFT,
  3078. offset + (idx << level)
  3079. );
  3080. }
  3081. };
  3082. }
  3083. }
  3084. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  3085. var list = Object.create(ListPrototype);
  3086. list.size = capacity - origin;
  3087. list._origin = origin;
  3088. list._capacity = capacity;
  3089. list._level = level;
  3090. list._root = root;
  3091. list._tail = tail;
  3092. list.__ownerID = ownerID;
  3093. list.__hash = hash;
  3094. list.__altered = false;
  3095. return list;
  3096. }
  3097. var EMPTY_LIST;
  3098. function emptyList() {
  3099. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  3100. }
  3101. function updateList(list, index, value) {
  3102. index = wrapIndex(list, index);
  3103. if (index !== index) {
  3104. return list;
  3105. }
  3106. if (index >= list.size || index < 0) {
  3107. return list.withMutations(function (list) {
  3108. index < 0
  3109. ? setListBounds(list, index).set(0, value)
  3110. : setListBounds(list, 0, index + 1).set(index, value);
  3111. });
  3112. }
  3113. index += list._origin;
  3114. var newTail = list._tail;
  3115. var newRoot = list._root;
  3116. var didAlter = MakeRef();
  3117. if (index >= getTailOffset(list._capacity)) {
  3118. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  3119. } else {
  3120. newRoot = updateVNode(
  3121. newRoot,
  3122. list.__ownerID,
  3123. list._level,
  3124. index,
  3125. value,
  3126. didAlter
  3127. );
  3128. }
  3129. if (!didAlter.value) {
  3130. return list;
  3131. }
  3132. if (list.__ownerID) {
  3133. list._root = newRoot;
  3134. list._tail = newTail;
  3135. list.__hash = undefined;
  3136. list.__altered = true;
  3137. return list;
  3138. }
  3139. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  3140. }
  3141. function updateVNode(node, ownerID, level, index, value, didAlter) {
  3142. var idx = (index >>> level) & MASK;
  3143. var nodeHas = node && idx < node.array.length;
  3144. if (!nodeHas && value === undefined) {
  3145. return node;
  3146. }
  3147. var newNode;
  3148. if (level > 0) {
  3149. var lowerNode = node && node.array[idx];
  3150. var newLowerNode = updateVNode(
  3151. lowerNode,
  3152. ownerID,
  3153. level - SHIFT,
  3154. index,
  3155. value,
  3156. didAlter
  3157. );
  3158. if (newLowerNode === lowerNode) {
  3159. return node;
  3160. }
  3161. newNode = editableVNode(node, ownerID);
  3162. newNode.array[idx] = newLowerNode;
  3163. return newNode;
  3164. }
  3165. if (nodeHas && node.array[idx] === value) {
  3166. return node;
  3167. }
  3168. if (didAlter) {
  3169. SetRef(didAlter);
  3170. }
  3171. newNode = editableVNode(node, ownerID);
  3172. if (value === undefined && idx === newNode.array.length - 1) {
  3173. newNode.array.pop();
  3174. } else {
  3175. newNode.array[idx] = value;
  3176. }
  3177. return newNode;
  3178. }
  3179. function editableVNode(node, ownerID) {
  3180. if (ownerID && node && ownerID === node.ownerID) {
  3181. return node;
  3182. }
  3183. return new VNode(node ? node.array.slice() : [], ownerID);
  3184. }
  3185. function listNodeFor(list, rawIndex) {
  3186. if (rawIndex >= getTailOffset(list._capacity)) {
  3187. return list._tail;
  3188. }
  3189. if (rawIndex < 1 << (list._level + SHIFT)) {
  3190. var node = list._root;
  3191. var level = list._level;
  3192. while (node && level > 0) {
  3193. node = node.array[(rawIndex >>> level) & MASK];
  3194. level -= SHIFT;
  3195. }
  3196. return node;
  3197. }
  3198. }
  3199. function setListBounds(list, begin, end) {
  3200. // Sanitize begin & end using this shorthand for ToInt32(argument)
  3201. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  3202. if (begin !== undefined) {
  3203. begin |= 0;
  3204. }
  3205. if (end !== undefined) {
  3206. end |= 0;
  3207. }
  3208. var owner = list.__ownerID || new OwnerID();
  3209. var oldOrigin = list._origin;
  3210. var oldCapacity = list._capacity;
  3211. var newOrigin = oldOrigin + begin;
  3212. var newCapacity =
  3213. end === undefined
  3214. ? oldCapacity
  3215. : end < 0
  3216. ? oldCapacity + end
  3217. : oldOrigin + end;
  3218. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  3219. return list;
  3220. }
  3221. // If it's going to end after it starts, it's empty.
  3222. if (newOrigin >= newCapacity) {
  3223. return list.clear();
  3224. }
  3225. var newLevel = list._level;
  3226. var newRoot = list._root;
  3227. // New origin might need creating a higher root.
  3228. var offsetShift = 0;
  3229. while (newOrigin + offsetShift < 0) {
  3230. newRoot = new VNode(
  3231. newRoot && newRoot.array.length ? [undefined, newRoot] : [],
  3232. owner
  3233. );
  3234. newLevel += SHIFT;
  3235. offsetShift += 1 << newLevel;
  3236. }
  3237. if (offsetShift) {
  3238. newOrigin += offsetShift;
  3239. oldOrigin += offsetShift;
  3240. newCapacity += offsetShift;
  3241. oldCapacity += offsetShift;
  3242. }
  3243. var oldTailOffset = getTailOffset(oldCapacity);
  3244. var newTailOffset = getTailOffset(newCapacity);
  3245. // New size might need creating a higher root.
  3246. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  3247. newRoot = new VNode(
  3248. newRoot && newRoot.array.length ? [newRoot] : [],
  3249. owner
  3250. );
  3251. newLevel += SHIFT;
  3252. }
  3253. // Locate or create the new tail.
  3254. var oldTail = list._tail;
  3255. var newTail =
  3256. newTailOffset < oldTailOffset
  3257. ? listNodeFor(list, newCapacity - 1)
  3258. : newTailOffset > oldTailOffset
  3259. ? new VNode([], owner)
  3260. : oldTail;
  3261. // Merge Tail into tree.
  3262. if (
  3263. oldTail &&
  3264. newTailOffset > oldTailOffset &&
  3265. newOrigin < oldCapacity &&
  3266. oldTail.array.length
  3267. ) {
  3268. newRoot = editableVNode(newRoot, owner);
  3269. var node = newRoot;
  3270. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  3271. var idx = (oldTailOffset >>> level) & MASK;
  3272. node = node.array[idx] = editableVNode(node.array[idx], owner);
  3273. }
  3274. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  3275. }
  3276. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  3277. if (newCapacity < oldCapacity) {
  3278. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  3279. }
  3280. // If the new origin is within the tail, then we do not need a root.
  3281. if (newOrigin >= newTailOffset) {
  3282. newOrigin -= newTailOffset;
  3283. newCapacity -= newTailOffset;
  3284. newLevel = SHIFT;
  3285. newRoot = null;
  3286. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  3287. // Otherwise, if the root has been trimmed, garbage collect.
  3288. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  3289. offsetShift = 0;
  3290. // Identify the new top root node of the subtree of the old root.
  3291. while (newRoot) {
  3292. var beginIndex = (newOrigin >>> newLevel) & MASK;
  3293. if ((beginIndex !== newTailOffset >>> newLevel) & MASK) {
  3294. break;
  3295. }
  3296. if (beginIndex) {
  3297. offsetShift += (1 << newLevel) * beginIndex;
  3298. }
  3299. newLevel -= SHIFT;
  3300. newRoot = newRoot.array[beginIndex];
  3301. }
  3302. // Trim the new sides of the new root.
  3303. if (newRoot && newOrigin > oldOrigin) {
  3304. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  3305. }
  3306. if (newRoot && newTailOffset < oldTailOffset) {
  3307. newRoot = newRoot.removeAfter(
  3308. owner,
  3309. newLevel,
  3310. newTailOffset - offsetShift
  3311. );
  3312. }
  3313. if (offsetShift) {
  3314. newOrigin -= offsetShift;
  3315. newCapacity -= offsetShift;
  3316. }
  3317. }
  3318. if (list.__ownerID) {
  3319. list.size = newCapacity - newOrigin;
  3320. list._origin = newOrigin;
  3321. list._capacity = newCapacity;
  3322. list._level = newLevel;
  3323. list._root = newRoot;
  3324. list._tail = newTail;
  3325. list.__hash = undefined;
  3326. list.__altered = true;
  3327. return list;
  3328. }
  3329. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  3330. }
  3331. function getTailOffset(size) {
  3332. return size < SIZE ? 0 : ((size - 1) >>> SHIFT) << SHIFT;
  3333. }
  3334. var OrderedMap = /*@__PURE__*/(function (Map) {
  3335. function OrderedMap(value) {
  3336. return value === undefined || value === null
  3337. ? emptyOrderedMap()
  3338. : isOrderedMap(value)
  3339. ? value
  3340. : emptyOrderedMap().withMutations(function (map) {
  3341. var iter = KeyedCollection(value);
  3342. assertNotInfinite(iter.size);
  3343. iter.forEach(function (v, k) { return map.set(k, v); });
  3344. });
  3345. }
  3346. if ( Map ) OrderedMap.__proto__ = Map;
  3347. OrderedMap.prototype = Object.create( Map && Map.prototype );
  3348. OrderedMap.prototype.constructor = OrderedMap;
  3349. OrderedMap.of = function of (/*...values*/) {
  3350. return this(arguments);
  3351. };
  3352. OrderedMap.prototype.toString = function toString () {
  3353. return this.__toString('OrderedMap {', '}');
  3354. };
  3355. // @pragma Access
  3356. OrderedMap.prototype.get = function get (k, notSetValue) {
  3357. var index = this._map.get(k);
  3358. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  3359. };
  3360. // @pragma Modification
  3361. OrderedMap.prototype.clear = function clear () {
  3362. if (this.size === 0) {
  3363. return this;
  3364. }
  3365. if (this.__ownerID) {
  3366. this.size = 0;
  3367. this._map.clear();
  3368. this._list.clear();
  3369. this.__altered = true;
  3370. return this;
  3371. }
  3372. return emptyOrderedMap();
  3373. };
  3374. OrderedMap.prototype.set = function set (k, v) {
  3375. return updateOrderedMap(this, k, v);
  3376. };
  3377. OrderedMap.prototype.remove = function remove (k) {
  3378. return updateOrderedMap(this, k, NOT_SET);
  3379. };
  3380. OrderedMap.prototype.__iterate = function __iterate (fn, reverse) {
  3381. var this$1$1 = this;
  3382. return this._list.__iterate(
  3383. function (entry) { return entry && fn(entry[1], entry[0], this$1$1); },
  3384. reverse
  3385. );
  3386. };
  3387. OrderedMap.prototype.__iterator = function __iterator (type, reverse) {
  3388. return this._list.fromEntrySeq().__iterator(type, reverse);
  3389. };
  3390. OrderedMap.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  3391. if (ownerID === this.__ownerID) {
  3392. return this;
  3393. }
  3394. var newMap = this._map.__ensureOwner(ownerID);
  3395. var newList = this._list.__ensureOwner(ownerID);
  3396. if (!ownerID) {
  3397. if (this.size === 0) {
  3398. return emptyOrderedMap();
  3399. }
  3400. this.__ownerID = ownerID;
  3401. this.__altered = false;
  3402. this._map = newMap;
  3403. this._list = newList;
  3404. return this;
  3405. }
  3406. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  3407. };
  3408. return OrderedMap;
  3409. }(Map));
  3410. OrderedMap.isOrderedMap = isOrderedMap;
  3411. OrderedMap.prototype[IS_ORDERED_SYMBOL] = true;
  3412. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  3413. function makeOrderedMap(map, list, ownerID, hash) {
  3414. var omap = Object.create(OrderedMap.prototype);
  3415. omap.size = map ? map.size : 0;
  3416. omap._map = map;
  3417. omap._list = list;
  3418. omap.__ownerID = ownerID;
  3419. omap.__hash = hash;
  3420. omap.__altered = false;
  3421. return omap;
  3422. }
  3423. var EMPTY_ORDERED_MAP;
  3424. function emptyOrderedMap() {
  3425. return (
  3426. EMPTY_ORDERED_MAP ||
  3427. (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()))
  3428. );
  3429. }
  3430. function updateOrderedMap(omap, k, v) {
  3431. var map = omap._map;
  3432. var list = omap._list;
  3433. var i = map.get(k);
  3434. var has = i !== undefined;
  3435. var newMap;
  3436. var newList;
  3437. if (v === NOT_SET) {
  3438. // removed
  3439. if (!has) {
  3440. return omap;
  3441. }
  3442. if (list.size >= SIZE && list.size >= map.size * 2) {
  3443. newList = list.filter(function (entry, idx) { return entry !== undefined && i !== idx; });
  3444. newMap = newList
  3445. .toKeyedSeq()
  3446. .map(function (entry) { return entry[0]; })
  3447. .flip()
  3448. .toMap();
  3449. if (omap.__ownerID) {
  3450. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  3451. }
  3452. } else {
  3453. newMap = map.remove(k);
  3454. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  3455. }
  3456. } else if (has) {
  3457. if (v === list.get(i)[1]) {
  3458. return omap;
  3459. }
  3460. newMap = map;
  3461. newList = list.set(i, [k, v]);
  3462. } else {
  3463. newMap = map.set(k, list.size);
  3464. newList = list.set(list.size, [k, v]);
  3465. }
  3466. if (omap.__ownerID) {
  3467. omap.size = newMap.size;
  3468. omap._map = newMap;
  3469. omap._list = newList;
  3470. omap.__hash = undefined;
  3471. omap.__altered = true;
  3472. return omap;
  3473. }
  3474. return makeOrderedMap(newMap, newList);
  3475. }
  3476. var IS_STACK_SYMBOL = '@@__IMMUTABLE_STACK__@@';
  3477. function isStack(maybeStack) {
  3478. return Boolean(maybeStack && maybeStack[IS_STACK_SYMBOL]);
  3479. }
  3480. var Stack = /*@__PURE__*/(function (IndexedCollection) {
  3481. function Stack(value) {
  3482. return value === undefined || value === null
  3483. ? emptyStack()
  3484. : isStack(value)
  3485. ? value
  3486. : emptyStack().pushAll(value);
  3487. }
  3488. if ( IndexedCollection ) Stack.__proto__ = IndexedCollection;
  3489. Stack.prototype = Object.create( IndexedCollection && IndexedCollection.prototype );
  3490. Stack.prototype.constructor = Stack;
  3491. Stack.of = function of (/*...values*/) {
  3492. return this(arguments);
  3493. };
  3494. Stack.prototype.toString = function toString () {
  3495. return this.__toString('Stack [', ']');
  3496. };
  3497. // @pragma Access
  3498. Stack.prototype.get = function get (index, notSetValue) {
  3499. var head = this._head;
  3500. index = wrapIndex(this, index);
  3501. while (head && index--) {
  3502. head = head.next;
  3503. }
  3504. return head ? head.value : notSetValue;
  3505. };
  3506. Stack.prototype.peek = function peek () {
  3507. return this._head && this._head.value;
  3508. };
  3509. // @pragma Modification
  3510. Stack.prototype.push = function push (/*...values*/) {
  3511. var arguments$1 = arguments;
  3512. if (arguments.length === 0) {
  3513. return this;
  3514. }
  3515. var newSize = this.size + arguments.length;
  3516. var head = this._head;
  3517. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  3518. head = {
  3519. value: arguments$1[ii],
  3520. next: head,
  3521. };
  3522. }
  3523. if (this.__ownerID) {
  3524. this.size = newSize;
  3525. this._head = head;
  3526. this.__hash = undefined;
  3527. this.__altered = true;
  3528. return this;
  3529. }
  3530. return makeStack(newSize, head);
  3531. };
  3532. Stack.prototype.pushAll = function pushAll (iter) {
  3533. iter = IndexedCollection(iter);
  3534. if (iter.size === 0) {
  3535. return this;
  3536. }
  3537. if (this.size === 0 && isStack(iter)) {
  3538. return iter;
  3539. }
  3540. assertNotInfinite(iter.size);
  3541. var newSize = this.size;
  3542. var head = this._head;
  3543. iter.__iterate(function (value) {
  3544. newSize++;
  3545. head = {
  3546. value: value,
  3547. next: head,
  3548. };
  3549. }, /* reverse */ true);
  3550. if (this.__ownerID) {
  3551. this.size = newSize;
  3552. this._head = head;
  3553. this.__hash = undefined;
  3554. this.__altered = true;
  3555. return this;
  3556. }
  3557. return makeStack(newSize, head);
  3558. };
  3559. Stack.prototype.pop = function pop () {
  3560. return this.slice(1);
  3561. };
  3562. Stack.prototype.clear = function clear () {
  3563. if (this.size === 0) {
  3564. return this;
  3565. }
  3566. if (this.__ownerID) {
  3567. this.size = 0;
  3568. this._head = undefined;
  3569. this.__hash = undefined;
  3570. this.__altered = true;
  3571. return this;
  3572. }
  3573. return emptyStack();
  3574. };
  3575. Stack.prototype.slice = function slice (begin, end) {
  3576. if (wholeSlice(begin, end, this.size)) {
  3577. return this;
  3578. }
  3579. var resolvedBegin = resolveBegin(begin, this.size);
  3580. var resolvedEnd = resolveEnd(end, this.size);
  3581. if (resolvedEnd !== this.size) {
  3582. // super.slice(begin, end);
  3583. return IndexedCollection.prototype.slice.call(this, begin, end);
  3584. }
  3585. var newSize = this.size - resolvedBegin;
  3586. var head = this._head;
  3587. while (resolvedBegin--) {
  3588. head = head.next;
  3589. }
  3590. if (this.__ownerID) {
  3591. this.size = newSize;
  3592. this._head = head;
  3593. this.__hash = undefined;
  3594. this.__altered = true;
  3595. return this;
  3596. }
  3597. return makeStack(newSize, head);
  3598. };
  3599. // @pragma Mutability
  3600. Stack.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  3601. if (ownerID === this.__ownerID) {
  3602. return this;
  3603. }
  3604. if (!ownerID) {
  3605. if (this.size === 0) {
  3606. return emptyStack();
  3607. }
  3608. this.__ownerID = ownerID;
  3609. this.__altered = false;
  3610. return this;
  3611. }
  3612. return makeStack(this.size, this._head, ownerID, this.__hash);
  3613. };
  3614. // @pragma Iteration
  3615. Stack.prototype.__iterate = function __iterate (fn, reverse) {
  3616. var this$1$1 = this;
  3617. if (reverse) {
  3618. return new ArraySeq(this.toArray()).__iterate(
  3619. function (v, k) { return fn(v, k, this$1$1); },
  3620. reverse
  3621. );
  3622. }
  3623. var iterations = 0;
  3624. var node = this._head;
  3625. while (node) {
  3626. if (fn(node.value, iterations++, this) === false) {
  3627. break;
  3628. }
  3629. node = node.next;
  3630. }
  3631. return iterations;
  3632. };
  3633. Stack.prototype.__iterator = function __iterator (type, reverse) {
  3634. if (reverse) {
  3635. return new ArraySeq(this.toArray()).__iterator(type, reverse);
  3636. }
  3637. var iterations = 0;
  3638. var node = this._head;
  3639. return new Iterator(function () {
  3640. if (node) {
  3641. var value = node.value;
  3642. node = node.next;
  3643. return iteratorValue(type, iterations++, value);
  3644. }
  3645. return iteratorDone();
  3646. });
  3647. };
  3648. return Stack;
  3649. }(IndexedCollection));
  3650. Stack.isStack = isStack;
  3651. var StackPrototype = Stack.prototype;
  3652. StackPrototype[IS_STACK_SYMBOL] = true;
  3653. StackPrototype.shift = StackPrototype.pop;
  3654. StackPrototype.unshift = StackPrototype.push;
  3655. StackPrototype.unshiftAll = StackPrototype.pushAll;
  3656. StackPrototype.withMutations = withMutations;
  3657. StackPrototype.wasAltered = wasAltered;
  3658. StackPrototype.asImmutable = asImmutable;
  3659. StackPrototype['@@transducer/init'] = StackPrototype.asMutable = asMutable;
  3660. StackPrototype['@@transducer/step'] = function (result, arr) {
  3661. return result.unshift(arr);
  3662. };
  3663. StackPrototype['@@transducer/result'] = function (obj) {
  3664. return obj.asImmutable();
  3665. };
  3666. function makeStack(size, head, ownerID, hash) {
  3667. var map = Object.create(StackPrototype);
  3668. map.size = size;
  3669. map._head = head;
  3670. map.__ownerID = ownerID;
  3671. map.__hash = hash;
  3672. map.__altered = false;
  3673. return map;
  3674. }
  3675. var EMPTY_STACK;
  3676. function emptyStack() {
  3677. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  3678. }
  3679. var IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
  3680. function isSet(maybeSet) {
  3681. return Boolean(maybeSet && maybeSet[IS_SET_SYMBOL]);
  3682. }
  3683. function isOrderedSet(maybeOrderedSet) {
  3684. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  3685. }
  3686. function deepEqual(a, b) {
  3687. if (a === b) {
  3688. return true;
  3689. }
  3690. if (
  3691. !isCollection(b) ||
  3692. (a.size !== undefined && b.size !== undefined && a.size !== b.size) ||
  3693. (a.__hash !== undefined &&
  3694. b.__hash !== undefined &&
  3695. a.__hash !== b.__hash) ||
  3696. isKeyed(a) !== isKeyed(b) ||
  3697. isIndexed(a) !== isIndexed(b) ||
  3698. isOrdered(a) !== isOrdered(b)
  3699. ) {
  3700. return false;
  3701. }
  3702. if (a.size === 0 && b.size === 0) {
  3703. return true;
  3704. }
  3705. var notAssociative = !isAssociative(a);
  3706. if (isOrdered(a)) {
  3707. var entries = a.entries();
  3708. return (
  3709. b.every(function (v, k) {
  3710. var entry = entries.next().value;
  3711. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  3712. }) && entries.next().done
  3713. );
  3714. }
  3715. var flipped = false;
  3716. if (a.size === undefined) {
  3717. if (b.size === undefined) {
  3718. if (typeof a.cacheResult === 'function') {
  3719. a.cacheResult();
  3720. }
  3721. } else {
  3722. flipped = true;
  3723. var _ = a;
  3724. a = b;
  3725. b = _;
  3726. }
  3727. }
  3728. var allEqual = true;
  3729. var bSize = b.__iterate(function (v, k) {
  3730. if (
  3731. notAssociative
  3732. ? !a.has(v)
  3733. : flipped
  3734. ? !is(v, a.get(k, NOT_SET))
  3735. : !is(a.get(k, NOT_SET), v)
  3736. ) {
  3737. allEqual = false;
  3738. return false;
  3739. }
  3740. });
  3741. return allEqual && a.size === bSize;
  3742. }
  3743. function mixin(ctor, methods) {
  3744. var keyCopier = function (key) {
  3745. ctor.prototype[key] = methods[key];
  3746. };
  3747. Object.keys(methods).forEach(keyCopier);
  3748. Object.getOwnPropertySymbols &&
  3749. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  3750. return ctor;
  3751. }
  3752. function toJS(value) {
  3753. if (!value || typeof value !== 'object') {
  3754. return value;
  3755. }
  3756. if (!isCollection(value)) {
  3757. if (!isDataStructure(value)) {
  3758. return value;
  3759. }
  3760. value = Seq(value);
  3761. }
  3762. if (isKeyed(value)) {
  3763. var result$1 = {};
  3764. value.__iterate(function (v, k) {
  3765. result$1[k] = toJS(v);
  3766. });
  3767. return result$1;
  3768. }
  3769. var result = [];
  3770. value.__iterate(function (v) {
  3771. result.push(toJS(v));
  3772. });
  3773. return result;
  3774. }
  3775. var Set = /*@__PURE__*/(function (SetCollection) {
  3776. function Set(value) {
  3777. return value === undefined || value === null
  3778. ? emptySet()
  3779. : isSet(value) && !isOrdered(value)
  3780. ? value
  3781. : emptySet().withMutations(function (set) {
  3782. var iter = SetCollection(value);
  3783. assertNotInfinite(iter.size);
  3784. iter.forEach(function (v) { return set.add(v); });
  3785. });
  3786. }
  3787. if ( SetCollection ) Set.__proto__ = SetCollection;
  3788. Set.prototype = Object.create( SetCollection && SetCollection.prototype );
  3789. Set.prototype.constructor = Set;
  3790. Set.of = function of (/*...values*/) {
  3791. return this(arguments);
  3792. };
  3793. Set.fromKeys = function fromKeys (value) {
  3794. return this(KeyedCollection(value).keySeq());
  3795. };
  3796. Set.intersect = function intersect (sets) {
  3797. sets = Collection(sets).toArray();
  3798. return sets.length
  3799. ? SetPrototype.intersect.apply(Set(sets.pop()), sets)
  3800. : emptySet();
  3801. };
  3802. Set.union = function union (sets) {
  3803. sets = Collection(sets).toArray();
  3804. return sets.length
  3805. ? SetPrototype.union.apply(Set(sets.pop()), sets)
  3806. : emptySet();
  3807. };
  3808. Set.prototype.toString = function toString () {
  3809. return this.__toString('Set {', '}');
  3810. };
  3811. // @pragma Access
  3812. Set.prototype.has = function has (value) {
  3813. return this._map.has(value);
  3814. };
  3815. // @pragma Modification
  3816. Set.prototype.add = function add (value) {
  3817. return updateSet(this, this._map.set(value, value));
  3818. };
  3819. Set.prototype.remove = function remove (value) {
  3820. return updateSet(this, this._map.remove(value));
  3821. };
  3822. Set.prototype.clear = function clear () {
  3823. return updateSet(this, this._map.clear());
  3824. };
  3825. // @pragma Composition
  3826. Set.prototype.map = function map (mapper, context) {
  3827. var this$1$1 = this;
  3828. // keep track if the set is altered by the map function
  3829. var didChanges = false;
  3830. var newMap = updateSet(
  3831. this,
  3832. this._map.mapEntries(function (ref) {
  3833. var v = ref[1];
  3834. var mapped = mapper.call(context, v, v, this$1$1);
  3835. if (mapped !== v) {
  3836. didChanges = true;
  3837. }
  3838. return [mapped, mapped];
  3839. }, context)
  3840. );
  3841. return didChanges ? newMap : this;
  3842. };
  3843. Set.prototype.union = function union () {
  3844. var iters = [], len = arguments.length;
  3845. while ( len-- ) iters[ len ] = arguments[ len ];
  3846. iters = iters.filter(function (x) { return x.size !== 0; });
  3847. if (iters.length === 0) {
  3848. return this;
  3849. }
  3850. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  3851. return this.constructor(iters[0]);
  3852. }
  3853. return this.withMutations(function (set) {
  3854. for (var ii = 0; ii < iters.length; ii++) {
  3855. SetCollection(iters[ii]).forEach(function (value) { return set.add(value); });
  3856. }
  3857. });
  3858. };
  3859. Set.prototype.intersect = function intersect () {
  3860. var iters = [], len = arguments.length;
  3861. while ( len-- ) iters[ len ] = arguments[ len ];
  3862. if (iters.length === 0) {
  3863. return this;
  3864. }
  3865. iters = iters.map(function (iter) { return SetCollection(iter); });
  3866. var toRemove = [];
  3867. this.forEach(function (value) {
  3868. if (!iters.every(function (iter) { return iter.includes(value); })) {
  3869. toRemove.push(value);
  3870. }
  3871. });
  3872. return this.withMutations(function (set) {
  3873. toRemove.forEach(function (value) {
  3874. set.remove(value);
  3875. });
  3876. });
  3877. };
  3878. Set.prototype.subtract = function subtract () {
  3879. var iters = [], len = arguments.length;
  3880. while ( len-- ) iters[ len ] = arguments[ len ];
  3881. if (iters.length === 0) {
  3882. return this;
  3883. }
  3884. iters = iters.map(function (iter) { return SetCollection(iter); });
  3885. var toRemove = [];
  3886. this.forEach(function (value) {
  3887. if (iters.some(function (iter) { return iter.includes(value); })) {
  3888. toRemove.push(value);
  3889. }
  3890. });
  3891. return this.withMutations(function (set) {
  3892. toRemove.forEach(function (value) {
  3893. set.remove(value);
  3894. });
  3895. });
  3896. };
  3897. Set.prototype.sort = function sort (comparator) {
  3898. // Late binding
  3899. return OrderedSet(sortFactory(this, comparator));
  3900. };
  3901. Set.prototype.sortBy = function sortBy (mapper, comparator) {
  3902. // Late binding
  3903. return OrderedSet(sortFactory(this, comparator, mapper));
  3904. };
  3905. Set.prototype.wasAltered = function wasAltered () {
  3906. return this._map.wasAltered();
  3907. };
  3908. Set.prototype.__iterate = function __iterate (fn, reverse) {
  3909. var this$1$1 = this;
  3910. return this._map.__iterate(function (k) { return fn(k, k, this$1$1); }, reverse);
  3911. };
  3912. Set.prototype.__iterator = function __iterator (type, reverse) {
  3913. return this._map.__iterator(type, reverse);
  3914. };
  3915. Set.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  3916. if (ownerID === this.__ownerID) {
  3917. return this;
  3918. }
  3919. var newMap = this._map.__ensureOwner(ownerID);
  3920. if (!ownerID) {
  3921. if (this.size === 0) {
  3922. return this.__empty();
  3923. }
  3924. this.__ownerID = ownerID;
  3925. this._map = newMap;
  3926. return this;
  3927. }
  3928. return this.__make(newMap, ownerID);
  3929. };
  3930. return Set;
  3931. }(SetCollection));
  3932. Set.isSet = isSet;
  3933. var SetPrototype = Set.prototype;
  3934. SetPrototype[IS_SET_SYMBOL] = true;
  3935. SetPrototype[DELETE] = SetPrototype.remove;
  3936. SetPrototype.merge = SetPrototype.concat = SetPrototype.union;
  3937. SetPrototype.withMutations = withMutations;
  3938. SetPrototype.asImmutable = asImmutable;
  3939. SetPrototype['@@transducer/init'] = SetPrototype.asMutable = asMutable;
  3940. SetPrototype['@@transducer/step'] = function (result, arr) {
  3941. return result.add(arr);
  3942. };
  3943. SetPrototype['@@transducer/result'] = function (obj) {
  3944. return obj.asImmutable();
  3945. };
  3946. SetPrototype.__empty = emptySet;
  3947. SetPrototype.__make = makeSet;
  3948. function updateSet(set, newMap) {
  3949. if (set.__ownerID) {
  3950. set.size = newMap.size;
  3951. set._map = newMap;
  3952. return set;
  3953. }
  3954. return newMap === set._map
  3955. ? set
  3956. : newMap.size === 0
  3957. ? set.__empty()
  3958. : set.__make(newMap);
  3959. }
  3960. function makeSet(map, ownerID) {
  3961. var set = Object.create(SetPrototype);
  3962. set.size = map ? map.size : 0;
  3963. set._map = map;
  3964. set.__ownerID = ownerID;
  3965. return set;
  3966. }
  3967. var EMPTY_SET;
  3968. function emptySet() {
  3969. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  3970. }
  3971. /**
  3972. * Returns a lazy seq of nums from start (inclusive) to end
  3973. * (exclusive), by step, where start defaults to 0, step to 1, and end to
  3974. * infinity. When start is equal to end, returns empty list.
  3975. */
  3976. var Range = /*@__PURE__*/(function (IndexedSeq) {
  3977. function Range(start, end, step) {
  3978. if (!(this instanceof Range)) {
  3979. return new Range(start, end, step);
  3980. }
  3981. invariant(step !== 0, 'Cannot step a Range by 0');
  3982. start = start || 0;
  3983. if (end === undefined) {
  3984. end = Infinity;
  3985. }
  3986. step = step === undefined ? 1 : Math.abs(step);
  3987. if (end < start) {
  3988. step = -step;
  3989. }
  3990. this._start = start;
  3991. this._end = end;
  3992. this._step = step;
  3993. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  3994. if (this.size === 0) {
  3995. if (EMPTY_RANGE) {
  3996. return EMPTY_RANGE;
  3997. }
  3998. EMPTY_RANGE = this;
  3999. }
  4000. }
  4001. if ( IndexedSeq ) Range.__proto__ = IndexedSeq;
  4002. Range.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  4003. Range.prototype.constructor = Range;
  4004. Range.prototype.toString = function toString () {
  4005. if (this.size === 0) {
  4006. return 'Range []';
  4007. }
  4008. return (
  4009. 'Range [ ' +
  4010. this._start +
  4011. '...' +
  4012. this._end +
  4013. (this._step !== 1 ? ' by ' + this._step : '') +
  4014. ' ]'
  4015. );
  4016. };
  4017. Range.prototype.get = function get (index, notSetValue) {
  4018. return this.has(index)
  4019. ? this._start + wrapIndex(this, index) * this._step
  4020. : notSetValue;
  4021. };
  4022. Range.prototype.includes = function includes (searchValue) {
  4023. var possibleIndex = (searchValue - this._start) / this._step;
  4024. return (
  4025. possibleIndex >= 0 &&
  4026. possibleIndex < this.size &&
  4027. possibleIndex === Math.floor(possibleIndex)
  4028. );
  4029. };
  4030. Range.prototype.slice = function slice (begin, end) {
  4031. if (wholeSlice(begin, end, this.size)) {
  4032. return this;
  4033. }
  4034. begin = resolveBegin(begin, this.size);
  4035. end = resolveEnd(end, this.size);
  4036. if (end <= begin) {
  4037. return new Range(0, 0);
  4038. }
  4039. return new Range(
  4040. this.get(begin, this._end),
  4041. this.get(end, this._end),
  4042. this._step
  4043. );
  4044. };
  4045. Range.prototype.indexOf = function indexOf (searchValue) {
  4046. var offsetValue = searchValue - this._start;
  4047. if (offsetValue % this._step === 0) {
  4048. var index = offsetValue / this._step;
  4049. if (index >= 0 && index < this.size) {
  4050. return index;
  4051. }
  4052. }
  4053. return -1;
  4054. };
  4055. Range.prototype.lastIndexOf = function lastIndexOf (searchValue) {
  4056. return this.indexOf(searchValue);
  4057. };
  4058. Range.prototype.__iterate = function __iterate (fn, reverse) {
  4059. var size = this.size;
  4060. var step = this._step;
  4061. var value = reverse ? this._start + (size - 1) * step : this._start;
  4062. var i = 0;
  4063. while (i !== size) {
  4064. if (fn(value, reverse ? size - ++i : i++, this) === false) {
  4065. break;
  4066. }
  4067. value += reverse ? -step : step;
  4068. }
  4069. return i;
  4070. };
  4071. Range.prototype.__iterator = function __iterator (type, reverse) {
  4072. var size = this.size;
  4073. var step = this._step;
  4074. var value = reverse ? this._start + (size - 1) * step : this._start;
  4075. var i = 0;
  4076. return new Iterator(function () {
  4077. if (i === size) {
  4078. return iteratorDone();
  4079. }
  4080. var v = value;
  4081. value += reverse ? -step : step;
  4082. return iteratorValue(type, reverse ? size - ++i : i++, v);
  4083. });
  4084. };
  4085. Range.prototype.equals = function equals (other) {
  4086. return other instanceof Range
  4087. ? this._start === other._start &&
  4088. this._end === other._end &&
  4089. this._step === other._step
  4090. : deepEqual(this, other);
  4091. };
  4092. return Range;
  4093. }(IndexedSeq));
  4094. var EMPTY_RANGE;
  4095. function getIn$1(collection, searchKeyPath, notSetValue) {
  4096. var keyPath = coerceKeyPath(searchKeyPath);
  4097. var i = 0;
  4098. while (i !== keyPath.length) {
  4099. collection = get(collection, keyPath[i++], NOT_SET);
  4100. if (collection === NOT_SET) {
  4101. return notSetValue;
  4102. }
  4103. }
  4104. return collection;
  4105. }
  4106. function getIn(searchKeyPath, notSetValue) {
  4107. return getIn$1(this, searchKeyPath, notSetValue);
  4108. }
  4109. function hasIn$1(collection, keyPath) {
  4110. return getIn$1(collection, keyPath, NOT_SET) !== NOT_SET;
  4111. }
  4112. function hasIn(searchKeyPath) {
  4113. return hasIn$1(this, searchKeyPath);
  4114. }
  4115. function toObject() {
  4116. assertNotInfinite(this.size);
  4117. var object = {};
  4118. this.__iterate(function (v, k) {
  4119. object[k] = v;
  4120. });
  4121. return object;
  4122. }
  4123. // Note: all of these methods are deprecated.
  4124. Collection.isIterable = isCollection;
  4125. Collection.isKeyed = isKeyed;
  4126. Collection.isIndexed = isIndexed;
  4127. Collection.isAssociative = isAssociative;
  4128. Collection.isOrdered = isOrdered;
  4129. Collection.Iterator = Iterator;
  4130. mixin(Collection, {
  4131. // ### Conversion to other types
  4132. toArray: function toArray() {
  4133. assertNotInfinite(this.size);
  4134. var array = new Array(this.size || 0);
  4135. var useTuples = isKeyed(this);
  4136. var i = 0;
  4137. this.__iterate(function (v, k) {
  4138. // Keyed collections produce an array of tuples.
  4139. array[i++] = useTuples ? [k, v] : v;
  4140. });
  4141. return array;
  4142. },
  4143. toIndexedSeq: function toIndexedSeq() {
  4144. return new ToIndexedSequence(this);
  4145. },
  4146. toJS: function toJS$1() {
  4147. return toJS(this);
  4148. },
  4149. toKeyedSeq: function toKeyedSeq() {
  4150. return new ToKeyedSequence(this, true);
  4151. },
  4152. toMap: function toMap() {
  4153. // Use Late Binding here to solve the circular dependency.
  4154. return Map(this.toKeyedSeq());
  4155. },
  4156. toObject: toObject,
  4157. toOrderedMap: function toOrderedMap() {
  4158. // Use Late Binding here to solve the circular dependency.
  4159. return OrderedMap(this.toKeyedSeq());
  4160. },
  4161. toOrderedSet: function toOrderedSet() {
  4162. // Use Late Binding here to solve the circular dependency.
  4163. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  4164. },
  4165. toSet: function toSet() {
  4166. // Use Late Binding here to solve the circular dependency.
  4167. return Set(isKeyed(this) ? this.valueSeq() : this);
  4168. },
  4169. toSetSeq: function toSetSeq() {
  4170. return new ToSetSequence(this);
  4171. },
  4172. toSeq: function toSeq() {
  4173. return isIndexed(this)
  4174. ? this.toIndexedSeq()
  4175. : isKeyed(this)
  4176. ? this.toKeyedSeq()
  4177. : this.toSetSeq();
  4178. },
  4179. toStack: function toStack() {
  4180. // Use Late Binding here to solve the circular dependency.
  4181. return Stack(isKeyed(this) ? this.valueSeq() : this);
  4182. },
  4183. toList: function toList() {
  4184. // Use Late Binding here to solve the circular dependency.
  4185. return List(isKeyed(this) ? this.valueSeq() : this);
  4186. },
  4187. // ### Common JavaScript methods and properties
  4188. toString: function toString() {
  4189. return '[Collection]';
  4190. },
  4191. __toString: function __toString(head, tail) {
  4192. if (this.size === 0) {
  4193. return head + tail;
  4194. }
  4195. return (
  4196. head +
  4197. ' ' +
  4198. this.toSeq().map(this.__toStringMapper).join(', ') +
  4199. ' ' +
  4200. tail
  4201. );
  4202. },
  4203. // ### ES6 Collection methods (ES6 Array and Map)
  4204. concat: function concat() {
  4205. var values = [], len = arguments.length;
  4206. while ( len-- ) values[ len ] = arguments[ len ];
  4207. return reify(this, concatFactory(this, values));
  4208. },
  4209. includes: function includes(searchValue) {
  4210. return this.some(function (value) { return is(value, searchValue); });
  4211. },
  4212. entries: function entries() {
  4213. return this.__iterator(ITERATE_ENTRIES);
  4214. },
  4215. every: function every(predicate, context) {
  4216. assertNotInfinite(this.size);
  4217. var returnValue = true;
  4218. this.__iterate(function (v, k, c) {
  4219. if (!predicate.call(context, v, k, c)) {
  4220. returnValue = false;
  4221. return false;
  4222. }
  4223. });
  4224. return returnValue;
  4225. },
  4226. filter: function filter(predicate, context) {
  4227. return reify(this, filterFactory(this, predicate, context, true));
  4228. },
  4229. find: function find(predicate, context, notSetValue) {
  4230. var entry = this.findEntry(predicate, context);
  4231. return entry ? entry[1] : notSetValue;
  4232. },
  4233. forEach: function forEach(sideEffect, context) {
  4234. assertNotInfinite(this.size);
  4235. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  4236. },
  4237. join: function join(separator) {
  4238. assertNotInfinite(this.size);
  4239. separator = separator !== undefined ? '' + separator : ',';
  4240. var joined = '';
  4241. var isFirst = true;
  4242. this.__iterate(function (v) {
  4243. isFirst ? (isFirst = false) : (joined += separator);
  4244. joined += v !== null && v !== undefined ? v.toString() : '';
  4245. });
  4246. return joined;
  4247. },
  4248. keys: function keys() {
  4249. return this.__iterator(ITERATE_KEYS);
  4250. },
  4251. map: function map(mapper, context) {
  4252. return reify(this, mapFactory(this, mapper, context));
  4253. },
  4254. reduce: function reduce$1(reducer, initialReduction, context) {
  4255. return reduce(
  4256. this,
  4257. reducer,
  4258. initialReduction,
  4259. context,
  4260. arguments.length < 2,
  4261. false
  4262. );
  4263. },
  4264. reduceRight: function reduceRight(reducer, initialReduction, context) {
  4265. return reduce(
  4266. this,
  4267. reducer,
  4268. initialReduction,
  4269. context,
  4270. arguments.length < 2,
  4271. true
  4272. );
  4273. },
  4274. reverse: function reverse() {
  4275. return reify(this, reverseFactory(this, true));
  4276. },
  4277. slice: function slice(begin, end) {
  4278. return reify(this, sliceFactory(this, begin, end, true));
  4279. },
  4280. some: function some(predicate, context) {
  4281. return !this.every(not(predicate), context);
  4282. },
  4283. sort: function sort(comparator) {
  4284. return reify(this, sortFactory(this, comparator));
  4285. },
  4286. values: function values() {
  4287. return this.__iterator(ITERATE_VALUES);
  4288. },
  4289. // ### More sequential methods
  4290. butLast: function butLast() {
  4291. return this.slice(0, -1);
  4292. },
  4293. isEmpty: function isEmpty() {
  4294. return this.size !== undefined ? this.size === 0 : !this.some(function () { return true; });
  4295. },
  4296. count: function count(predicate, context) {
  4297. return ensureSize(
  4298. predicate ? this.toSeq().filter(predicate, context) : this
  4299. );
  4300. },
  4301. countBy: function countBy(grouper, context) {
  4302. return countByFactory(this, grouper, context);
  4303. },
  4304. equals: function equals(other) {
  4305. return deepEqual(this, other);
  4306. },
  4307. entrySeq: function entrySeq() {
  4308. var collection = this;
  4309. if (collection._cache) {
  4310. // We cache as an entries array, so we can just return the cache!
  4311. return new ArraySeq(collection._cache);
  4312. }
  4313. var entriesSequence = collection.toSeq().map(entryMapper).toIndexedSeq();
  4314. entriesSequence.fromEntrySeq = function () { return collection.toSeq(); };
  4315. return entriesSequence;
  4316. },
  4317. filterNot: function filterNot(predicate, context) {
  4318. return this.filter(not(predicate), context);
  4319. },
  4320. findEntry: function findEntry(predicate, context, notSetValue) {
  4321. var found = notSetValue;
  4322. this.__iterate(function (v, k, c) {
  4323. if (predicate.call(context, v, k, c)) {
  4324. found = [k, v];
  4325. return false;
  4326. }
  4327. });
  4328. return found;
  4329. },
  4330. findKey: function findKey(predicate, context) {
  4331. var entry = this.findEntry(predicate, context);
  4332. return entry && entry[0];
  4333. },
  4334. findLast: function findLast(predicate, context, notSetValue) {
  4335. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  4336. },
  4337. findLastEntry: function findLastEntry(predicate, context, notSetValue) {
  4338. return this.toKeyedSeq()
  4339. .reverse()
  4340. .findEntry(predicate, context, notSetValue);
  4341. },
  4342. findLastKey: function findLastKey(predicate, context) {
  4343. return this.toKeyedSeq().reverse().findKey(predicate, context);
  4344. },
  4345. first: function first(notSetValue) {
  4346. return this.find(returnTrue, null, notSetValue);
  4347. },
  4348. flatMap: function flatMap(mapper, context) {
  4349. return reify(this, flatMapFactory(this, mapper, context));
  4350. },
  4351. flatten: function flatten(depth) {
  4352. return reify(this, flattenFactory(this, depth, true));
  4353. },
  4354. fromEntrySeq: function fromEntrySeq() {
  4355. return new FromEntriesSequence(this);
  4356. },
  4357. get: function get(searchKey, notSetValue) {
  4358. return this.find(function (_, key) { return is(key, searchKey); }, undefined, notSetValue);
  4359. },
  4360. getIn: getIn,
  4361. groupBy: function groupBy(grouper, context) {
  4362. return groupByFactory(this, grouper, context);
  4363. },
  4364. has: function has(searchKey) {
  4365. return this.get(searchKey, NOT_SET) !== NOT_SET;
  4366. },
  4367. hasIn: hasIn,
  4368. isSubset: function isSubset(iter) {
  4369. iter = typeof iter.includes === 'function' ? iter : Collection(iter);
  4370. return this.every(function (value) { return iter.includes(value); });
  4371. },
  4372. isSuperset: function isSuperset(iter) {
  4373. iter = typeof iter.isSubset === 'function' ? iter : Collection(iter);
  4374. return iter.isSubset(this);
  4375. },
  4376. keyOf: function keyOf(searchValue) {
  4377. return this.findKey(function (value) { return is(value, searchValue); });
  4378. },
  4379. keySeq: function keySeq() {
  4380. return this.toSeq().map(keyMapper).toIndexedSeq();
  4381. },
  4382. last: function last(notSetValue) {
  4383. return this.toSeq().reverse().first(notSetValue);
  4384. },
  4385. lastKeyOf: function lastKeyOf(searchValue) {
  4386. return this.toKeyedSeq().reverse().keyOf(searchValue);
  4387. },
  4388. max: function max(comparator) {
  4389. return maxFactory(this, comparator);
  4390. },
  4391. maxBy: function maxBy(mapper, comparator) {
  4392. return maxFactory(this, comparator, mapper);
  4393. },
  4394. min: function min(comparator) {
  4395. return maxFactory(
  4396. this,
  4397. comparator ? neg(comparator) : defaultNegComparator
  4398. );
  4399. },
  4400. minBy: function minBy(mapper, comparator) {
  4401. return maxFactory(
  4402. this,
  4403. comparator ? neg(comparator) : defaultNegComparator,
  4404. mapper
  4405. );
  4406. },
  4407. rest: function rest() {
  4408. return this.slice(1);
  4409. },
  4410. skip: function skip(amount) {
  4411. return amount === 0 ? this : this.slice(Math.max(0, amount));
  4412. },
  4413. skipLast: function skipLast(amount) {
  4414. return amount === 0 ? this : this.slice(0, -Math.max(0, amount));
  4415. },
  4416. skipWhile: function skipWhile(predicate, context) {
  4417. return reify(this, skipWhileFactory(this, predicate, context, true));
  4418. },
  4419. skipUntil: function skipUntil(predicate, context) {
  4420. return this.skipWhile(not(predicate), context);
  4421. },
  4422. sortBy: function sortBy(mapper, comparator) {
  4423. return reify(this, sortFactory(this, comparator, mapper));
  4424. },
  4425. take: function take(amount) {
  4426. return this.slice(0, Math.max(0, amount));
  4427. },
  4428. takeLast: function takeLast(amount) {
  4429. return this.slice(-Math.max(0, amount));
  4430. },
  4431. takeWhile: function takeWhile(predicate, context) {
  4432. return reify(this, takeWhileFactory(this, predicate, context));
  4433. },
  4434. takeUntil: function takeUntil(predicate, context) {
  4435. return this.takeWhile(not(predicate), context);
  4436. },
  4437. update: function update(fn) {
  4438. return fn(this);
  4439. },
  4440. valueSeq: function valueSeq() {
  4441. return this.toIndexedSeq();
  4442. },
  4443. // ### Hashable Object
  4444. hashCode: function hashCode() {
  4445. return this.__hash || (this.__hash = hashCollection(this));
  4446. },
  4447. // ### Internal
  4448. // abstract __iterate(fn, reverse)
  4449. // abstract __iterator(type, reverse)
  4450. });
  4451. var CollectionPrototype = Collection.prototype;
  4452. CollectionPrototype[IS_COLLECTION_SYMBOL] = true;
  4453. CollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.values;
  4454. CollectionPrototype.toJSON = CollectionPrototype.toArray;
  4455. CollectionPrototype.__toStringMapper = quoteString;
  4456. CollectionPrototype.inspect = CollectionPrototype.toSource = function () {
  4457. return this.toString();
  4458. };
  4459. CollectionPrototype.chain = CollectionPrototype.flatMap;
  4460. CollectionPrototype.contains = CollectionPrototype.includes;
  4461. mixin(KeyedCollection, {
  4462. // ### More sequential methods
  4463. flip: function flip() {
  4464. return reify(this, flipFactory(this));
  4465. },
  4466. mapEntries: function mapEntries(mapper, context) {
  4467. var this$1$1 = this;
  4468. var iterations = 0;
  4469. return reify(
  4470. this,
  4471. this.toSeq()
  4472. .map(function (v, k) { return mapper.call(context, [k, v], iterations++, this$1$1); })
  4473. .fromEntrySeq()
  4474. );
  4475. },
  4476. mapKeys: function mapKeys(mapper, context) {
  4477. var this$1$1 = this;
  4478. return reify(
  4479. this,
  4480. this.toSeq()
  4481. .flip()
  4482. .map(function (k, v) { return mapper.call(context, k, v, this$1$1); })
  4483. .flip()
  4484. );
  4485. },
  4486. });
  4487. var KeyedCollectionPrototype = KeyedCollection.prototype;
  4488. KeyedCollectionPrototype[IS_KEYED_SYMBOL] = true;
  4489. KeyedCollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.entries;
  4490. KeyedCollectionPrototype.toJSON = toObject;
  4491. KeyedCollectionPrototype.__toStringMapper = function (v, k) { return quoteString(k) + ': ' + quoteString(v); };
  4492. mixin(IndexedCollection, {
  4493. // ### Conversion to other types
  4494. toKeyedSeq: function toKeyedSeq() {
  4495. return new ToKeyedSequence(this, false);
  4496. },
  4497. // ### ES6 Collection methods (ES6 Array and Map)
  4498. filter: function filter(predicate, context) {
  4499. return reify(this, filterFactory(this, predicate, context, false));
  4500. },
  4501. findIndex: function findIndex(predicate, context) {
  4502. var entry = this.findEntry(predicate, context);
  4503. return entry ? entry[0] : -1;
  4504. },
  4505. indexOf: function indexOf(searchValue) {
  4506. var key = this.keyOf(searchValue);
  4507. return key === undefined ? -1 : key;
  4508. },
  4509. lastIndexOf: function lastIndexOf(searchValue) {
  4510. var key = this.lastKeyOf(searchValue);
  4511. return key === undefined ? -1 : key;
  4512. },
  4513. reverse: function reverse() {
  4514. return reify(this, reverseFactory(this, false));
  4515. },
  4516. slice: function slice(begin, end) {
  4517. return reify(this, sliceFactory(this, begin, end, false));
  4518. },
  4519. splice: function splice(index, removeNum /*, ...values*/) {
  4520. var numArgs = arguments.length;
  4521. removeNum = Math.max(removeNum || 0, 0);
  4522. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  4523. return this;
  4524. }
  4525. // If index is negative, it should resolve relative to the size of the
  4526. // collection. However size may be expensive to compute if not cached, so
  4527. // only call count() if the number is in fact negative.
  4528. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  4529. var spliced = this.slice(0, index);
  4530. return reify(
  4531. this,
  4532. numArgs === 1
  4533. ? spliced
  4534. : spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  4535. );
  4536. },
  4537. // ### More collection methods
  4538. findLastIndex: function findLastIndex(predicate, context) {
  4539. var entry = this.findLastEntry(predicate, context);
  4540. return entry ? entry[0] : -1;
  4541. },
  4542. first: function first(notSetValue) {
  4543. return this.get(0, notSetValue);
  4544. },
  4545. flatten: function flatten(depth) {
  4546. return reify(this, flattenFactory(this, depth, false));
  4547. },
  4548. get: function get(index, notSetValue) {
  4549. index = wrapIndex(this, index);
  4550. return index < 0 ||
  4551. this.size === Infinity ||
  4552. (this.size !== undefined && index > this.size)
  4553. ? notSetValue
  4554. : this.find(function (_, key) { return key === index; }, undefined, notSetValue);
  4555. },
  4556. has: function has(index) {
  4557. index = wrapIndex(this, index);
  4558. return (
  4559. index >= 0 &&
  4560. (this.size !== undefined
  4561. ? this.size === Infinity || index < this.size
  4562. : this.indexOf(index) !== -1)
  4563. );
  4564. },
  4565. interpose: function interpose(separator) {
  4566. return reify(this, interposeFactory(this, separator));
  4567. },
  4568. interleave: function interleave(/*...collections*/) {
  4569. var collections = [this].concat(arrCopy(arguments));
  4570. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, collections);
  4571. var interleaved = zipped.flatten(true);
  4572. if (zipped.size) {
  4573. interleaved.size = zipped.size * collections.length;
  4574. }
  4575. return reify(this, interleaved);
  4576. },
  4577. keySeq: function keySeq() {
  4578. return Range(0, this.size);
  4579. },
  4580. last: function last(notSetValue) {
  4581. return this.get(-1, notSetValue);
  4582. },
  4583. skipWhile: function skipWhile(predicate, context) {
  4584. return reify(this, skipWhileFactory(this, predicate, context, false));
  4585. },
  4586. zip: function zip(/*, ...collections */) {
  4587. var collections = [this].concat(arrCopy(arguments));
  4588. return reify(this, zipWithFactory(this, defaultZipper, collections));
  4589. },
  4590. zipAll: function zipAll(/*, ...collections */) {
  4591. var collections = [this].concat(arrCopy(arguments));
  4592. return reify(this, zipWithFactory(this, defaultZipper, collections, true));
  4593. },
  4594. zipWith: function zipWith(zipper /*, ...collections */) {
  4595. var collections = arrCopy(arguments);
  4596. collections[0] = this;
  4597. return reify(this, zipWithFactory(this, zipper, collections));
  4598. },
  4599. });
  4600. var IndexedCollectionPrototype = IndexedCollection.prototype;
  4601. IndexedCollectionPrototype[IS_INDEXED_SYMBOL] = true;
  4602. IndexedCollectionPrototype[IS_ORDERED_SYMBOL] = true;
  4603. mixin(SetCollection, {
  4604. // ### ES6 Collection methods (ES6 Array and Map)
  4605. get: function get(value, notSetValue) {
  4606. return this.has(value) ? value : notSetValue;
  4607. },
  4608. includes: function includes(value) {
  4609. return this.has(value);
  4610. },
  4611. // ### More sequential methods
  4612. keySeq: function keySeq() {
  4613. return this.valueSeq();
  4614. },
  4615. });
  4616. var SetCollectionPrototype = SetCollection.prototype;
  4617. SetCollectionPrototype.has = CollectionPrototype.includes;
  4618. SetCollectionPrototype.contains = SetCollectionPrototype.includes;
  4619. SetCollectionPrototype.keys = SetCollectionPrototype.values;
  4620. // Mixin subclasses
  4621. mixin(KeyedSeq, KeyedCollectionPrototype);
  4622. mixin(IndexedSeq, IndexedCollectionPrototype);
  4623. mixin(SetSeq, SetCollectionPrototype);
  4624. // #pragma Helper functions
  4625. function reduce(collection, reducer, reduction, context, useFirst, reverse) {
  4626. assertNotInfinite(collection.size);
  4627. collection.__iterate(function (v, k, c) {
  4628. if (useFirst) {
  4629. useFirst = false;
  4630. reduction = v;
  4631. } else {
  4632. reduction = reducer.call(context, reduction, v, k, c);
  4633. }
  4634. }, reverse);
  4635. return reduction;
  4636. }
  4637. function keyMapper(v, k) {
  4638. return k;
  4639. }
  4640. function entryMapper(v, k) {
  4641. return [k, v];
  4642. }
  4643. function not(predicate) {
  4644. return function () {
  4645. return !predicate.apply(this, arguments);
  4646. };
  4647. }
  4648. function neg(predicate) {
  4649. return function () {
  4650. return -predicate.apply(this, arguments);
  4651. };
  4652. }
  4653. function defaultZipper() {
  4654. return arrCopy(arguments);
  4655. }
  4656. function defaultNegComparator(a, b) {
  4657. return a < b ? 1 : a > b ? -1 : 0;
  4658. }
  4659. function hashCollection(collection) {
  4660. if (collection.size === Infinity) {
  4661. return 0;
  4662. }
  4663. var ordered = isOrdered(collection);
  4664. var keyed = isKeyed(collection);
  4665. var h = ordered ? 1 : 0;
  4666. var size = collection.__iterate(
  4667. keyed
  4668. ? ordered
  4669. ? function (v, k) {
  4670. h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
  4671. }
  4672. : function (v, k) {
  4673. h = (h + hashMerge(hash(v), hash(k))) | 0;
  4674. }
  4675. : ordered
  4676. ? function (v) {
  4677. h = (31 * h + hash(v)) | 0;
  4678. }
  4679. : function (v) {
  4680. h = (h + hash(v)) | 0;
  4681. }
  4682. );
  4683. return murmurHashOfSize(size, h);
  4684. }
  4685. function murmurHashOfSize(size, h) {
  4686. h = imul(h, 0xcc9e2d51);
  4687. h = imul((h << 15) | (h >>> -15), 0x1b873593);
  4688. h = imul((h << 13) | (h >>> -13), 5);
  4689. h = ((h + 0xe6546b64) | 0) ^ size;
  4690. h = imul(h ^ (h >>> 16), 0x85ebca6b);
  4691. h = imul(h ^ (h >>> 13), 0xc2b2ae35);
  4692. h = smi(h ^ (h >>> 16));
  4693. return h;
  4694. }
  4695. function hashMerge(a, b) {
  4696. return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
  4697. }
  4698. var OrderedSet = /*@__PURE__*/(function (Set) {
  4699. function OrderedSet(value) {
  4700. return value === undefined || value === null
  4701. ? emptyOrderedSet()
  4702. : isOrderedSet(value)
  4703. ? value
  4704. : emptyOrderedSet().withMutations(function (set) {
  4705. var iter = SetCollection(value);
  4706. assertNotInfinite(iter.size);
  4707. iter.forEach(function (v) { return set.add(v); });
  4708. });
  4709. }
  4710. if ( Set ) OrderedSet.__proto__ = Set;
  4711. OrderedSet.prototype = Object.create( Set && Set.prototype );
  4712. OrderedSet.prototype.constructor = OrderedSet;
  4713. OrderedSet.of = function of (/*...values*/) {
  4714. return this(arguments);
  4715. };
  4716. OrderedSet.fromKeys = function fromKeys (value) {
  4717. return this(KeyedCollection(value).keySeq());
  4718. };
  4719. OrderedSet.prototype.toString = function toString () {
  4720. return this.__toString('OrderedSet {', '}');
  4721. };
  4722. return OrderedSet;
  4723. }(Set));
  4724. OrderedSet.isOrderedSet = isOrderedSet;
  4725. var OrderedSetPrototype = OrderedSet.prototype;
  4726. OrderedSetPrototype[IS_ORDERED_SYMBOL] = true;
  4727. OrderedSetPrototype.zip = IndexedCollectionPrototype.zip;
  4728. OrderedSetPrototype.zipWith = IndexedCollectionPrototype.zipWith;
  4729. OrderedSetPrototype.zipAll = IndexedCollectionPrototype.zipAll;
  4730. OrderedSetPrototype.__empty = emptyOrderedSet;
  4731. OrderedSetPrototype.__make = makeOrderedSet;
  4732. function makeOrderedSet(map, ownerID) {
  4733. var set = Object.create(OrderedSetPrototype);
  4734. set.size = map ? map.size : 0;
  4735. set._map = map;
  4736. set.__ownerID = ownerID;
  4737. return set;
  4738. }
  4739. var EMPTY_ORDERED_SET;
  4740. function emptyOrderedSet() {
  4741. return (
  4742. EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()))
  4743. );
  4744. }
  4745. function throwOnInvalidDefaultValues(defaultValues) {
  4746. if (isRecord(defaultValues)) {
  4747. throw new Error(
  4748. 'Can not call `Record` with an immutable Record as default values. Use a plain javascript object instead.'
  4749. );
  4750. }
  4751. if (isImmutable(defaultValues)) {
  4752. throw new Error(
  4753. 'Can not call `Record` with an immutable Collection as default values. Use a plain javascript object instead.'
  4754. );
  4755. }
  4756. if (defaultValues === null || typeof defaultValues !== 'object') {
  4757. throw new Error(
  4758. 'Can not call `Record` with a non-object as default values. Use a plain javascript object instead.'
  4759. );
  4760. }
  4761. }
  4762. var Record = function Record(defaultValues, name) {
  4763. var hasInitialized;
  4764. throwOnInvalidDefaultValues(defaultValues);
  4765. var RecordType = function Record(values) {
  4766. var this$1$1 = this;
  4767. if (values instanceof RecordType) {
  4768. return values;
  4769. }
  4770. if (!(this instanceof RecordType)) {
  4771. return new RecordType(values);
  4772. }
  4773. if (!hasInitialized) {
  4774. hasInitialized = true;
  4775. var keys = Object.keys(defaultValues);
  4776. var indices = (RecordTypePrototype._indices = {});
  4777. // Deprecated: left to attempt not to break any external code which
  4778. // relies on a ._name property existing on record instances.
  4779. // Use Record.getDescriptiveName() instead
  4780. RecordTypePrototype._name = name;
  4781. RecordTypePrototype._keys = keys;
  4782. RecordTypePrototype._defaultValues = defaultValues;
  4783. for (var i = 0; i < keys.length; i++) {
  4784. var propName = keys[i];
  4785. indices[propName] = i;
  4786. if (RecordTypePrototype[propName]) {
  4787. /* eslint-disable no-console */
  4788. typeof console === 'object' &&
  4789. console.warn &&
  4790. console.warn(
  4791. 'Cannot define ' +
  4792. recordName(this) +
  4793. ' with property "' +
  4794. propName +
  4795. '" since that property name is part of the Record API.'
  4796. );
  4797. /* eslint-enable no-console */
  4798. } else {
  4799. setProp(RecordTypePrototype, propName);
  4800. }
  4801. }
  4802. }
  4803. this.__ownerID = undefined;
  4804. this._values = List().withMutations(function (l) {
  4805. l.setSize(this$1$1._keys.length);
  4806. KeyedCollection(values).forEach(function (v, k) {
  4807. l.set(this$1$1._indices[k], v === this$1$1._defaultValues[k] ? undefined : v);
  4808. });
  4809. });
  4810. return this;
  4811. };
  4812. var RecordTypePrototype = (RecordType.prototype =
  4813. Object.create(RecordPrototype));
  4814. RecordTypePrototype.constructor = RecordType;
  4815. if (name) {
  4816. RecordType.displayName = name;
  4817. }
  4818. return RecordType;
  4819. };
  4820. Record.prototype.toString = function toString () {
  4821. var str = recordName(this) + ' { ';
  4822. var keys = this._keys;
  4823. var k;
  4824. for (var i = 0, l = keys.length; i !== l; i++) {
  4825. k = keys[i];
  4826. str += (i ? ', ' : '') + k + ': ' + quoteString(this.get(k));
  4827. }
  4828. return str + ' }';
  4829. };
  4830. Record.prototype.equals = function equals (other) {
  4831. return (
  4832. this === other ||
  4833. (isRecord(other) && recordSeq(this).equals(recordSeq(other)))
  4834. );
  4835. };
  4836. Record.prototype.hashCode = function hashCode () {
  4837. return recordSeq(this).hashCode();
  4838. };
  4839. // @pragma Access
  4840. Record.prototype.has = function has (k) {
  4841. return this._indices.hasOwnProperty(k);
  4842. };
  4843. Record.prototype.get = function get (k, notSetValue) {
  4844. if (!this.has(k)) {
  4845. return notSetValue;
  4846. }
  4847. var index = this._indices[k];
  4848. var value = this._values.get(index);
  4849. return value === undefined ? this._defaultValues[k] : value;
  4850. };
  4851. // @pragma Modification
  4852. Record.prototype.set = function set (k, v) {
  4853. if (this.has(k)) {
  4854. var newValues = this._values.set(
  4855. this._indices[k],
  4856. v === this._defaultValues[k] ? undefined : v
  4857. );
  4858. if (newValues !== this._values && !this.__ownerID) {
  4859. return makeRecord(this, newValues);
  4860. }
  4861. }
  4862. return this;
  4863. };
  4864. Record.prototype.remove = function remove (k) {
  4865. return this.set(k);
  4866. };
  4867. Record.prototype.clear = function clear () {
  4868. var newValues = this._values.clear().setSize(this._keys.length);
  4869. return this.__ownerID ? this : makeRecord(this, newValues);
  4870. };
  4871. Record.prototype.wasAltered = function wasAltered () {
  4872. return this._values.wasAltered();
  4873. };
  4874. Record.prototype.toSeq = function toSeq () {
  4875. return recordSeq(this);
  4876. };
  4877. Record.prototype.toJS = function toJS$1 () {
  4878. return toJS(this);
  4879. };
  4880. Record.prototype.entries = function entries () {
  4881. return this.__iterator(ITERATE_ENTRIES);
  4882. };
  4883. Record.prototype.__iterator = function __iterator (type, reverse) {
  4884. return recordSeq(this).__iterator(type, reverse);
  4885. };
  4886. Record.prototype.__iterate = function __iterate (fn, reverse) {
  4887. return recordSeq(this).__iterate(fn, reverse);
  4888. };
  4889. Record.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  4890. if (ownerID === this.__ownerID) {
  4891. return this;
  4892. }
  4893. var newValues = this._values.__ensureOwner(ownerID);
  4894. if (!ownerID) {
  4895. this.__ownerID = ownerID;
  4896. this._values = newValues;
  4897. return this;
  4898. }
  4899. return makeRecord(this, newValues, ownerID);
  4900. };
  4901. Record.isRecord = isRecord;
  4902. Record.getDescriptiveName = recordName;
  4903. var RecordPrototype = Record.prototype;
  4904. RecordPrototype[IS_RECORD_SYMBOL] = true;
  4905. RecordPrototype[DELETE] = RecordPrototype.remove;
  4906. RecordPrototype.deleteIn = RecordPrototype.removeIn = deleteIn;
  4907. RecordPrototype.getIn = getIn;
  4908. RecordPrototype.hasIn = CollectionPrototype.hasIn;
  4909. RecordPrototype.merge = merge$1;
  4910. RecordPrototype.mergeWith = mergeWith$1;
  4911. RecordPrototype.mergeIn = mergeIn;
  4912. RecordPrototype.mergeDeep = mergeDeep;
  4913. RecordPrototype.mergeDeepWith = mergeDeepWith;
  4914. RecordPrototype.mergeDeepIn = mergeDeepIn;
  4915. RecordPrototype.setIn = setIn;
  4916. RecordPrototype.update = update;
  4917. RecordPrototype.updateIn = updateIn;
  4918. RecordPrototype.withMutations = withMutations;
  4919. RecordPrototype.asMutable = asMutable;
  4920. RecordPrototype.asImmutable = asImmutable;
  4921. RecordPrototype[ITERATOR_SYMBOL] = RecordPrototype.entries;
  4922. RecordPrototype.toJSON = RecordPrototype.toObject =
  4923. CollectionPrototype.toObject;
  4924. RecordPrototype.inspect = RecordPrototype.toSource = function () {
  4925. return this.toString();
  4926. };
  4927. function makeRecord(likeRecord, values, ownerID) {
  4928. var record = Object.create(Object.getPrototypeOf(likeRecord));
  4929. record._values = values;
  4930. record.__ownerID = ownerID;
  4931. return record;
  4932. }
  4933. function recordName(record) {
  4934. return record.constructor.displayName || record.constructor.name || 'Record';
  4935. }
  4936. function recordSeq(record) {
  4937. return keyedSeqFromValue(record._keys.map(function (k) { return [k, record.get(k)]; }));
  4938. }
  4939. function setProp(prototype, name) {
  4940. try {
  4941. Object.defineProperty(prototype, name, {
  4942. get: function () {
  4943. return this.get(name);
  4944. },
  4945. set: function (value) {
  4946. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  4947. this.set(name, value);
  4948. },
  4949. });
  4950. } catch (error) {
  4951. // Object.defineProperty failed. Probably IE8.
  4952. }
  4953. }
  4954. /**
  4955. * Returns a lazy Seq of `value` repeated `times` times. When `times` is
  4956. * undefined, returns an infinite sequence of `value`.
  4957. */
  4958. var Repeat = /*@__PURE__*/(function (IndexedSeq) {
  4959. function Repeat(value, times) {
  4960. if (!(this instanceof Repeat)) {
  4961. return new Repeat(value, times);
  4962. }
  4963. this._value = value;
  4964. this.size = times === undefined ? Infinity : Math.max(0, times);
  4965. if (this.size === 0) {
  4966. if (EMPTY_REPEAT) {
  4967. return EMPTY_REPEAT;
  4968. }
  4969. EMPTY_REPEAT = this;
  4970. }
  4971. }
  4972. if ( IndexedSeq ) Repeat.__proto__ = IndexedSeq;
  4973. Repeat.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  4974. Repeat.prototype.constructor = Repeat;
  4975. Repeat.prototype.toString = function toString () {
  4976. if (this.size === 0) {
  4977. return 'Repeat []';
  4978. }
  4979. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  4980. };
  4981. Repeat.prototype.get = function get (index, notSetValue) {
  4982. return this.has(index) ? this._value : notSetValue;
  4983. };
  4984. Repeat.prototype.includes = function includes (searchValue) {
  4985. return is(this._value, searchValue);
  4986. };
  4987. Repeat.prototype.slice = function slice (begin, end) {
  4988. var size = this.size;
  4989. return wholeSlice(begin, end, size)
  4990. ? this
  4991. : new Repeat(
  4992. this._value,
  4993. resolveEnd(end, size) - resolveBegin(begin, size)
  4994. );
  4995. };
  4996. Repeat.prototype.reverse = function reverse () {
  4997. return this;
  4998. };
  4999. Repeat.prototype.indexOf = function indexOf (searchValue) {
  5000. if (is(this._value, searchValue)) {
  5001. return 0;
  5002. }
  5003. return -1;
  5004. };
  5005. Repeat.prototype.lastIndexOf = function lastIndexOf (searchValue) {
  5006. if (is(this._value, searchValue)) {
  5007. return this.size;
  5008. }
  5009. return -1;
  5010. };
  5011. Repeat.prototype.__iterate = function __iterate (fn, reverse) {
  5012. var size = this.size;
  5013. var i = 0;
  5014. while (i !== size) {
  5015. if (fn(this._value, reverse ? size - ++i : i++, this) === false) {
  5016. break;
  5017. }
  5018. }
  5019. return i;
  5020. };
  5021. Repeat.prototype.__iterator = function __iterator (type, reverse) {
  5022. var this$1$1 = this;
  5023. var size = this.size;
  5024. var i = 0;
  5025. return new Iterator(function () { return i === size
  5026. ? iteratorDone()
  5027. : iteratorValue(type, reverse ? size - ++i : i++, this$1$1._value); }
  5028. );
  5029. };
  5030. Repeat.prototype.equals = function equals (other) {
  5031. return other instanceof Repeat
  5032. ? is(this._value, other._value)
  5033. : deepEqual(other);
  5034. };
  5035. return Repeat;
  5036. }(IndexedSeq));
  5037. var EMPTY_REPEAT;
  5038. function fromJS(value, converter) {
  5039. return fromJSWith(
  5040. [],
  5041. converter || defaultConverter,
  5042. value,
  5043. '',
  5044. converter && converter.length > 2 ? [] : undefined,
  5045. { '': value }
  5046. );
  5047. }
  5048. function fromJSWith(stack, converter, value, key, keyPath, parentValue) {
  5049. if (
  5050. typeof value !== 'string' &&
  5051. !isImmutable(value) &&
  5052. (isArrayLike(value) || hasIterator(value) || isPlainObject(value))
  5053. ) {
  5054. if (~stack.indexOf(value)) {
  5055. throw new TypeError('Cannot convert circular structure to Immutable');
  5056. }
  5057. stack.push(value);
  5058. keyPath && key !== '' && keyPath.push(key);
  5059. var converted = converter.call(
  5060. parentValue,
  5061. key,
  5062. Seq(value).map(function (v, k) { return fromJSWith(stack, converter, v, k, keyPath, value); }
  5063. ),
  5064. keyPath && keyPath.slice()
  5065. );
  5066. stack.pop();
  5067. keyPath && keyPath.pop();
  5068. return converted;
  5069. }
  5070. return value;
  5071. }
  5072. function defaultConverter(k, v) {
  5073. // Effectively the opposite of "Collection.toSeq()"
  5074. return isIndexed(v) ? v.toList() : isKeyed(v) ? v.toMap() : v.toSet();
  5075. }
  5076. var version = "4.1.0";
  5077. var Immutable = {
  5078. version: version,
  5079. Collection: Collection,
  5080. // Note: Iterable is deprecated
  5081. Iterable: Collection,
  5082. Seq: Seq,
  5083. Map: Map,
  5084. OrderedMap: OrderedMap,
  5085. List: List,
  5086. Stack: Stack,
  5087. Set: Set,
  5088. OrderedSet: OrderedSet,
  5089. Record: Record,
  5090. Range: Range,
  5091. Repeat: Repeat,
  5092. is: is,
  5093. fromJS: fromJS,
  5094. hash: hash,
  5095. isImmutable: isImmutable,
  5096. isCollection: isCollection,
  5097. isKeyed: isKeyed,
  5098. isIndexed: isIndexed,
  5099. isAssociative: isAssociative,
  5100. isOrdered: isOrdered,
  5101. isValueObject: isValueObject,
  5102. isPlainObject: isPlainObject,
  5103. isSeq: isSeq,
  5104. isList: isList,
  5105. isMap: isMap,
  5106. isOrderedMap: isOrderedMap,
  5107. isStack: isStack,
  5108. isSet: isSet,
  5109. isOrderedSet: isOrderedSet,
  5110. isRecord: isRecord,
  5111. get: get,
  5112. getIn: getIn$1,
  5113. has: has,
  5114. hasIn: hasIn$1,
  5115. merge: merge,
  5116. mergeDeep: mergeDeep$1,
  5117. mergeWith: mergeWith,
  5118. mergeDeepWith: mergeDeepWith$1,
  5119. remove: remove,
  5120. removeIn: removeIn,
  5121. set: set,
  5122. setIn: setIn$1,
  5123. update: update$1,
  5124. updateIn: updateIn$1,
  5125. };
  5126. // Note: Iterable is deprecated
  5127. var Iterable = Collection;
  5128. export default Immutable;
  5129. export { Collection, Iterable, List, Map, OrderedMap, OrderedSet, Range, Record, Repeat, Seq, Set, Stack, fromJS, get, getIn$1 as getIn, has, hasIn$1 as hasIn, hash, is, isAssociative, isCollection, isImmutable, isIndexed, isKeyed, isList, isMap, isOrdered, isOrderedMap, isOrderedSet, isPlainObject, isRecord, isSeq, isSet, isStack, isValueObject, merge, mergeDeep$1 as mergeDeep, mergeDeepWith$1 as mergeDeepWith, mergeWith, remove, removeIn, set, setIn$1 as setIn, update$1 as update, updateIn$1 as updateIn, version };