immutable.es.js 158 KB

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