immutable.js 168 KB

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