immutable.es.js 175 KB

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