immutable.es.js 176 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201
  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. function isProtoKey(key) {
  2004. return (typeof key === 'string' && (key === '__proto__' || key === 'constructor'));
  2005. }
  2006. // http://jsperf.com/copy-array-inline
  2007. function arrCopy(arr, offset) {
  2008. offset = offset || 0;
  2009. var len = Math.max(0, arr.length - offset);
  2010. var newArr = new Array(len);
  2011. for (var ii = 0; ii < len; ii++) {
  2012. // @ts-expect-error We may want to guard for undefined values with `if (arr[ii + offset] !== undefined`, but ths should not happen by design
  2013. newArr[ii] = arr[ii + offset];
  2014. }
  2015. return newArr;
  2016. }
  2017. function shallowCopy(from) {
  2018. if (Array.isArray(from)) {
  2019. return arrCopy(from);
  2020. }
  2021. var to = {};
  2022. for (var key in from) {
  2023. if (isProtoKey(key)) {
  2024. continue;
  2025. }
  2026. if (hasOwnProperty.call(from, key)) {
  2027. to[key] = from[key];
  2028. }
  2029. }
  2030. return to;
  2031. }
  2032. function merge(collection) {
  2033. var sources = [], len = arguments.length - 1;
  2034. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  2035. return mergeWithSources(collection, sources);
  2036. }
  2037. function mergeWith(merger, collection) {
  2038. var sources = [], len = arguments.length - 2;
  2039. while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
  2040. return mergeWithSources(collection, sources, merger);
  2041. }
  2042. function mergeDeep$1(collection) {
  2043. var sources = [], len = arguments.length - 1;
  2044. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  2045. return mergeDeepWithSources(collection, sources);
  2046. }
  2047. function mergeDeepWith$1(merger, collection) {
  2048. var sources = [], len = arguments.length - 2;
  2049. while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
  2050. return mergeDeepWithSources(collection, sources, merger);
  2051. }
  2052. function mergeDeepWithSources(collection, sources, merger) {
  2053. return mergeWithSources(collection, sources, deepMergerWith(merger));
  2054. }
  2055. function mergeWithSources(collection, sources, merger) {
  2056. if (!isDataStructure(collection)) {
  2057. throw new TypeError(
  2058. 'Cannot merge into non-data-structure value: ' + collection
  2059. );
  2060. }
  2061. if (isImmutable(collection)) {
  2062. return typeof merger === 'function' && collection.mergeWith
  2063. ? collection.mergeWith.apply(collection, [ merger ].concat( sources ))
  2064. : collection.merge
  2065. ? collection.merge.apply(collection, sources)
  2066. : collection.concat.apply(collection, sources);
  2067. }
  2068. var isArray = Array.isArray(collection);
  2069. var merged = collection;
  2070. var Collection = isArray ? IndexedCollection : KeyedCollection;
  2071. var mergeItem = isArray
  2072. ? function (value) {
  2073. // Copy on write
  2074. if (merged === collection) {
  2075. merged = shallowCopy(merged);
  2076. }
  2077. merged.push(value);
  2078. }
  2079. : function (value, key) {
  2080. if (isProtoKey(key)) {
  2081. return;
  2082. }
  2083. var hasVal = hasOwnProperty.call(merged, key);
  2084. var nextVal =
  2085. hasVal && merger ? merger(merged[key], value, key) : value;
  2086. if (!hasVal || nextVal !== merged[key]) {
  2087. // Copy on write
  2088. if (merged === collection) {
  2089. merged = shallowCopy(merged);
  2090. }
  2091. merged[key] = nextVal;
  2092. }
  2093. };
  2094. for (var i = 0; i < sources.length; i++) {
  2095. Collection(sources[i]).forEach(mergeItem);
  2096. }
  2097. return merged;
  2098. }
  2099. function deepMergerWith(merger) {
  2100. function deepMerger(oldValue, newValue, key) {
  2101. return isDataStructure(oldValue) &&
  2102. isDataStructure(newValue) &&
  2103. areMergeable(oldValue, newValue)
  2104. ? mergeWithSources(oldValue, [newValue], deepMerger)
  2105. : merger
  2106. ? merger(oldValue, newValue, key)
  2107. : newValue;
  2108. }
  2109. return deepMerger;
  2110. }
  2111. /**
  2112. * It's unclear what the desired behavior is for merging two collections that
  2113. * fall into separate categories between keyed, indexed, or set-like, so we only
  2114. * consider them mergeable if they fall into the same category.
  2115. */
  2116. function areMergeable(oldDataStructure, newDataStructure) {
  2117. var oldSeq = Seq(oldDataStructure);
  2118. var newSeq = Seq(newDataStructure);
  2119. // This logic assumes that a sequence can only fall into one of the three
  2120. // categories mentioned above (since there's no `isSetLike()` method).
  2121. return (
  2122. isIndexed(oldSeq) === isIndexed(newSeq) &&
  2123. isKeyed(oldSeq) === isKeyed(newSeq)
  2124. );
  2125. }
  2126. function mergeDeep() {
  2127. var iters = [], len = arguments.length;
  2128. while ( len-- ) iters[ len ] = arguments[ len ];
  2129. return mergeDeepWithSources(this, iters);
  2130. }
  2131. function mergeDeepWith(merger) {
  2132. var iters = [], len = arguments.length - 1;
  2133. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  2134. return mergeDeepWithSources(this, iters, merger);
  2135. }
  2136. function mergeDeepIn(keyPath) {
  2137. var iters = [], len = arguments.length - 1;
  2138. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  2139. return updateIn(this, keyPath, emptyMap(), function (m) { return mergeDeepWithSources(m, iters); }
  2140. );
  2141. }
  2142. function mergeIn(keyPath) {
  2143. var iters = [], len = arguments.length - 1;
  2144. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  2145. return updateIn(this, keyPath, emptyMap(), function (m) { return mergeWithSources(m, iters); });
  2146. }
  2147. /**
  2148. * Returns a copy of the collection with the value at the key path set to the
  2149. * provided value.
  2150. *
  2151. * A functional alternative to `collection.setIn(keypath)` which will also
  2152. * work with plain Objects and Arrays.
  2153. */
  2154. function setIn$1(collection, keyPath, value) {
  2155. return updateIn(collection, keyPath, NOT_SET, function () { return value; });
  2156. }
  2157. function setIn(keyPath, v) {
  2158. return setIn$1(this, keyPath, v);
  2159. }
  2160. function update(key, notSetValue, updater) {
  2161. return arguments.length === 1
  2162. ? key(this)
  2163. : update$1(this, key, notSetValue, updater);
  2164. }
  2165. function updateIn$1(keyPath, notSetValue, updater) {
  2166. return updateIn(this, keyPath, notSetValue, updater);
  2167. }
  2168. function wasAltered() {
  2169. return this.__altered;
  2170. }
  2171. function withMutations(fn) {
  2172. var mutable = this.asMutable();
  2173. fn(mutable);
  2174. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  2175. }
  2176. var IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
  2177. /**
  2178. * True if `maybeMap` is a Map.
  2179. *
  2180. * Also true for OrderedMaps.
  2181. */
  2182. function isMap(maybeMap) {
  2183. return Boolean(maybeMap &&
  2184. // @ts-expect-error: maybeMap is typed as `{}`, need to change in 6.0 to `maybeMap && typeof maybeMap === 'object' && IS_MAP_SYMBOL in maybeMap`
  2185. maybeMap[IS_MAP_SYMBOL]);
  2186. }
  2187. function invariant(condition, error) {
  2188. if (!condition)
  2189. { throw new Error(error); }
  2190. }
  2191. function assertNotInfinite(size) {
  2192. invariant(size !== Infinity, 'Cannot perform this action with an infinite size.');
  2193. }
  2194. var Map = /*@__PURE__*/(function (KeyedCollection) {
  2195. function Map(value) {
  2196. // eslint-disable-next-line no-constructor-return
  2197. return value === undefined || value === null
  2198. ? emptyMap()
  2199. : isMap(value) && !isOrdered(value)
  2200. ? value
  2201. : emptyMap().withMutations(function (map) {
  2202. var iter = KeyedCollection(value);
  2203. assertNotInfinite(iter.size);
  2204. iter.forEach(function (v, k) { return map.set(k, v); });
  2205. });
  2206. }
  2207. if ( KeyedCollection ) Map.__proto__ = KeyedCollection;
  2208. Map.prototype = Object.create( KeyedCollection && KeyedCollection.prototype );
  2209. Map.prototype.constructor = Map;
  2210. Map.prototype.toString = function toString () {
  2211. return this.__toString('Map {', '}');
  2212. };
  2213. // @pragma Access
  2214. Map.prototype.get = function get (k, notSetValue) {
  2215. return this._root
  2216. ? this._root.get(0, undefined, k, notSetValue)
  2217. : notSetValue;
  2218. };
  2219. // @pragma Modification
  2220. Map.prototype.set = function set (k, v) {
  2221. return updateMap(this, k, v);
  2222. };
  2223. Map.prototype.remove = function remove (k) {
  2224. return updateMap(this, k, NOT_SET);
  2225. };
  2226. Map.prototype.deleteAll = function deleteAll (keys) {
  2227. var collection = Collection(keys);
  2228. if (collection.size === 0) {
  2229. return this;
  2230. }
  2231. return this.withMutations(function (map) {
  2232. collection.forEach(function (key) { return map.remove(key); });
  2233. });
  2234. };
  2235. Map.prototype.clear = function clear () {
  2236. if (this.size === 0) {
  2237. return this;
  2238. }
  2239. if (this.__ownerID) {
  2240. this.size = 0;
  2241. this._root = null;
  2242. this.__hash = undefined;
  2243. this.__altered = true;
  2244. return this;
  2245. }
  2246. return emptyMap();
  2247. };
  2248. // @pragma Composition
  2249. Map.prototype.sort = function sort (comparator) {
  2250. // Late binding
  2251. return OrderedMap(sortFactory(this, comparator));
  2252. };
  2253. Map.prototype.sortBy = function sortBy (mapper, comparator) {
  2254. // Late binding
  2255. return OrderedMap(sortFactory(this, comparator, mapper));
  2256. };
  2257. Map.prototype.map = function map (mapper, context) {
  2258. var this$1$1 = this;
  2259. return this.withMutations(function (map) {
  2260. map.forEach(function (value, key) {
  2261. map.set(key, mapper.call(context, value, key, this$1$1));
  2262. });
  2263. });
  2264. };
  2265. // @pragma Mutability
  2266. Map.prototype.__iterator = function __iterator (type, reverse) {
  2267. return new MapIterator(this, type, reverse);
  2268. };
  2269. Map.prototype.__iterate = function __iterate (fn, reverse) {
  2270. var this$1$1 = this;
  2271. var iterations = 0;
  2272. // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
  2273. this._root &&
  2274. this._root.iterate(function (entry) {
  2275. iterations++;
  2276. return fn(entry[1], entry[0], this$1$1);
  2277. }, reverse);
  2278. return iterations;
  2279. };
  2280. Map.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  2281. if (ownerID === this.__ownerID) {
  2282. return this;
  2283. }
  2284. if (!ownerID) {
  2285. if (this.size === 0) {
  2286. return emptyMap();
  2287. }
  2288. this.__ownerID = ownerID;
  2289. this.__altered = false;
  2290. return this;
  2291. }
  2292. return makeMap(this.size, this._root, ownerID, this.__hash);
  2293. };
  2294. return Map;
  2295. }(KeyedCollection));
  2296. Map.isMap = isMap;
  2297. var MapPrototype = Map.prototype;
  2298. MapPrototype[IS_MAP_SYMBOL] = true;
  2299. MapPrototype[DELETE] = MapPrototype.remove;
  2300. MapPrototype.removeAll = MapPrototype.deleteAll;
  2301. MapPrototype.setIn = setIn;
  2302. MapPrototype.removeIn = MapPrototype.deleteIn = deleteIn;
  2303. MapPrototype.update = update;
  2304. MapPrototype.updateIn = updateIn$1;
  2305. MapPrototype.merge = MapPrototype.concat = merge$1;
  2306. MapPrototype.mergeWith = mergeWith$1;
  2307. MapPrototype.mergeDeep = mergeDeep;
  2308. MapPrototype.mergeDeepWith = mergeDeepWith;
  2309. MapPrototype.mergeIn = mergeIn;
  2310. MapPrototype.mergeDeepIn = mergeDeepIn;
  2311. MapPrototype.withMutations = withMutations;
  2312. MapPrototype.wasAltered = wasAltered;
  2313. MapPrototype.asImmutable = asImmutable;
  2314. MapPrototype['@@transducer/init'] = MapPrototype.asMutable = asMutable;
  2315. MapPrototype['@@transducer/step'] = function (result, arr) {
  2316. return result.set(arr[0], arr[1]);
  2317. };
  2318. MapPrototype['@@transducer/result'] = function (obj) {
  2319. return obj.asImmutable();
  2320. };
  2321. // #pragma Trie Nodes
  2322. var ArrayMapNode = function ArrayMapNode(ownerID, entries) {
  2323. this.ownerID = ownerID;
  2324. this.entries = entries;
  2325. };
  2326. ArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  2327. var entries = this.entries;
  2328. for (var ii = 0, len = entries.length; ii < len; ii++) {
  2329. if (is(key, entries[ii][0])) {
  2330. return entries[ii][1];
  2331. }
  2332. }
  2333. return notSetValue;
  2334. };
  2335. ArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  2336. var removed = value === NOT_SET;
  2337. var entries = this.entries;
  2338. var idx = 0;
  2339. var len = entries.length;
  2340. for (; idx < len; idx++) {
  2341. if (is(key, entries[idx][0])) {
  2342. break;
  2343. }
  2344. }
  2345. var exists = idx < len;
  2346. if (exists ? entries[idx][1] === value : removed) {
  2347. return this;
  2348. }
  2349. SetRef(didAlter);
  2350. // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
  2351. (removed || !exists) && SetRef(didChangeSize);
  2352. if (removed && entries.length === 1) {
  2353. return; // undefined
  2354. }
  2355. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  2356. return createNodes(ownerID, entries, key, value);
  2357. }
  2358. var isEditable = ownerID && ownerID === this.ownerID;
  2359. var newEntries = isEditable ? entries : arrCopy(entries);
  2360. if (exists) {
  2361. if (removed) {
  2362. // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
  2363. idx === len - 1
  2364. ? newEntries.pop()
  2365. : (newEntries[idx] = newEntries.pop());
  2366. } else {
  2367. newEntries[idx] = [key, value];
  2368. }
  2369. } else {
  2370. newEntries.push([key, value]);
  2371. }
  2372. if (isEditable) {
  2373. this.entries = newEntries;
  2374. return this;
  2375. }
  2376. return new ArrayMapNode(ownerID, newEntries);
  2377. };
  2378. var BitmapIndexedNode = function BitmapIndexedNode(ownerID, bitmap, nodes) {
  2379. this.ownerID = ownerID;
  2380. this.bitmap = bitmap;
  2381. this.nodes = nodes;
  2382. };
  2383. BitmapIndexedNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  2384. if (keyHash === undefined) {
  2385. keyHash = hash(key);
  2386. }
  2387. var bit = 1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK);
  2388. var bitmap = this.bitmap;
  2389. return (bitmap & bit) === 0
  2390. ? notSetValue
  2391. : this.nodes[popCount(bitmap & (bit - 1))].get(
  2392. shift + SHIFT,
  2393. keyHash,
  2394. key,
  2395. notSetValue
  2396. );
  2397. };
  2398. BitmapIndexedNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  2399. if (keyHash === undefined) {
  2400. keyHash = hash(key);
  2401. }
  2402. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  2403. var bit = 1 << keyHashFrag;
  2404. var bitmap = this.bitmap;
  2405. var exists = (bitmap & bit) !== 0;
  2406. if (!exists && value === NOT_SET) {
  2407. return this;
  2408. }
  2409. var idx = popCount(bitmap & (bit - 1));
  2410. var nodes = this.nodes;
  2411. var node = exists ? nodes[idx] : undefined;
  2412. var newNode = updateNode(
  2413. node,
  2414. ownerID,
  2415. shift + SHIFT,
  2416. keyHash,
  2417. key,
  2418. value,
  2419. didChangeSize,
  2420. didAlter
  2421. );
  2422. if (newNode === node) {
  2423. return this;
  2424. }
  2425. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  2426. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  2427. }
  2428. if (
  2429. exists &&
  2430. !newNode &&
  2431. nodes.length === 2 &&
  2432. isLeafNode(nodes[idx ^ 1])
  2433. ) {
  2434. return nodes[idx ^ 1];
  2435. }
  2436. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  2437. return newNode;
  2438. }
  2439. var isEditable = ownerID && ownerID === this.ownerID;
  2440. var newBitmap = exists ? (newNode ? bitmap : bitmap ^ bit) : bitmap | bit;
  2441. var newNodes = exists
  2442. ? newNode
  2443. ? setAt(nodes, idx, newNode, isEditable)
  2444. : spliceOut(nodes, idx, isEditable)
  2445. : spliceIn(nodes, idx, newNode, isEditable);
  2446. if (isEditable) {
  2447. this.bitmap = newBitmap;
  2448. this.nodes = newNodes;
  2449. return this;
  2450. }
  2451. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  2452. };
  2453. var HashArrayMapNode = function HashArrayMapNode(ownerID, count, nodes) {
  2454. this.ownerID = ownerID;
  2455. this.count = count;
  2456. this.nodes = nodes;
  2457. };
  2458. HashArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  2459. if (keyHash === undefined) {
  2460. keyHash = hash(key);
  2461. }
  2462. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  2463. var node = this.nodes[idx];
  2464. return node
  2465. ? node.get(shift + SHIFT, keyHash, key, notSetValue)
  2466. : notSetValue;
  2467. };
  2468. HashArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  2469. if (keyHash === undefined) {
  2470. keyHash = hash(key);
  2471. }
  2472. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  2473. var removed = value === NOT_SET;
  2474. var nodes = this.nodes;
  2475. var node = nodes[idx];
  2476. if (removed && !node) {
  2477. return this;
  2478. }
  2479. var newNode = updateNode(
  2480. node,
  2481. ownerID,
  2482. shift + SHIFT,
  2483. keyHash,
  2484. key,
  2485. value,
  2486. didChangeSize,
  2487. didAlter
  2488. );
  2489. if (newNode === node) {
  2490. return this;
  2491. }
  2492. var newCount = this.count;
  2493. if (!node) {
  2494. newCount++;
  2495. } else if (!newNode) {
  2496. newCount--;
  2497. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  2498. return packNodes(ownerID, nodes, newCount, idx);
  2499. }
  2500. }
  2501. var isEditable = ownerID && ownerID === this.ownerID;
  2502. var newNodes = setAt(nodes, idx, newNode, isEditable);
  2503. if (isEditable) {
  2504. this.count = newCount;
  2505. this.nodes = newNodes;
  2506. return this;
  2507. }
  2508. return new HashArrayMapNode(ownerID, newCount, newNodes);
  2509. };
  2510. var HashCollisionNode = function HashCollisionNode(ownerID, keyHash, entries) {
  2511. this.ownerID = ownerID;
  2512. this.keyHash = keyHash;
  2513. this.entries = entries;
  2514. };
  2515. HashCollisionNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  2516. var entries = this.entries;
  2517. for (var ii = 0, len = entries.length; ii < len; ii++) {
  2518. if (is(key, entries[ii][0])) {
  2519. return entries[ii][1];
  2520. }
  2521. }
  2522. return notSetValue;
  2523. };
  2524. HashCollisionNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  2525. if (keyHash === undefined) {
  2526. keyHash = hash(key);
  2527. }
  2528. var removed = value === NOT_SET;
  2529. if (keyHash !== this.keyHash) {
  2530. if (removed) {
  2531. return this;
  2532. }
  2533. SetRef(didAlter);
  2534. SetRef(didChangeSize);
  2535. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  2536. }
  2537. var entries = this.entries;
  2538. var idx = 0;
  2539. var len = entries.length;
  2540. for (; idx < len; idx++) {
  2541. if (is(key, entries[idx][0])) {
  2542. break;
  2543. }
  2544. }
  2545. var exists = idx < len;
  2546. if (exists ? entries[idx][1] === value : removed) {
  2547. return this;
  2548. }
  2549. SetRef(didAlter);
  2550. // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
  2551. (removed || !exists) && SetRef(didChangeSize);
  2552. if (removed && len === 2) {
  2553. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  2554. }
  2555. var isEditable = ownerID && ownerID === this.ownerID;
  2556. var newEntries = isEditable ? entries : arrCopy(entries);
  2557. if (exists) {
  2558. if (removed) {
  2559. // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
  2560. idx === len - 1
  2561. ? newEntries.pop()
  2562. : (newEntries[idx] = newEntries.pop());
  2563. } else {
  2564. newEntries[idx] = [key, value];
  2565. }
  2566. } else {
  2567. newEntries.push([key, value]);
  2568. }
  2569. if (isEditable) {
  2570. this.entries = newEntries;
  2571. return this;
  2572. }
  2573. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  2574. };
  2575. var ValueNode = function ValueNode(ownerID, keyHash, entry) {
  2576. this.ownerID = ownerID;
  2577. this.keyHash = keyHash;
  2578. this.entry = entry;
  2579. };
  2580. ValueNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  2581. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  2582. };
  2583. ValueNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  2584. var removed = value === NOT_SET;
  2585. var keyMatch = is(key, this.entry[0]);
  2586. if (keyMatch ? value === this.entry[1] : removed) {
  2587. return this;
  2588. }
  2589. SetRef(didAlter);
  2590. if (removed) {
  2591. SetRef(didChangeSize);
  2592. return; // undefined
  2593. }
  2594. if (keyMatch) {
  2595. if (ownerID && ownerID === this.ownerID) {
  2596. this.entry[1] = value;
  2597. return this;
  2598. }
  2599. return new ValueNode(ownerID, this.keyHash, [key, value]);
  2600. }
  2601. SetRef(didChangeSize);
  2602. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  2603. };
  2604. // #pragma Iterators
  2605. ArrayMapNode.prototype.iterate = HashCollisionNode.prototype.iterate =
  2606. function (fn, reverse) {
  2607. var entries = this.entries;
  2608. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  2609. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  2610. return false;
  2611. }
  2612. }
  2613. };
  2614. BitmapIndexedNode.prototype.iterate = HashArrayMapNode.prototype.iterate =
  2615. function (fn, reverse) {
  2616. var nodes = this.nodes;
  2617. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  2618. var node = nodes[reverse ? maxIndex - ii : ii];
  2619. if (node && node.iterate(fn, reverse) === false) {
  2620. return false;
  2621. }
  2622. }
  2623. };
  2624. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  2625. ValueNode.prototype.iterate = function (fn, reverse) {
  2626. return fn(this.entry);
  2627. };
  2628. var MapIterator = /*@__PURE__*/(function (Iterator) {
  2629. function MapIterator(map, type, reverse) {
  2630. this._type = type;
  2631. this._reverse = reverse;
  2632. this._stack = map._root && mapIteratorFrame(map._root);
  2633. }
  2634. if ( Iterator ) MapIterator.__proto__ = Iterator;
  2635. MapIterator.prototype = Object.create( Iterator && Iterator.prototype );
  2636. MapIterator.prototype.constructor = MapIterator;
  2637. MapIterator.prototype.next = function next () {
  2638. var type = this._type;
  2639. var stack = this._stack;
  2640. while (stack) {
  2641. var node = stack.node;
  2642. var index = stack.index++;
  2643. var maxIndex = (void 0);
  2644. if (node.entry) {
  2645. if (index === 0) {
  2646. return mapIteratorValue(type, node.entry);
  2647. }
  2648. } else if (node.entries) {
  2649. maxIndex = node.entries.length - 1;
  2650. if (index <= maxIndex) {
  2651. return mapIteratorValue(
  2652. type,
  2653. node.entries[this._reverse ? maxIndex - index : index]
  2654. );
  2655. }
  2656. } else {
  2657. maxIndex = node.nodes.length - 1;
  2658. if (index <= maxIndex) {
  2659. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  2660. if (subNode) {
  2661. if (subNode.entry) {
  2662. return mapIteratorValue(type, subNode.entry);
  2663. }
  2664. stack = this._stack = mapIteratorFrame(subNode, stack);
  2665. }
  2666. continue;
  2667. }
  2668. }
  2669. stack = this._stack = this._stack.__prev;
  2670. }
  2671. return iteratorDone();
  2672. };
  2673. return MapIterator;
  2674. }(Iterator));
  2675. function mapIteratorValue(type, entry) {
  2676. return iteratorValue(type, entry[0], entry[1]);
  2677. }
  2678. function mapIteratorFrame(node, prev) {
  2679. return {
  2680. node: node,
  2681. index: 0,
  2682. __prev: prev,
  2683. };
  2684. }
  2685. function makeMap(size, root, ownerID, hash) {
  2686. var map = Object.create(MapPrototype);
  2687. map.size = size;
  2688. map._root = root;
  2689. map.__ownerID = ownerID;
  2690. map.__hash = hash;
  2691. map.__altered = false;
  2692. return map;
  2693. }
  2694. var EMPTY_MAP;
  2695. function emptyMap() {
  2696. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  2697. }
  2698. function updateMap(map, k, v) {
  2699. var newRoot;
  2700. var newSize;
  2701. if (!map._root) {
  2702. if (v === NOT_SET) {
  2703. return map;
  2704. }
  2705. newSize = 1;
  2706. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  2707. } else {
  2708. var didChangeSize = MakeRef();
  2709. var didAlter = MakeRef();
  2710. newRoot = updateNode(
  2711. map._root,
  2712. map.__ownerID,
  2713. 0,
  2714. undefined,
  2715. k,
  2716. v,
  2717. didChangeSize,
  2718. didAlter
  2719. );
  2720. if (!didAlter.value) {
  2721. return map;
  2722. }
  2723. newSize = map.size + (didChangeSize.value ? (v === NOT_SET ? -1 : 1) : 0);
  2724. }
  2725. if (map.__ownerID) {
  2726. map.size = newSize;
  2727. map._root = newRoot;
  2728. map.__hash = undefined;
  2729. map.__altered = true;
  2730. return map;
  2731. }
  2732. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  2733. }
  2734. function updateNode(
  2735. node,
  2736. ownerID,
  2737. shift,
  2738. keyHash,
  2739. key,
  2740. value,
  2741. didChangeSize,
  2742. didAlter
  2743. ) {
  2744. if (!node) {
  2745. if (value === NOT_SET) {
  2746. return node;
  2747. }
  2748. SetRef(didAlter);
  2749. SetRef(didChangeSize);
  2750. return new ValueNode(ownerID, keyHash, [key, value]);
  2751. }
  2752. return node.update(
  2753. ownerID,
  2754. shift,
  2755. keyHash,
  2756. key,
  2757. value,
  2758. didChangeSize,
  2759. didAlter
  2760. );
  2761. }
  2762. function isLeafNode(node) {
  2763. return (
  2764. node.constructor === ValueNode || node.constructor === HashCollisionNode
  2765. );
  2766. }
  2767. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  2768. if (node.keyHash === keyHash) {
  2769. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  2770. }
  2771. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  2772. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  2773. var newNode;
  2774. var nodes =
  2775. idx1 === idx2
  2776. ? [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)]
  2777. : ((newNode = new ValueNode(ownerID, keyHash, entry)),
  2778. idx1 < idx2 ? [node, newNode] : [newNode, node]);
  2779. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  2780. }
  2781. function createNodes(ownerID, entries, key, value) {
  2782. if (!ownerID) {
  2783. ownerID = new OwnerID();
  2784. }
  2785. var node = new ValueNode(ownerID, hash(key), [key, value]);
  2786. for (var ii = 0; ii < entries.length; ii++) {
  2787. var entry = entries[ii];
  2788. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  2789. }
  2790. return node;
  2791. }
  2792. function packNodes(ownerID, nodes, count, excluding) {
  2793. var bitmap = 0;
  2794. var packedII = 0;
  2795. var packedNodes = new Array(count);
  2796. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  2797. var node = nodes[ii];
  2798. if (node !== undefined && ii !== excluding) {
  2799. bitmap |= bit;
  2800. packedNodes[packedII++] = node;
  2801. }
  2802. }
  2803. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  2804. }
  2805. function expandNodes(ownerID, nodes, bitmap, including, node) {
  2806. var count = 0;
  2807. var expandedNodes = new Array(SIZE);
  2808. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  2809. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  2810. }
  2811. expandedNodes[including] = node;
  2812. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  2813. }
  2814. function popCount(x) {
  2815. x -= (x >> 1) & 0x55555555;
  2816. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  2817. x = (x + (x >> 4)) & 0x0f0f0f0f;
  2818. x += x >> 8;
  2819. x += x >> 16;
  2820. return x & 0x7f;
  2821. }
  2822. function setAt(array, idx, val, canEdit) {
  2823. var newArray = canEdit ? array : arrCopy(array);
  2824. newArray[idx] = val;
  2825. return newArray;
  2826. }
  2827. function spliceIn(array, idx, val, canEdit) {
  2828. var newLen = array.length + 1;
  2829. if (canEdit && idx + 1 === newLen) {
  2830. array[idx] = val;
  2831. return array;
  2832. }
  2833. var newArray = new Array(newLen);
  2834. var after = 0;
  2835. for (var ii = 0; ii < newLen; ii++) {
  2836. if (ii === idx) {
  2837. newArray[ii] = val;
  2838. after = -1;
  2839. } else {
  2840. newArray[ii] = array[ii + after];
  2841. }
  2842. }
  2843. return newArray;
  2844. }
  2845. function spliceOut(array, idx, canEdit) {
  2846. var newLen = array.length - 1;
  2847. if (canEdit && idx === newLen) {
  2848. array.pop();
  2849. return array;
  2850. }
  2851. var newArray = new Array(newLen);
  2852. var after = 0;
  2853. for (var ii = 0; ii < newLen; ii++) {
  2854. if (ii === idx) {
  2855. after = 1;
  2856. }
  2857. newArray[ii] = array[ii + after];
  2858. }
  2859. return newArray;
  2860. }
  2861. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  2862. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  2863. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  2864. function coerceKeyPath(keyPath) {
  2865. if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
  2866. return keyPath;
  2867. }
  2868. if (isOrdered(keyPath)) {
  2869. return keyPath.toArray();
  2870. }
  2871. throw new TypeError('Invalid keyPath: expected Ordered Collection or Array: ' + keyPath);
  2872. }
  2873. /**
  2874. * Converts a value to a string, adding quotes if a string was provided.
  2875. */
  2876. function quoteString(value) {
  2877. try {
  2878. return typeof value === 'string' ? JSON.stringify(value) : String(value);
  2879. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  2880. }
  2881. catch (_ignoreError) {
  2882. return JSON.stringify(value);
  2883. }
  2884. }
  2885. /**
  2886. * Returns true if the key is defined in the provided collection.
  2887. *
  2888. * A functional alternative to `collection.has(key)` which will also work with
  2889. * plain Objects and Arrays as an alternative for
  2890. * `collection.hasOwnProperty(key)`.
  2891. */
  2892. function has(collection, key) {
  2893. return isImmutable(collection)
  2894. ? // @ts-expect-error key might be a number or symbol, which is not handled be Record key type
  2895. collection.has(key)
  2896. : // @ts-expect-error key might be anything else than PropertyKey, and will return false in that case but runtime is OK
  2897. isDataStructure(collection) && hasOwnProperty.call(collection, key);
  2898. }
  2899. function get(collection, key, notSetValue) {
  2900. return isImmutable(collection)
  2901. ? collection.get(key, notSetValue)
  2902. : !has(collection, key)
  2903. ? notSetValue
  2904. : // @ts-expect-error weird "get" here,
  2905. typeof collection.get === 'function'
  2906. ? // @ts-expect-error weird "get" here,
  2907. collection.get(key)
  2908. : // @ts-expect-error key is unknown here,
  2909. collection[key];
  2910. }
  2911. function remove(collection, key) {
  2912. if (!isDataStructure(collection)) {
  2913. throw new TypeError('Cannot update non-data-structure value: ' + collection);
  2914. }
  2915. if (isImmutable(collection)) {
  2916. // @ts-expect-error weird "remove" here,
  2917. if (!collection.remove) {
  2918. throw new TypeError('Cannot update immutable value without .remove() method: ' + collection);
  2919. }
  2920. // @ts-expect-error weird "remove" here,
  2921. return collection.remove(key);
  2922. }
  2923. // @ts-expect-error assert that key is a string, a number or a symbol here
  2924. if (!hasOwnProperty.call(collection, key)) {
  2925. return collection;
  2926. }
  2927. var collectionCopy = shallowCopy(collection);
  2928. if (Array.isArray(collectionCopy)) {
  2929. // @ts-expect-error assert that key is a number here
  2930. collectionCopy.splice(key, 1);
  2931. }
  2932. else {
  2933. // @ts-expect-error assert that key is a string, a number or a symbol here
  2934. delete collectionCopy[key];
  2935. }
  2936. return collectionCopy;
  2937. }
  2938. function set(collection, key, value) {
  2939. if (typeof key === 'string' && isProtoKey(key)) {
  2940. return collection;
  2941. }
  2942. if (!isDataStructure(collection)) {
  2943. throw new TypeError('Cannot update non-data-structure value: ' + collection);
  2944. }
  2945. if (isImmutable(collection)) {
  2946. // @ts-expect-error weird "set" here,
  2947. if (!collection.set) {
  2948. throw new TypeError('Cannot update immutable value without .set() method: ' + collection);
  2949. }
  2950. // @ts-expect-error weird "set" here,
  2951. return collection.set(key, value);
  2952. }
  2953. // @ts-expect-error mix of key and string here. Probably need a more fine type here
  2954. if (hasOwnProperty.call(collection, key) && value === collection[key]) {
  2955. return collection;
  2956. }
  2957. var collectionCopy = shallowCopy(collection);
  2958. // @ts-expect-error mix of key and string here. Probably need a more fine type here
  2959. collectionCopy[key] = value;
  2960. return collectionCopy;
  2961. }
  2962. function updateIn(collection, keyPath, notSetValue, updater) {
  2963. if (!updater) {
  2964. // handle the fact that `notSetValue` is optional here, in that case `updater` is the updater function
  2965. // @ts-expect-error updater is a function here
  2966. updater = notSetValue;
  2967. notSetValue = undefined;
  2968. }
  2969. var updatedValue = updateInDeeply(isImmutable(collection),
  2970. // @ts-expect-error type issues with Record and mixed types
  2971. collection, coerceKeyPath(keyPath), 0, notSetValue, updater);
  2972. // @ts-expect-error mixed return type
  2973. return updatedValue === NOT_SET ? notSetValue : updatedValue;
  2974. }
  2975. function updateInDeeply(inImmutable, existing, keyPath, i, notSetValue, updater) {
  2976. var wasNotSet = existing === NOT_SET;
  2977. if (i === keyPath.length) {
  2978. var existingValue = wasNotSet ? notSetValue : existing;
  2979. // @ts-expect-error mixed type with optional value
  2980. var newValue = updater(existingValue);
  2981. // @ts-expect-error mixed type
  2982. return newValue === existingValue ? existing : newValue;
  2983. }
  2984. if (!wasNotSet && !isDataStructure(existing)) {
  2985. throw new TypeError('Cannot update within non-data-structure value in path [' +
  2986. Array.from(keyPath).slice(0, i).map(quoteString) +
  2987. ']: ' +
  2988. existing);
  2989. }
  2990. var key = keyPath[i];
  2991. var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
  2992. var nextUpdated = updateInDeeply(nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
  2993. // @ts-expect-error mixed type
  2994. nextExisting, keyPath, i + 1, notSetValue, updater);
  2995. return nextUpdated === nextExisting
  2996. ? existing
  2997. : nextUpdated === NOT_SET
  2998. ? remove(existing, key)
  2999. : set(wasNotSet ? (inImmutable ? emptyMap() : {}) : existing, key, nextUpdated);
  3000. }
  3001. /**
  3002. * Returns a copy of the collection with the value at the key path removed.
  3003. *
  3004. * A functional alternative to `collection.removeIn(keypath)` which will also
  3005. * work with plain Objects and Arrays.
  3006. */
  3007. function removeIn(collection, keyPath) {
  3008. return updateIn(collection, keyPath, function () { return NOT_SET; });
  3009. }
  3010. function deleteIn(keyPath) {
  3011. return removeIn(this, keyPath);
  3012. }
  3013. var IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
  3014. /**
  3015. * True if `maybeList` is a List.
  3016. */
  3017. function isList(maybeList) {
  3018. return Boolean(maybeList &&
  3019. // @ts-expect-error: maybeList is typed as `{}`, need to change in 6.0 to `maybeList && typeof maybeList === 'object' && IS_LIST_SYMBOL in maybeList`
  3020. maybeList[IS_LIST_SYMBOL]);
  3021. }
  3022. var List = /*@__PURE__*/(function (IndexedCollection) {
  3023. function List(value) {
  3024. var empty = emptyList();
  3025. if (value === undefined || value === null) {
  3026. // eslint-disable-next-line no-constructor-return
  3027. return empty;
  3028. }
  3029. if (isList(value)) {
  3030. // eslint-disable-next-line no-constructor-return
  3031. return value;
  3032. }
  3033. var iter = IndexedCollection(value);
  3034. var size = iter.size;
  3035. if (size === 0) {
  3036. // eslint-disable-next-line no-constructor-return
  3037. return empty;
  3038. }
  3039. assertNotInfinite(size);
  3040. if (size > 0 && size < SIZE) {
  3041. // eslint-disable-next-line no-constructor-return
  3042. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  3043. }
  3044. // eslint-disable-next-line no-constructor-return
  3045. return empty.withMutations(function (list) {
  3046. list.setSize(size);
  3047. iter.forEach(function (v, i) { return list.set(i, v); });
  3048. });
  3049. }
  3050. if ( IndexedCollection ) List.__proto__ = IndexedCollection;
  3051. List.prototype = Object.create( IndexedCollection && IndexedCollection.prototype );
  3052. List.prototype.constructor = List;
  3053. List.of = function of (/*...values*/) {
  3054. return this(arguments);
  3055. };
  3056. List.prototype.toString = function toString () {
  3057. return this.__toString('List [', ']');
  3058. };
  3059. // @pragma Access
  3060. List.prototype.get = function get (index, notSetValue) {
  3061. index = wrapIndex(this, index);
  3062. if (index >= 0 && index < this.size) {
  3063. index += this._origin;
  3064. var node = listNodeFor(this, index);
  3065. return node && node.array[index & MASK];
  3066. }
  3067. return notSetValue;
  3068. };
  3069. // @pragma Modification
  3070. List.prototype.set = function set (index, value) {
  3071. return updateList(this, index, value);
  3072. };
  3073. List.prototype.remove = function remove (index) {
  3074. return !this.has(index)
  3075. ? this
  3076. : index === 0
  3077. ? this.shift()
  3078. : index === this.size - 1
  3079. ? this.pop()
  3080. : this.splice(index, 1);
  3081. };
  3082. List.prototype.insert = function insert (index, value) {
  3083. return this.splice(index, 0, value);
  3084. };
  3085. List.prototype.clear = function clear () {
  3086. if (this.size === 0) {
  3087. return this;
  3088. }
  3089. if (this.__ownerID) {
  3090. this.size = this._origin = this._capacity = 0;
  3091. this._level = SHIFT;
  3092. this._root = this._tail = this.__hash = undefined;
  3093. this.__altered = true;
  3094. return this;
  3095. }
  3096. return emptyList();
  3097. };
  3098. List.prototype.push = function push (/*...values*/) {
  3099. var values = arguments;
  3100. var oldSize = this.size;
  3101. return this.withMutations(function (list) {
  3102. setListBounds(list, 0, oldSize + values.length);
  3103. for (var ii = 0; ii < values.length; ii++) {
  3104. list.set(oldSize + ii, values[ii]);
  3105. }
  3106. });
  3107. };
  3108. List.prototype.pop = function pop () {
  3109. return setListBounds(this, 0, -1);
  3110. };
  3111. List.prototype.unshift = function unshift (/*...values*/) {
  3112. var values = arguments;
  3113. return this.withMutations(function (list) {
  3114. setListBounds(list, -values.length);
  3115. for (var ii = 0; ii < values.length; ii++) {
  3116. list.set(ii, values[ii]);
  3117. }
  3118. });
  3119. };
  3120. List.prototype.shift = function shift () {
  3121. return setListBounds(this, 1);
  3122. };
  3123. List.prototype.shuffle = function shuffle (random) {
  3124. if ( random === void 0 ) random = Math.random;
  3125. return this.withMutations(function (mutable) {
  3126. // implementation of the Fisher-Yates shuffle: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
  3127. var current = mutable.size;
  3128. var destination;
  3129. var tmp;
  3130. while (current) {
  3131. destination = Math.floor(random() * current--);
  3132. tmp = mutable.get(destination);
  3133. mutable.set(destination, mutable.get(current));
  3134. mutable.set(current, tmp);
  3135. }
  3136. });
  3137. };
  3138. // @pragma Composition
  3139. List.prototype.concat = function concat (/*...collections*/) {
  3140. var arguments$1 = arguments;
  3141. var seqs = [];
  3142. for (var i = 0; i < arguments.length; i++) {
  3143. var argument = arguments$1[i];
  3144. var seq = IndexedCollection(
  3145. typeof argument !== 'string' && hasIterator(argument)
  3146. ? argument
  3147. : [argument]
  3148. );
  3149. if (seq.size !== 0) {
  3150. seqs.push(seq);
  3151. }
  3152. }
  3153. if (seqs.length === 0) {
  3154. return this;
  3155. }
  3156. if (this.size === 0 && !this.__ownerID && seqs.length === 1) {
  3157. return this.constructor(seqs[0]);
  3158. }
  3159. return this.withMutations(function (list) {
  3160. seqs.forEach(function (seq) { return seq.forEach(function (value) { return list.push(value); }); });
  3161. });
  3162. };
  3163. List.prototype.setSize = function setSize (size) {
  3164. return setListBounds(this, 0, size);
  3165. };
  3166. List.prototype.map = function map (mapper, context) {
  3167. var this$1$1 = this;
  3168. return this.withMutations(function (list) {
  3169. for (var i = 0; i < this$1$1.size; i++) {
  3170. list.set(i, mapper.call(context, list.get(i), i, this$1$1));
  3171. }
  3172. });
  3173. };
  3174. // @pragma Iteration
  3175. List.prototype.slice = function slice (begin, end) {
  3176. var size = this.size;
  3177. if (wholeSlice(begin, end, size)) {
  3178. return this;
  3179. }
  3180. return setListBounds(
  3181. this,
  3182. resolveBegin(begin, size),
  3183. resolveEnd(end, size)
  3184. );
  3185. };
  3186. List.prototype.__iterator = function __iterator (type, reverse) {
  3187. var index = reverse ? this.size : 0;
  3188. var values = iterateList(this, reverse);
  3189. return new Iterator(function () {
  3190. var value = values();
  3191. return value === DONE
  3192. ? iteratorDone()
  3193. : iteratorValue(type, reverse ? --index : index++, value);
  3194. });
  3195. };
  3196. List.prototype.__iterate = function __iterate (fn, reverse) {
  3197. var index = reverse ? this.size : 0;
  3198. var values = iterateList(this, reverse);
  3199. var value;
  3200. while ((value = values()) !== DONE) {
  3201. if (fn(value, reverse ? --index : index++, this) === false) {
  3202. break;
  3203. }
  3204. }
  3205. return index;
  3206. };
  3207. List.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  3208. if (ownerID === this.__ownerID) {
  3209. return this;
  3210. }
  3211. if (!ownerID) {
  3212. if (this.size === 0) {
  3213. return emptyList();
  3214. }
  3215. this.__ownerID = ownerID;
  3216. this.__altered = false;
  3217. return this;
  3218. }
  3219. return makeList(
  3220. this._origin,
  3221. this._capacity,
  3222. this._level,
  3223. this._root,
  3224. this._tail,
  3225. ownerID,
  3226. this.__hash
  3227. );
  3228. };
  3229. return List;
  3230. }(IndexedCollection));
  3231. List.isList = isList;
  3232. var ListPrototype = List.prototype;
  3233. ListPrototype[IS_LIST_SYMBOL] = true;
  3234. ListPrototype[DELETE] = ListPrototype.remove;
  3235. ListPrototype.merge = ListPrototype.concat;
  3236. ListPrototype.setIn = setIn;
  3237. ListPrototype.deleteIn = ListPrototype.removeIn = deleteIn;
  3238. ListPrototype.update = update;
  3239. ListPrototype.updateIn = updateIn$1;
  3240. ListPrototype.mergeIn = mergeIn;
  3241. ListPrototype.mergeDeepIn = mergeDeepIn;
  3242. ListPrototype.withMutations = withMutations;
  3243. ListPrototype.wasAltered = wasAltered;
  3244. ListPrototype.asImmutable = asImmutable;
  3245. ListPrototype['@@transducer/init'] = ListPrototype.asMutable = asMutable;
  3246. ListPrototype['@@transducer/step'] = function (result, arr) {
  3247. return result.push(arr);
  3248. };
  3249. ListPrototype['@@transducer/result'] = function (obj) {
  3250. return obj.asImmutable();
  3251. };
  3252. var VNode = function VNode(array, ownerID) {
  3253. this.array = array;
  3254. this.ownerID = ownerID;
  3255. };
  3256. // TODO: seems like these methods are very similar
  3257. VNode.prototype.removeBefore = function removeBefore (ownerID, level, index) {
  3258. if (
  3259. (index & ((1 << (level + SHIFT)) - 1)) === 0 ||
  3260. this.array.length === 0
  3261. ) {
  3262. return this;
  3263. }
  3264. var originIndex = (index >>> level) & MASK;
  3265. if (originIndex >= this.array.length) {
  3266. return new VNode([], ownerID);
  3267. }
  3268. var removingFirst = originIndex === 0;
  3269. var newChild;
  3270. if (level > 0) {
  3271. var oldChild = this.array[originIndex];
  3272. newChild =
  3273. oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  3274. if (newChild === oldChild && removingFirst) {
  3275. return this;
  3276. }
  3277. }
  3278. if (removingFirst && !newChild) {
  3279. return this;
  3280. }
  3281. var editable = editableVNode(this, ownerID);
  3282. if (!removingFirst) {
  3283. for (var ii = 0; ii < originIndex; ii++) {
  3284. editable.array[ii] = undefined;
  3285. }
  3286. }
  3287. if (newChild) {
  3288. editable.array[originIndex] = newChild;
  3289. }
  3290. return editable;
  3291. };
  3292. VNode.prototype.removeAfter = function removeAfter (ownerID, level, index) {
  3293. if (
  3294. index === (level ? 1 << (level + SHIFT) : SIZE) ||
  3295. this.array.length === 0
  3296. ) {
  3297. return this;
  3298. }
  3299. var sizeIndex = ((index - 1) >>> level) & MASK;
  3300. if (sizeIndex >= this.array.length) {
  3301. return this;
  3302. }
  3303. var newChild;
  3304. if (level > 0) {
  3305. var oldChild = this.array[sizeIndex];
  3306. newChild =
  3307. oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  3308. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  3309. return this;
  3310. }
  3311. }
  3312. var editable = editableVNode(this, ownerID);
  3313. editable.array.splice(sizeIndex + 1);
  3314. if (newChild) {
  3315. editable.array[sizeIndex] = newChild;
  3316. }
  3317. return editable;
  3318. };
  3319. var DONE = {};
  3320. function iterateList(list, reverse) {
  3321. var left = list._origin;
  3322. var right = list._capacity;
  3323. var tailPos = getTailOffset(right);
  3324. var tail = list._tail;
  3325. return iterateNodeOrLeaf(list._root, list._level, 0);
  3326. function iterateNodeOrLeaf(node, level, offset) {
  3327. return level === 0
  3328. ? iterateLeaf(node, offset)
  3329. : iterateNode(node, level, offset);
  3330. }
  3331. function iterateLeaf(node, offset) {
  3332. var array = offset === tailPos ? tail && tail.array : node && node.array;
  3333. var from = offset > left ? 0 : left - offset;
  3334. var to = right - offset;
  3335. if (to > SIZE) {
  3336. to = SIZE;
  3337. }
  3338. return function () {
  3339. if (from === to) {
  3340. return DONE;
  3341. }
  3342. var idx = reverse ? --to : from++;
  3343. return array && array[idx];
  3344. };
  3345. }
  3346. function iterateNode(node, level, offset) {
  3347. var values;
  3348. var array = node && node.array;
  3349. var from = offset > left ? 0 : (left - offset) >> level;
  3350. var to = ((right - offset) >> level) + 1;
  3351. if (to > SIZE) {
  3352. to = SIZE;
  3353. }
  3354. return function () {
  3355. while (true) {
  3356. if (values) {
  3357. var value = values();
  3358. if (value !== DONE) {
  3359. return value;
  3360. }
  3361. values = null;
  3362. }
  3363. if (from === to) {
  3364. return DONE;
  3365. }
  3366. var idx = reverse ? --to : from++;
  3367. values = iterateNodeOrLeaf(
  3368. array && array[idx],
  3369. level - SHIFT,
  3370. offset + (idx << level)
  3371. );
  3372. }
  3373. };
  3374. }
  3375. }
  3376. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  3377. var list = Object.create(ListPrototype);
  3378. list.size = capacity - origin;
  3379. list._origin = origin;
  3380. list._capacity = capacity;
  3381. list._level = level;
  3382. list._root = root;
  3383. list._tail = tail;
  3384. list.__ownerID = ownerID;
  3385. list.__hash = hash;
  3386. list.__altered = false;
  3387. return list;
  3388. }
  3389. function emptyList() {
  3390. return makeList(0, 0, SHIFT);
  3391. }
  3392. function updateList(list, index, value) {
  3393. index = wrapIndex(list, index);
  3394. if (index !== index) {
  3395. return list;
  3396. }
  3397. if (index >= list.size || index < 0) {
  3398. return list.withMutations(function (list) {
  3399. // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
  3400. index < 0
  3401. ? setListBounds(list, index).set(0, value)
  3402. : setListBounds(list, 0, index + 1).set(index, value);
  3403. });
  3404. }
  3405. index += list._origin;
  3406. var newTail = list._tail;
  3407. var newRoot = list._root;
  3408. var didAlter = MakeRef();
  3409. if (index >= getTailOffset(list._capacity)) {
  3410. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  3411. } else {
  3412. newRoot = updateVNode(
  3413. newRoot,
  3414. list.__ownerID,
  3415. list._level,
  3416. index,
  3417. value,
  3418. didAlter
  3419. );
  3420. }
  3421. if (!didAlter.value) {
  3422. return list;
  3423. }
  3424. if (list.__ownerID) {
  3425. list._root = newRoot;
  3426. list._tail = newTail;
  3427. list.__hash = undefined;
  3428. list.__altered = true;
  3429. return list;
  3430. }
  3431. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  3432. }
  3433. function updateVNode(node, ownerID, level, index, value, didAlter) {
  3434. var idx = (index >>> level) & MASK;
  3435. var nodeHas = node && idx < node.array.length;
  3436. if (!nodeHas && value === undefined) {
  3437. return node;
  3438. }
  3439. var newNode;
  3440. if (level > 0) {
  3441. var lowerNode = node && node.array[idx];
  3442. var newLowerNode = updateVNode(
  3443. lowerNode,
  3444. ownerID,
  3445. level - SHIFT,
  3446. index,
  3447. value,
  3448. didAlter
  3449. );
  3450. if (newLowerNode === lowerNode) {
  3451. return node;
  3452. }
  3453. newNode = editableVNode(node, ownerID);
  3454. newNode.array[idx] = newLowerNode;
  3455. return newNode;
  3456. }
  3457. if (nodeHas && node.array[idx] === value) {
  3458. return node;
  3459. }
  3460. if (didAlter) {
  3461. SetRef(didAlter);
  3462. }
  3463. newNode = editableVNode(node, ownerID);
  3464. if (value === undefined && idx === newNode.array.length - 1) {
  3465. newNode.array.pop();
  3466. } else {
  3467. newNode.array[idx] = value;
  3468. }
  3469. return newNode;
  3470. }
  3471. function editableVNode(node, ownerID) {
  3472. if (ownerID && node && ownerID === node.ownerID) {
  3473. return node;
  3474. }
  3475. return new VNode(node ? node.array.slice() : [], ownerID);
  3476. }
  3477. function listNodeFor(list, rawIndex) {
  3478. if (rawIndex >= getTailOffset(list._capacity)) {
  3479. return list._tail;
  3480. }
  3481. if (rawIndex < 1 << (list._level + SHIFT)) {
  3482. var node = list._root;
  3483. var level = list._level;
  3484. while (node && level > 0) {
  3485. node = node.array[(rawIndex >>> level) & MASK];
  3486. level -= SHIFT;
  3487. }
  3488. return node;
  3489. }
  3490. }
  3491. function setListBounds(list, begin, end) {
  3492. // Sanitize begin & end using this shorthand for ToInt32(argument)
  3493. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  3494. if (begin !== undefined) {
  3495. begin |= 0;
  3496. }
  3497. if (end !== undefined) {
  3498. end |= 0;
  3499. }
  3500. var owner = list.__ownerID || new OwnerID();
  3501. var oldOrigin = list._origin;
  3502. var oldCapacity = list._capacity;
  3503. var newOrigin = oldOrigin + begin;
  3504. var newCapacity =
  3505. end === undefined
  3506. ? oldCapacity
  3507. : end < 0
  3508. ? oldCapacity + end
  3509. : oldOrigin + end;
  3510. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  3511. return list;
  3512. }
  3513. // If it's going to end after it starts, it's empty.
  3514. if (newOrigin >= newCapacity) {
  3515. return list.clear();
  3516. }
  3517. var newLevel = list._level;
  3518. var newRoot = list._root;
  3519. // New origin might need creating a higher root.
  3520. var offsetShift = 0;
  3521. while (newOrigin + offsetShift < 0) {
  3522. newRoot = new VNode(
  3523. newRoot && newRoot.array.length ? [undefined, newRoot] : [],
  3524. owner
  3525. );
  3526. newLevel += SHIFT;
  3527. offsetShift += 1 << newLevel;
  3528. }
  3529. if (offsetShift) {
  3530. newOrigin += offsetShift;
  3531. oldOrigin += offsetShift;
  3532. newCapacity += offsetShift;
  3533. oldCapacity += offsetShift;
  3534. }
  3535. var oldTailOffset = getTailOffset(oldCapacity);
  3536. var newTailOffset = getTailOffset(newCapacity);
  3537. // New size might need creating a higher root.
  3538. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  3539. newRoot = new VNode(
  3540. newRoot && newRoot.array.length ? [newRoot] : [],
  3541. owner
  3542. );
  3543. newLevel += SHIFT;
  3544. }
  3545. // Locate or create the new tail.
  3546. var oldTail = list._tail;
  3547. var newTail =
  3548. newTailOffset < oldTailOffset
  3549. ? listNodeFor(list, newCapacity - 1)
  3550. : newTailOffset > oldTailOffset
  3551. ? new VNode([], owner)
  3552. : oldTail;
  3553. // Merge Tail into tree.
  3554. if (
  3555. oldTail &&
  3556. newTailOffset > oldTailOffset &&
  3557. newOrigin < oldCapacity &&
  3558. oldTail.array.length
  3559. ) {
  3560. newRoot = editableVNode(newRoot, owner);
  3561. var node = newRoot;
  3562. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  3563. var idx = (oldTailOffset >>> level) & MASK;
  3564. node = node.array[idx] = editableVNode(node.array[idx], owner);
  3565. }
  3566. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  3567. }
  3568. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  3569. if (newCapacity < oldCapacity) {
  3570. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  3571. }
  3572. // If the new origin is within the tail, then we do not need a root.
  3573. if (newOrigin >= newTailOffset) {
  3574. newOrigin -= newTailOffset;
  3575. newCapacity -= newTailOffset;
  3576. newLevel = SHIFT;
  3577. newRoot = null;
  3578. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  3579. // Otherwise, if the root has been trimmed, garbage collect.
  3580. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  3581. offsetShift = 0;
  3582. // Identify the new top root node of the subtree of the old root.
  3583. while (newRoot) {
  3584. var beginIndex = (newOrigin >>> newLevel) & MASK;
  3585. if ((beginIndex !== newTailOffset >>> newLevel) & MASK) {
  3586. break;
  3587. }
  3588. if (beginIndex) {
  3589. offsetShift += (1 << newLevel) * beginIndex;
  3590. }
  3591. newLevel -= SHIFT;
  3592. newRoot = newRoot.array[beginIndex];
  3593. }
  3594. // Trim the new sides of the new root.
  3595. if (newRoot && newOrigin > oldOrigin) {
  3596. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  3597. }
  3598. if (newRoot && newTailOffset < oldTailOffset) {
  3599. newRoot = newRoot.removeAfter(
  3600. owner,
  3601. newLevel,
  3602. newTailOffset - offsetShift
  3603. );
  3604. }
  3605. if (offsetShift) {
  3606. newOrigin -= offsetShift;
  3607. newCapacity -= offsetShift;
  3608. }
  3609. }
  3610. if (list.__ownerID) {
  3611. list.size = newCapacity - newOrigin;
  3612. list._origin = newOrigin;
  3613. list._capacity = newCapacity;
  3614. list._level = newLevel;
  3615. list._root = newRoot;
  3616. list._tail = newTail;
  3617. list.__hash = undefined;
  3618. list.__altered = true;
  3619. return list;
  3620. }
  3621. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  3622. }
  3623. function getTailOffset(size) {
  3624. return size < SIZE ? 0 : ((size - 1) >>> SHIFT) << SHIFT;
  3625. }
  3626. /**
  3627. * True if `maybeOrderedMap` is an OrderedMap.
  3628. */
  3629. function isOrderedMap(maybeOrderedMap) {
  3630. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  3631. }
  3632. var OrderedMap = /*@__PURE__*/(function (Map) {
  3633. function OrderedMap(value) {
  3634. // eslint-disable-next-line no-constructor-return
  3635. return value === undefined || value === null
  3636. ? emptyOrderedMap()
  3637. : isOrderedMap(value)
  3638. ? value
  3639. : emptyOrderedMap().withMutations(function (map) {
  3640. var iter = KeyedCollection(value);
  3641. assertNotInfinite(iter.size);
  3642. iter.forEach(function (v, k) { return map.set(k, v); });
  3643. });
  3644. }
  3645. if ( Map ) OrderedMap.__proto__ = Map;
  3646. OrderedMap.prototype = Object.create( Map && Map.prototype );
  3647. OrderedMap.prototype.constructor = OrderedMap;
  3648. OrderedMap.of = function of (/*...values*/) {
  3649. return this(arguments);
  3650. };
  3651. OrderedMap.prototype.toString = function toString () {
  3652. return this.__toString('OrderedMap {', '}');
  3653. };
  3654. // @pragma Access
  3655. OrderedMap.prototype.get = function get (k, notSetValue) {
  3656. var index = this._map.get(k);
  3657. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  3658. };
  3659. // @pragma Modification
  3660. OrderedMap.prototype.clear = function clear () {
  3661. if (this.size === 0) {
  3662. return this;
  3663. }
  3664. if (this.__ownerID) {
  3665. this.size = 0;
  3666. this._map.clear();
  3667. this._list.clear();
  3668. this.__altered = true;
  3669. return this;
  3670. }
  3671. return emptyOrderedMap();
  3672. };
  3673. OrderedMap.prototype.set = function set (k, v) {
  3674. return updateOrderedMap(this, k, v);
  3675. };
  3676. OrderedMap.prototype.remove = function remove (k) {
  3677. return updateOrderedMap(this, k, NOT_SET);
  3678. };
  3679. OrderedMap.prototype.__iterate = function __iterate (fn, reverse) {
  3680. var this$1$1 = this;
  3681. return this._list.__iterate(
  3682. function (entry) { return entry && fn(entry[1], entry[0], this$1$1); },
  3683. reverse
  3684. );
  3685. };
  3686. OrderedMap.prototype.__iterator = function __iterator (type, reverse) {
  3687. return this._list.fromEntrySeq().__iterator(type, reverse);
  3688. };
  3689. OrderedMap.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  3690. if (ownerID === this.__ownerID) {
  3691. return this;
  3692. }
  3693. var newMap = this._map.__ensureOwner(ownerID);
  3694. var newList = this._list.__ensureOwner(ownerID);
  3695. if (!ownerID) {
  3696. if (this.size === 0) {
  3697. return emptyOrderedMap();
  3698. }
  3699. this.__ownerID = ownerID;
  3700. this.__altered = false;
  3701. this._map = newMap;
  3702. this._list = newList;
  3703. return this;
  3704. }
  3705. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  3706. };
  3707. return OrderedMap;
  3708. }(Map));
  3709. OrderedMap.isOrderedMap = isOrderedMap;
  3710. OrderedMap.prototype[IS_ORDERED_SYMBOL] = true;
  3711. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  3712. function makeOrderedMap(map, list, ownerID, hash) {
  3713. var omap = Object.create(OrderedMap.prototype);
  3714. omap.size = map ? map.size : 0;
  3715. omap._map = map;
  3716. omap._list = list;
  3717. omap.__ownerID = ownerID;
  3718. omap.__hash = hash;
  3719. omap.__altered = false;
  3720. return omap;
  3721. }
  3722. var EMPTY_ORDERED_MAP;
  3723. function emptyOrderedMap() {
  3724. return (
  3725. EMPTY_ORDERED_MAP ||
  3726. (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()))
  3727. );
  3728. }
  3729. function updateOrderedMap(omap, k, v) {
  3730. var map = omap._map;
  3731. var list = omap._list;
  3732. var i = map.get(k);
  3733. var has = i !== undefined;
  3734. var newMap;
  3735. var newList;
  3736. if (v === NOT_SET) {
  3737. // removed
  3738. if (!has) {
  3739. return omap;
  3740. }
  3741. if (list.size >= SIZE && list.size >= map.size * 2) {
  3742. newList = list.filter(function (entry, idx) { return entry !== undefined && i !== idx; });
  3743. newMap = newList
  3744. .toKeyedSeq()
  3745. .map(function (entry) { return entry[0]; })
  3746. .flip()
  3747. .toMap();
  3748. if (omap.__ownerID) {
  3749. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  3750. }
  3751. } else {
  3752. newMap = map.remove(k);
  3753. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  3754. }
  3755. } else if (has) {
  3756. if (v === list.get(i)[1]) {
  3757. return omap;
  3758. }
  3759. newMap = map;
  3760. newList = list.set(i, [k, v]);
  3761. } else {
  3762. newMap = map.set(k, list.size);
  3763. newList = list.set(list.size, [k, v]);
  3764. }
  3765. if (omap.__ownerID) {
  3766. omap.size = newMap.size;
  3767. omap._map = newMap;
  3768. omap._list = newList;
  3769. omap.__hash = undefined;
  3770. omap.__altered = true;
  3771. return omap;
  3772. }
  3773. return makeOrderedMap(newMap, newList);
  3774. }
  3775. var IS_STACK_SYMBOL = '@@__IMMUTABLE_STACK__@@';
  3776. /**
  3777. * True if `maybeStack` is a Stack.
  3778. */
  3779. function isStack(maybeStack) {
  3780. return Boolean(maybeStack &&
  3781. // @ts-expect-error: maybeStack is typed as `{}`, need to change in 6.0 to `maybeStack && typeof maybeStack === 'object' && MAYBE_STACK_SYMBOL in maybeStack`
  3782. maybeStack[IS_STACK_SYMBOL]);
  3783. }
  3784. var Stack = /*@__PURE__*/(function (IndexedCollection) {
  3785. function Stack(value) {
  3786. // eslint-disable-next-line no-constructor-return
  3787. return value === undefined || value === null
  3788. ? emptyStack()
  3789. : isStack(value)
  3790. ? value
  3791. : emptyStack().pushAll(value);
  3792. }
  3793. if ( IndexedCollection ) Stack.__proto__ = IndexedCollection;
  3794. Stack.prototype = Object.create( IndexedCollection && IndexedCollection.prototype );
  3795. Stack.prototype.constructor = Stack;
  3796. Stack.of = function of (/*...values*/) {
  3797. return this(arguments);
  3798. };
  3799. Stack.prototype.toString = function toString () {
  3800. return this.__toString('Stack [', ']');
  3801. };
  3802. // @pragma Access
  3803. Stack.prototype.get = function get (index, notSetValue) {
  3804. var head = this._head;
  3805. index = wrapIndex(this, index);
  3806. while (head && index--) {
  3807. head = head.next;
  3808. }
  3809. return head ? head.value : notSetValue;
  3810. };
  3811. Stack.prototype.peek = function peek () {
  3812. return this._head && this._head.value;
  3813. };
  3814. // @pragma Modification
  3815. Stack.prototype.push = function push (/*...values*/) {
  3816. var arguments$1 = arguments;
  3817. if (arguments.length === 0) {
  3818. return this;
  3819. }
  3820. var newSize = this.size + arguments.length;
  3821. var head = this._head;
  3822. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  3823. head = {
  3824. value: arguments$1[ii],
  3825. next: head,
  3826. };
  3827. }
  3828. if (this.__ownerID) {
  3829. this.size = newSize;
  3830. this._head = head;
  3831. this.__hash = undefined;
  3832. this.__altered = true;
  3833. return this;
  3834. }
  3835. return makeStack(newSize, head);
  3836. };
  3837. Stack.prototype.pushAll = function pushAll (iter) {
  3838. iter = IndexedCollection(iter);
  3839. if (iter.size === 0) {
  3840. return this;
  3841. }
  3842. if (this.size === 0 && isStack(iter)) {
  3843. return iter;
  3844. }
  3845. assertNotInfinite(iter.size);
  3846. var newSize = this.size;
  3847. var head = this._head;
  3848. iter.__iterate(function (value) {
  3849. newSize++;
  3850. head = {
  3851. value: value,
  3852. next: head,
  3853. };
  3854. }, /* reverse */ true);
  3855. if (this.__ownerID) {
  3856. this.size = newSize;
  3857. this._head = head;
  3858. this.__hash = undefined;
  3859. this.__altered = true;
  3860. return this;
  3861. }
  3862. return makeStack(newSize, head);
  3863. };
  3864. Stack.prototype.pop = function pop () {
  3865. return this.slice(1);
  3866. };
  3867. Stack.prototype.clear = function clear () {
  3868. if (this.size === 0) {
  3869. return this;
  3870. }
  3871. if (this.__ownerID) {
  3872. this.size = 0;
  3873. this._head = undefined;
  3874. this.__hash = undefined;
  3875. this.__altered = true;
  3876. return this;
  3877. }
  3878. return emptyStack();
  3879. };
  3880. Stack.prototype.slice = function slice (begin, end) {
  3881. if (wholeSlice(begin, end, this.size)) {
  3882. return this;
  3883. }
  3884. var resolvedBegin = resolveBegin(begin, this.size);
  3885. var resolvedEnd = resolveEnd(end, this.size);
  3886. if (resolvedEnd !== this.size) {
  3887. // super.slice(begin, end);
  3888. return IndexedCollection.prototype.slice.call(this, begin, end);
  3889. }
  3890. var newSize = this.size - resolvedBegin;
  3891. var head = this._head;
  3892. while (resolvedBegin--) {
  3893. head = head.next;
  3894. }
  3895. if (this.__ownerID) {
  3896. this.size = newSize;
  3897. this._head = head;
  3898. this.__hash = undefined;
  3899. this.__altered = true;
  3900. return this;
  3901. }
  3902. return makeStack(newSize, head);
  3903. };
  3904. // @pragma Mutability
  3905. Stack.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  3906. if (ownerID === this.__ownerID) {
  3907. return this;
  3908. }
  3909. if (!ownerID) {
  3910. if (this.size === 0) {
  3911. return emptyStack();
  3912. }
  3913. this.__ownerID = ownerID;
  3914. this.__altered = false;
  3915. return this;
  3916. }
  3917. return makeStack(this.size, this._head, ownerID, this.__hash);
  3918. };
  3919. // @pragma Iteration
  3920. Stack.prototype.__iterate = function __iterate (fn, reverse) {
  3921. var this$1$1 = this;
  3922. if (reverse) {
  3923. return new ArraySeq(this.toArray()).__iterate(
  3924. function (v, k) { return fn(v, k, this$1$1); },
  3925. reverse
  3926. );
  3927. }
  3928. var iterations = 0;
  3929. var node = this._head;
  3930. while (node) {
  3931. if (fn(node.value, iterations++, this) === false) {
  3932. break;
  3933. }
  3934. node = node.next;
  3935. }
  3936. return iterations;
  3937. };
  3938. Stack.prototype.__iterator = function __iterator (type, reverse) {
  3939. if (reverse) {
  3940. return new ArraySeq(this.toArray()).__iterator(type, reverse);
  3941. }
  3942. var iterations = 0;
  3943. var node = this._head;
  3944. return new Iterator(function () {
  3945. if (node) {
  3946. var value = node.value;
  3947. node = node.next;
  3948. return iteratorValue(type, iterations++, value);
  3949. }
  3950. return iteratorDone();
  3951. });
  3952. };
  3953. return Stack;
  3954. }(IndexedCollection));
  3955. Stack.isStack = isStack;
  3956. var StackPrototype = Stack.prototype;
  3957. StackPrototype[IS_STACK_SYMBOL] = true;
  3958. StackPrototype.shift = StackPrototype.pop;
  3959. StackPrototype.unshift = StackPrototype.push;
  3960. StackPrototype.unshiftAll = StackPrototype.pushAll;
  3961. StackPrototype.withMutations = withMutations;
  3962. StackPrototype.wasAltered = wasAltered;
  3963. StackPrototype.asImmutable = asImmutable;
  3964. StackPrototype['@@transducer/init'] = StackPrototype.asMutable = asMutable;
  3965. StackPrototype['@@transducer/step'] = function (result, arr) {
  3966. return result.unshift(arr);
  3967. };
  3968. StackPrototype['@@transducer/result'] = function (obj) {
  3969. return obj.asImmutable();
  3970. };
  3971. function makeStack(size, head, ownerID, hash) {
  3972. var map = Object.create(StackPrototype);
  3973. map.size = size;
  3974. map._head = head;
  3975. map.__ownerID = ownerID;
  3976. map.__hash = hash;
  3977. map.__altered = false;
  3978. return map;
  3979. }
  3980. var EMPTY_STACK;
  3981. function emptyStack() {
  3982. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  3983. }
  3984. function reduce(collection, reducer, reduction, context, useFirst, reverse) {
  3985. // @ts-expect-error Migrate to CollectionImpl in v6
  3986. assertNotInfinite(collection.size);
  3987. // @ts-expect-error Migrate to CollectionImpl in v6
  3988. collection.__iterate(function (v, k, c) {
  3989. if (useFirst) {
  3990. useFirst = false;
  3991. reduction = v;
  3992. }
  3993. else {
  3994. reduction = reducer.call(context, reduction, v, k, c);
  3995. }
  3996. }, reverse);
  3997. return reduction;
  3998. }
  3999. function keyMapper(v, k) {
  4000. return k;
  4001. }
  4002. function entryMapper(v, k) {
  4003. return [k, v];
  4004. }
  4005. function not(predicate) {
  4006. return function () {
  4007. var args = [], len = arguments.length;
  4008. while ( len-- ) args[ len ] = arguments[ len ];
  4009. return !predicate.apply(this, args);
  4010. };
  4011. }
  4012. function neg(predicate) {
  4013. return function () {
  4014. var args = [], len = arguments.length;
  4015. while ( len-- ) args[ len ] = arguments[ len ];
  4016. return -predicate.apply(this, args);
  4017. };
  4018. }
  4019. function defaultNegComparator(a, b) {
  4020. return a < b ? 1 : a > b ? -1 : 0;
  4021. }
  4022. function deepEqual(a, b) {
  4023. if (a === b) {
  4024. return true;
  4025. }
  4026. if (!isCollection(b) ||
  4027. // @ts-expect-error size should exists on Collection
  4028. (a.size !== undefined && b.size !== undefined && a.size !== b.size) ||
  4029. // @ts-expect-error __hash exists on Collection
  4030. (a.__hash !== undefined &&
  4031. // @ts-expect-error __hash exists on Collection
  4032. b.__hash !== undefined &&
  4033. // @ts-expect-error __hash exists on Collection
  4034. a.__hash !== b.__hash) ||
  4035. isKeyed(a) !== isKeyed(b) ||
  4036. isIndexed(a) !== isIndexed(b) ||
  4037. // @ts-expect-error Range extends Collection, which implements [Symbol.iterator], so it is valid
  4038. isOrdered(a) !== isOrdered(b)) {
  4039. return false;
  4040. }
  4041. // @ts-expect-error size should exists on Collection
  4042. if (a.size === 0 && b.size === 0) {
  4043. return true;
  4044. }
  4045. var notAssociative = !isAssociative(a);
  4046. // @ts-expect-error Range extends Collection, which implements [Symbol.iterator], so it is valid
  4047. if (isOrdered(a)) {
  4048. var entries = a.entries();
  4049. // @ts-expect-error need to cast as boolean
  4050. return (b.every(function (v, k) {
  4051. var entry = entries.next().value;
  4052. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  4053. }) && entries.next().done);
  4054. }
  4055. var flipped = false;
  4056. if (a.size === undefined) {
  4057. // @ts-expect-error size should exists on Collection
  4058. if (b.size === undefined) {
  4059. if (typeof a.cacheResult === 'function') {
  4060. a.cacheResult();
  4061. }
  4062. }
  4063. else {
  4064. flipped = true;
  4065. var _ = a;
  4066. a = b;
  4067. b = _;
  4068. }
  4069. }
  4070. var allEqual = true;
  4071. var bSize =
  4072. // @ts-expect-error b is Range | Repeat | Collection<unknown, unknown> as it may have been flipped, and __iterate is valid
  4073. b.__iterate(function (v, k) {
  4074. if (notAssociative
  4075. ? // @ts-expect-error has exists on Collection
  4076. !a.has(v)
  4077. : flipped
  4078. ? // @ts-expect-error type of `get` does not "catch" the version with `notSetValue`
  4079. !is(v, a.get(k, NOT_SET))
  4080. : // @ts-expect-error type of `get` does not "catch" the version with `notSetValue`
  4081. !is(a.get(k, NOT_SET), v)) {
  4082. allEqual = false;
  4083. return false;
  4084. }
  4085. });
  4086. return (allEqual &&
  4087. // @ts-expect-error size should exists on Collection
  4088. a.size === bSize);
  4089. }
  4090. /**
  4091. * Returns a lazy seq of nums from start (inclusive) to end
  4092. * (exclusive), by step, where start defaults to 0, step to 1, and end to
  4093. * infinity. When start is equal to end, returns empty list.
  4094. */
  4095. var Range = /*@__PURE__*/(function (IndexedSeq) {
  4096. function Range(start, end, step) {
  4097. if ( step === void 0 ) step = 1;
  4098. if (!(this instanceof Range)) {
  4099. // eslint-disable-next-line no-constructor-return
  4100. return new Range(start, end, step);
  4101. }
  4102. invariant(step !== 0, 'Cannot step a Range by 0');
  4103. invariant(
  4104. start !== undefined,
  4105. 'You must define a start value when using Range'
  4106. );
  4107. invariant(
  4108. end !== undefined,
  4109. 'You must define an end value when using Range'
  4110. );
  4111. step = Math.abs(step);
  4112. if (end < start) {
  4113. step = -step;
  4114. }
  4115. this._start = start;
  4116. this._end = end;
  4117. this._step = step;
  4118. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  4119. if (this.size === 0) {
  4120. if (EMPTY_RANGE) {
  4121. // eslint-disable-next-line no-constructor-return
  4122. return EMPTY_RANGE;
  4123. }
  4124. // eslint-disable-next-line @typescript-eslint/no-this-alias
  4125. EMPTY_RANGE = this;
  4126. }
  4127. }
  4128. if ( IndexedSeq ) Range.__proto__ = IndexedSeq;
  4129. Range.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  4130. Range.prototype.constructor = Range;
  4131. Range.prototype.toString = function toString () {
  4132. return this.size === 0
  4133. ? 'Range []'
  4134. : ("Range [ " + (this._start) + "..." + (this._end) + (this._step !== 1 ? ' by ' + this._step : '') + " ]");
  4135. };
  4136. Range.prototype.get = function get (index, notSetValue) {
  4137. return this.has(index)
  4138. ? this._start + wrapIndex(this, index) * this._step
  4139. : notSetValue;
  4140. };
  4141. Range.prototype.includes = function includes (searchValue) {
  4142. var possibleIndex = (searchValue - this._start) / this._step;
  4143. return (
  4144. possibleIndex >= 0 &&
  4145. possibleIndex < this.size &&
  4146. possibleIndex === Math.floor(possibleIndex)
  4147. );
  4148. };
  4149. Range.prototype.slice = function slice (begin, end) {
  4150. if (wholeSlice(begin, end, this.size)) {
  4151. return this;
  4152. }
  4153. begin = resolveBegin(begin, this.size);
  4154. end = resolveEnd(end, this.size);
  4155. if (end <= begin) {
  4156. return new Range(0, 0);
  4157. }
  4158. return new Range(
  4159. this.get(begin, this._end),
  4160. this.get(end, this._end),
  4161. this._step
  4162. );
  4163. };
  4164. Range.prototype.indexOf = function indexOf (searchValue) {
  4165. var offsetValue = searchValue - this._start;
  4166. if (offsetValue % this._step === 0) {
  4167. var index = offsetValue / this._step;
  4168. if (index >= 0 && index < this.size) {
  4169. return index;
  4170. }
  4171. }
  4172. return -1;
  4173. };
  4174. Range.prototype.lastIndexOf = function lastIndexOf (searchValue) {
  4175. return this.indexOf(searchValue);
  4176. };
  4177. Range.prototype.__iterate = function __iterate (fn, reverse) {
  4178. var size = this.size;
  4179. var step = this._step;
  4180. var value = reverse ? this._start + (size - 1) * step : this._start;
  4181. var i = 0;
  4182. while (i !== size) {
  4183. if (fn(value, reverse ? size - ++i : i++, this) === false) {
  4184. break;
  4185. }
  4186. value += reverse ? -step : step;
  4187. }
  4188. return i;
  4189. };
  4190. Range.prototype.__iterator = function __iterator (type, reverse) {
  4191. var size = this.size;
  4192. var step = this._step;
  4193. var value = reverse ? this._start + (size - 1) * step : this._start;
  4194. var i = 0;
  4195. return new Iterator(function () {
  4196. if (i === size) {
  4197. return iteratorDone();
  4198. }
  4199. var v = value;
  4200. value += reverse ? -step : step;
  4201. return iteratorValue(type, reverse ? size - ++i : i++, v);
  4202. });
  4203. };
  4204. Range.prototype.equals = function equals (other) {
  4205. return other instanceof Range
  4206. ? this._start === other._start &&
  4207. this._end === other._end &&
  4208. this._step === other._step
  4209. : deepEqual(this, other);
  4210. };
  4211. return Range;
  4212. }(IndexedSeq));
  4213. var EMPTY_RANGE;
  4214. var IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
  4215. /**
  4216. * True if `maybeSet` is a Set.
  4217. *
  4218. * Also true for OrderedSets.
  4219. */
  4220. function isSet(maybeSet) {
  4221. return Boolean(maybeSet &&
  4222. // @ts-expect-error: maybeSet is typed as `{}`, need to change in 6.0 to `maybeSeq && typeof maybeSet === 'object' && MAYBE_SET_SYMBOL in maybeSet`
  4223. maybeSet[IS_SET_SYMBOL]);
  4224. }
  4225. var Set = /*@__PURE__*/(function (SetCollection) {
  4226. function Set(value) {
  4227. // eslint-disable-next-line no-constructor-return
  4228. return value === undefined || value === null
  4229. ? emptySet()
  4230. : isSet(value) && !isOrdered(value)
  4231. ? value
  4232. : emptySet().withMutations(function (set) {
  4233. var iter = SetCollection(value);
  4234. assertNotInfinite(iter.size);
  4235. iter.forEach(function (v) { return set.add(v); });
  4236. });
  4237. }
  4238. if ( SetCollection ) Set.__proto__ = SetCollection;
  4239. Set.prototype = Object.create( SetCollection && SetCollection.prototype );
  4240. Set.prototype.constructor = Set;
  4241. Set.of = function of (/*...values*/) {
  4242. return this(arguments);
  4243. };
  4244. Set.fromKeys = function fromKeys (value) {
  4245. return this(KeyedCollection(value).keySeq());
  4246. };
  4247. Set.intersect = function intersect (sets) {
  4248. sets = Collection(sets).toArray();
  4249. return sets.length
  4250. ? SetPrototype.intersect.apply(Set(sets.pop()), sets)
  4251. : emptySet();
  4252. };
  4253. Set.union = function union (sets) {
  4254. sets = Collection(sets).toArray();
  4255. return sets.length
  4256. ? SetPrototype.union.apply(Set(sets.pop()), sets)
  4257. : emptySet();
  4258. };
  4259. Set.prototype.toString = function toString () {
  4260. return this.__toString('Set {', '}');
  4261. };
  4262. // @pragma Access
  4263. Set.prototype.has = function has (value) {
  4264. return this._map.has(value);
  4265. };
  4266. // @pragma Modification
  4267. Set.prototype.add = function add (value) {
  4268. return updateSet(this, this._map.set(value, value));
  4269. };
  4270. Set.prototype.remove = function remove (value) {
  4271. return updateSet(this, this._map.remove(value));
  4272. };
  4273. Set.prototype.clear = function clear () {
  4274. return updateSet(this, this._map.clear());
  4275. };
  4276. // @pragma Composition
  4277. Set.prototype.map = function map (mapper, context) {
  4278. var this$1$1 = this;
  4279. // keep track if the set is altered by the map function
  4280. var didChanges = false;
  4281. var newMap = updateSet(
  4282. this,
  4283. this._map.mapEntries(function (ref) {
  4284. var v = ref[1];
  4285. var mapped = mapper.call(context, v, v, this$1$1);
  4286. if (mapped !== v) {
  4287. didChanges = true;
  4288. }
  4289. return [mapped, mapped];
  4290. }, context)
  4291. );
  4292. return didChanges ? newMap : this;
  4293. };
  4294. Set.prototype.union = function union () {
  4295. var iters = [], len = arguments.length;
  4296. while ( len-- ) iters[ len ] = arguments[ len ];
  4297. iters = iters.filter(function (x) { return x.size !== 0; });
  4298. if (iters.length === 0) {
  4299. return this;
  4300. }
  4301. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  4302. return this.constructor(iters[0]);
  4303. }
  4304. return this.withMutations(function (set) {
  4305. for (var ii = 0; ii < iters.length; ii++) {
  4306. if (typeof iters[ii] === 'string') {
  4307. set.add(iters[ii]);
  4308. } else {
  4309. SetCollection(iters[ii]).forEach(function (value) { return set.add(value); });
  4310. }
  4311. }
  4312. });
  4313. };
  4314. Set.prototype.intersect = function intersect () {
  4315. var iters = [], len = arguments.length;
  4316. while ( len-- ) iters[ len ] = arguments[ len ];
  4317. if (iters.length === 0) {
  4318. return this;
  4319. }
  4320. iters = iters.map(function (iter) { return SetCollection(iter); });
  4321. var toRemove = [];
  4322. this.forEach(function (value) {
  4323. if (!iters.every(function (iter) { return iter.includes(value); })) {
  4324. toRemove.push(value);
  4325. }
  4326. });
  4327. return this.withMutations(function (set) {
  4328. toRemove.forEach(function (value) {
  4329. set.remove(value);
  4330. });
  4331. });
  4332. };
  4333. Set.prototype.subtract = function subtract () {
  4334. var iters = [], len = arguments.length;
  4335. while ( len-- ) iters[ len ] = arguments[ len ];
  4336. if (iters.length === 0) {
  4337. return this;
  4338. }
  4339. iters = iters.map(function (iter) { return SetCollection(iter); });
  4340. var toRemove = [];
  4341. this.forEach(function (value) {
  4342. if (iters.some(function (iter) { return iter.includes(value); })) {
  4343. toRemove.push(value);
  4344. }
  4345. });
  4346. return this.withMutations(function (set) {
  4347. toRemove.forEach(function (value) {
  4348. set.remove(value);
  4349. });
  4350. });
  4351. };
  4352. Set.prototype.sort = function sort (comparator) {
  4353. // Late binding
  4354. return OrderedSet(sortFactory(this, comparator));
  4355. };
  4356. Set.prototype.sortBy = function sortBy (mapper, comparator) {
  4357. // Late binding
  4358. return OrderedSet(sortFactory(this, comparator, mapper));
  4359. };
  4360. Set.prototype.wasAltered = function wasAltered () {
  4361. return this._map.wasAltered();
  4362. };
  4363. Set.prototype.__iterate = function __iterate (fn, reverse) {
  4364. var this$1$1 = this;
  4365. return this._map.__iterate(function (k) { return fn(k, k, this$1$1); }, reverse);
  4366. };
  4367. Set.prototype.__iterator = function __iterator (type, reverse) {
  4368. return this._map.__iterator(type, reverse);
  4369. };
  4370. Set.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  4371. if (ownerID === this.__ownerID) {
  4372. return this;
  4373. }
  4374. var newMap = this._map.__ensureOwner(ownerID);
  4375. if (!ownerID) {
  4376. if (this.size === 0) {
  4377. return this.__empty();
  4378. }
  4379. this.__ownerID = ownerID;
  4380. this._map = newMap;
  4381. return this;
  4382. }
  4383. return this.__make(newMap, ownerID);
  4384. };
  4385. return Set;
  4386. }(SetCollection));
  4387. Set.isSet = isSet;
  4388. var SetPrototype = Set.prototype;
  4389. SetPrototype[IS_SET_SYMBOL] = true;
  4390. SetPrototype[DELETE] = SetPrototype.remove;
  4391. SetPrototype.merge = SetPrototype.concat = SetPrototype.union;
  4392. SetPrototype.withMutations = withMutations;
  4393. SetPrototype.asImmutable = asImmutable;
  4394. SetPrototype['@@transducer/init'] = SetPrototype.asMutable = asMutable;
  4395. SetPrototype['@@transducer/step'] = function (result, arr) {
  4396. return result.add(arr);
  4397. };
  4398. SetPrototype['@@transducer/result'] = function (obj) {
  4399. return obj.asImmutable();
  4400. };
  4401. SetPrototype.__empty = emptySet;
  4402. SetPrototype.__make = makeSet;
  4403. function updateSet(set, newMap) {
  4404. if (set.__ownerID) {
  4405. set.size = newMap.size;
  4406. set._map = newMap;
  4407. return set;
  4408. }
  4409. return newMap === set._map
  4410. ? set
  4411. : newMap.size === 0
  4412. ? set.__empty()
  4413. : set.__make(newMap);
  4414. }
  4415. function makeSet(map, ownerID) {
  4416. var set = Object.create(SetPrototype);
  4417. set.size = map ? map.size : 0;
  4418. set._map = map;
  4419. set.__ownerID = ownerID;
  4420. return set;
  4421. }
  4422. var EMPTY_SET;
  4423. function emptySet() {
  4424. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  4425. }
  4426. /**
  4427. * Returns the value at the provided key path starting at the provided
  4428. * collection, or notSetValue if the key path is not defined.
  4429. *
  4430. * A functional alternative to `collection.getIn(keypath)` which will also
  4431. * work with plain Objects and Arrays.
  4432. */
  4433. function getIn$1(collection, searchKeyPath, notSetValue) {
  4434. var keyPath = coerceKeyPath(searchKeyPath);
  4435. var i = 0;
  4436. while (i !== keyPath.length) {
  4437. // @ts-expect-error keyPath[i++] can not be undefined by design
  4438. collection = get(collection, keyPath[i++], NOT_SET);
  4439. if (collection === NOT_SET) {
  4440. return notSetValue;
  4441. }
  4442. }
  4443. return collection;
  4444. }
  4445. function getIn(searchKeyPath, notSetValue) {
  4446. return getIn$1(this, searchKeyPath, notSetValue);
  4447. }
  4448. /**
  4449. * Returns true if the key path is defined in the provided collection.
  4450. *
  4451. * A functional alternative to `collection.hasIn(keypath)` which will also
  4452. * work with plain Objects and Arrays.
  4453. */
  4454. function hasIn$1(collection, keyPath) {
  4455. return getIn$1(collection, keyPath, NOT_SET) !== NOT_SET;
  4456. }
  4457. function hasIn(searchKeyPath) {
  4458. return hasIn$1(this, searchKeyPath);
  4459. }
  4460. function toObject() {
  4461. assertNotInfinite(this.size);
  4462. var object = {};
  4463. this.__iterate(function (v, k) {
  4464. if (isProtoKey(k)) {
  4465. return;
  4466. }
  4467. object[k] = v;
  4468. });
  4469. return object;
  4470. }
  4471. function toJS(value) {
  4472. if (!value || typeof value !== 'object') {
  4473. return value;
  4474. }
  4475. if (!isCollection(value)) {
  4476. if (!isDataStructure(value)) {
  4477. return value;
  4478. }
  4479. // @ts-expect-error until Seq has been migrated to TypeScript
  4480. value = Seq(value);
  4481. }
  4482. if (isKeyed(value)) {
  4483. var result$1 = {};
  4484. // @ts-expect-error `__iterate` exists on all Keyed collections but method is not defined in the type
  4485. value.__iterate(function (v, k) {
  4486. if (isProtoKey(k)) {
  4487. return;
  4488. }
  4489. result$1[k] = toJS(v);
  4490. });
  4491. return result$1;
  4492. }
  4493. var result = [];
  4494. // @ts-expect-error value "should" be a non-keyed collection, but we may need to assert for stricter types
  4495. value.__iterate(function (v) {
  4496. result.push(toJS(v));
  4497. });
  4498. return result;
  4499. }
  4500. function hashCollection(collection) {
  4501. // @ts-expect-error Migrate to CollectionImpl in v6
  4502. if (collection.size === Infinity) {
  4503. return 0;
  4504. }
  4505. var ordered = isOrdered(collection);
  4506. var keyed = isKeyed(collection);
  4507. var h = ordered ? 1 : 0;
  4508. // @ts-expect-error Migrate to CollectionImpl in v6
  4509. collection.__iterate(keyed
  4510. ? ordered
  4511. ? function (v, k) {
  4512. h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
  4513. }
  4514. : function (v, k) {
  4515. h = (h + hashMerge(hash(v), hash(k))) | 0;
  4516. }
  4517. : ordered
  4518. ? function (v) {
  4519. h = (31 * h + hash(v)) | 0;
  4520. }
  4521. : function (v) {
  4522. h = (h + hash(v)) | 0;
  4523. });
  4524. // @ts-expect-error Migrate to CollectionImpl in v6
  4525. return murmurHashOfSize(collection.size, h);
  4526. }
  4527. function murmurHashOfSize(size, h) {
  4528. h = imul(h, 0xcc9e2d51);
  4529. h = imul((h << 15) | (h >>> -15), 0x1b873593);
  4530. h = imul((h << 13) | (h >>> -13), 5);
  4531. h = ((h + 0xe6546b64) | 0) ^ size;
  4532. h = imul(h ^ (h >>> 16), 0x85ebca6b);
  4533. h = imul(h ^ (h >>> 13), 0xc2b2ae35);
  4534. h = smi(h ^ (h >>> 16));
  4535. return h;
  4536. }
  4537. function hashMerge(a, b) {
  4538. return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
  4539. }
  4540. /**
  4541. * Contributes additional methods to a constructor
  4542. */
  4543. function mixin(ctor,
  4544. // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
  4545. methods) {
  4546. var keyCopier = function (key) {
  4547. // @ts-expect-error how to handle symbol ?
  4548. ctor.prototype[key] = methods[key];
  4549. };
  4550. Object.keys(methods).forEach(keyCopier);
  4551. // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
  4552. Object.getOwnPropertySymbols &&
  4553. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  4554. return ctor;
  4555. }
  4556. Collection.Iterator = Iterator;
  4557. mixin(Collection, {
  4558. // ### Conversion to other types
  4559. toArray: function toArray() {
  4560. assertNotInfinite(this.size);
  4561. var array = new Array(this.size || 0);
  4562. var useTuples = isKeyed(this);
  4563. var i = 0;
  4564. this.__iterate(function (v, k) {
  4565. // Keyed collections produce an array of tuples.
  4566. array[i++] = useTuples ? [k, v] : v;
  4567. });
  4568. return array;
  4569. },
  4570. toIndexedSeq: function toIndexedSeq() {
  4571. return new ToIndexedSequence(this);
  4572. },
  4573. toJS: function toJS$1() {
  4574. return toJS(this);
  4575. },
  4576. toKeyedSeq: function toKeyedSeq() {
  4577. return new ToKeyedSequence(this, true);
  4578. },
  4579. toMap: function toMap() {
  4580. // Use Late Binding here to solve the circular dependency.
  4581. return Map(this.toKeyedSeq());
  4582. },
  4583. toObject: toObject,
  4584. toOrderedMap: function toOrderedMap() {
  4585. // Use Late Binding here to solve the circular dependency.
  4586. return OrderedMap(this.toKeyedSeq());
  4587. },
  4588. toOrderedSet: function toOrderedSet() {
  4589. // Use Late Binding here to solve the circular dependency.
  4590. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  4591. },
  4592. toSet: function toSet() {
  4593. // Use Late Binding here to solve the circular dependency.
  4594. return Set(isKeyed(this) ? this.valueSeq() : this);
  4595. },
  4596. toSetSeq: function toSetSeq() {
  4597. return new ToSetSequence(this);
  4598. },
  4599. toSeq: function toSeq() {
  4600. return isIndexed(this)
  4601. ? this.toIndexedSeq()
  4602. : isKeyed(this)
  4603. ? this.toKeyedSeq()
  4604. : this.toSetSeq();
  4605. },
  4606. toStack: function toStack() {
  4607. // Use Late Binding here to solve the circular dependency.
  4608. return Stack(isKeyed(this) ? this.valueSeq() : this);
  4609. },
  4610. toList: function toList() {
  4611. // Use Late Binding here to solve the circular dependency.
  4612. return List(isKeyed(this) ? this.valueSeq() : this);
  4613. },
  4614. // ### Common JavaScript methods and properties
  4615. toString: function toString() {
  4616. return '[Collection]';
  4617. },
  4618. __toString: function __toString(head, tail) {
  4619. if (this.size === 0) {
  4620. return head + tail;
  4621. }
  4622. return (
  4623. head +
  4624. ' ' +
  4625. this.toSeq().map(this.__toStringMapper).join(', ') +
  4626. ' ' +
  4627. tail
  4628. );
  4629. },
  4630. // ### ES6 Collection methods (ES6 Array and Map)
  4631. concat: function concat() {
  4632. var values = [], len = arguments.length;
  4633. while ( len-- ) values[ len ] = arguments[ len ];
  4634. return reify(this, concatFactory(this, values));
  4635. },
  4636. includes: function includes(searchValue) {
  4637. return this.some(function (value) { return is(value, searchValue); });
  4638. },
  4639. entries: function entries() {
  4640. return this.__iterator(ITERATE_ENTRIES);
  4641. },
  4642. every: function every(predicate, context) {
  4643. assertNotInfinite(this.size);
  4644. var returnValue = true;
  4645. this.__iterate(function (v, k, c) {
  4646. if (!predicate.call(context, v, k, c)) {
  4647. returnValue = false;
  4648. return false;
  4649. }
  4650. });
  4651. return returnValue;
  4652. },
  4653. filter: function filter(predicate, context) {
  4654. return reify(this, filterFactory(this, predicate, context, true));
  4655. },
  4656. partition: function partition(predicate, context) {
  4657. return partitionFactory(this, predicate, context);
  4658. },
  4659. find: function find(predicate, context, notSetValue) {
  4660. var entry = this.findEntry(predicate, context);
  4661. return entry ? entry[1] : notSetValue;
  4662. },
  4663. forEach: function forEach(sideEffect, context) {
  4664. assertNotInfinite(this.size);
  4665. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  4666. },
  4667. join: function join(separator) {
  4668. assertNotInfinite(this.size);
  4669. separator = separator !== undefined ? '' + separator : ',';
  4670. var joined = '';
  4671. var isFirst = true;
  4672. this.__iterate(function (v) {
  4673. // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
  4674. isFirst ? (isFirst = false) : (joined += separator);
  4675. joined += v !== null && v !== undefined ? v.toString() : '';
  4676. });
  4677. return joined;
  4678. },
  4679. keys: function keys() {
  4680. return this.__iterator(ITERATE_KEYS);
  4681. },
  4682. map: function map(mapper, context) {
  4683. return reify(this, mapFactory(this, mapper, context));
  4684. },
  4685. reduce: function reduce$1(reducer, initialReduction, context) {
  4686. return reduce(
  4687. this,
  4688. reducer,
  4689. initialReduction,
  4690. context,
  4691. arguments.length < 2,
  4692. false
  4693. );
  4694. },
  4695. reduceRight: function reduceRight(reducer, initialReduction, context) {
  4696. return reduce(
  4697. this,
  4698. reducer,
  4699. initialReduction,
  4700. context,
  4701. arguments.length < 2,
  4702. true
  4703. );
  4704. },
  4705. reverse: function reverse() {
  4706. return reify(this, reverseFactory(this, true));
  4707. },
  4708. slice: function slice(begin, end) {
  4709. return reify(this, sliceFactory(this, begin, end, true));
  4710. },
  4711. some: function some(predicate, context) {
  4712. assertNotInfinite(this.size);
  4713. var returnValue = false;
  4714. this.__iterate(function (v, k, c) {
  4715. if (predicate.call(context, v, k, c)) {
  4716. returnValue = true;
  4717. return false;
  4718. }
  4719. });
  4720. return returnValue;
  4721. },
  4722. sort: function sort(comparator) {
  4723. return reify(this, sortFactory(this, comparator));
  4724. },
  4725. values: function values() {
  4726. return this.__iterator(ITERATE_VALUES);
  4727. },
  4728. // ### More sequential methods
  4729. butLast: function butLast() {
  4730. return this.slice(0, -1);
  4731. },
  4732. isEmpty: function isEmpty() {
  4733. return this.size !== undefined ? this.size === 0 : !this.some(function () { return true; });
  4734. },
  4735. count: function count(predicate, context) {
  4736. return ensureSize(
  4737. predicate ? this.toSeq().filter(predicate, context) : this
  4738. );
  4739. },
  4740. countBy: function countBy(grouper, context) {
  4741. return countByFactory(this, grouper, context);
  4742. },
  4743. equals: function equals(other) {
  4744. return deepEqual(this, other);
  4745. },
  4746. entrySeq: function entrySeq() {
  4747. // eslint-disable-next-line @typescript-eslint/no-this-alias
  4748. var collection = this;
  4749. if (collection._cache) {
  4750. // We cache as an entries array, so we can just return the cache!
  4751. return new ArraySeq(collection._cache);
  4752. }
  4753. var entriesSequence = collection.toSeq().map(entryMapper).toIndexedSeq();
  4754. entriesSequence.fromEntrySeq = function () { return collection.toSeq(); };
  4755. return entriesSequence;
  4756. },
  4757. filterNot: function filterNot(predicate, context) {
  4758. return this.filter(not(predicate), context);
  4759. },
  4760. findEntry: function findEntry(predicate, context, notSetValue) {
  4761. var found = notSetValue;
  4762. this.__iterate(function (v, k, c) {
  4763. if (predicate.call(context, v, k, c)) {
  4764. found = [k, v];
  4765. return false;
  4766. }
  4767. });
  4768. return found;
  4769. },
  4770. findKey: function findKey(predicate, context) {
  4771. var entry = this.findEntry(predicate, context);
  4772. return entry && entry[0];
  4773. },
  4774. findLast: function findLast(predicate, context, notSetValue) {
  4775. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  4776. },
  4777. findLastEntry: function findLastEntry(predicate, context, notSetValue) {
  4778. return this.toKeyedSeq()
  4779. .reverse()
  4780. .findEntry(predicate, context, notSetValue);
  4781. },
  4782. findLastKey: function findLastKey(predicate, context) {
  4783. return this.toKeyedSeq().reverse().findKey(predicate, context);
  4784. },
  4785. first: function first(notSetValue) {
  4786. return this.find(returnTrue, null, notSetValue);
  4787. },
  4788. flatMap: function flatMap(mapper, context) {
  4789. return reify(this, flatMapFactory(this, mapper, context));
  4790. },
  4791. flatten: function flatten(depth) {
  4792. return reify(this, flattenFactory(this, depth, true));
  4793. },
  4794. fromEntrySeq: function fromEntrySeq() {
  4795. return new FromEntriesSequence(this);
  4796. },
  4797. get: function get(searchKey, notSetValue) {
  4798. return this.find(function (_, key) { return is(key, searchKey); }, undefined, notSetValue);
  4799. },
  4800. getIn: getIn,
  4801. groupBy: function groupBy(grouper, context) {
  4802. return groupByFactory(this, grouper, context);
  4803. },
  4804. has: function has(searchKey) {
  4805. return this.get(searchKey, NOT_SET) !== NOT_SET;
  4806. },
  4807. hasIn: hasIn,
  4808. isSubset: function isSubset(iter) {
  4809. iter = typeof iter.includes === 'function' ? iter : Collection(iter);
  4810. return this.every(function (value) { return iter.includes(value); });
  4811. },
  4812. isSuperset: function isSuperset(iter) {
  4813. iter = typeof iter.isSubset === 'function' ? iter : Collection(iter);
  4814. return iter.isSubset(this);
  4815. },
  4816. keyOf: function keyOf(searchValue) {
  4817. return this.findKey(function (value) { return is(value, searchValue); });
  4818. },
  4819. keySeq: function keySeq() {
  4820. return this.toSeq().map(keyMapper).toIndexedSeq();
  4821. },
  4822. last: function last(notSetValue) {
  4823. return this.toSeq().reverse().first(notSetValue);
  4824. },
  4825. lastKeyOf: function lastKeyOf(searchValue) {
  4826. return this.toKeyedSeq().reverse().keyOf(searchValue);
  4827. },
  4828. max: function max(comparator) {
  4829. return maxFactory(this, comparator);
  4830. },
  4831. maxBy: function maxBy(mapper, comparator) {
  4832. return maxFactory(this, comparator, mapper);
  4833. },
  4834. min: function min(comparator) {
  4835. return maxFactory(
  4836. this,
  4837. comparator ? neg(comparator) : defaultNegComparator
  4838. );
  4839. },
  4840. minBy: function minBy(mapper, comparator) {
  4841. return maxFactory(
  4842. this,
  4843. comparator ? neg(comparator) : defaultNegComparator,
  4844. mapper
  4845. );
  4846. },
  4847. rest: function rest() {
  4848. return this.slice(1);
  4849. },
  4850. skip: function skip(amount) {
  4851. return amount === 0 ? this : this.slice(Math.max(0, amount));
  4852. },
  4853. skipLast: function skipLast(amount) {
  4854. return amount === 0 ? this : this.slice(0, -Math.max(0, amount));
  4855. },
  4856. skipWhile: function skipWhile(predicate, context) {
  4857. return reify(this, skipWhileFactory(this, predicate, context, true));
  4858. },
  4859. skipUntil: function skipUntil(predicate, context) {
  4860. return this.skipWhile(not(predicate), context);
  4861. },
  4862. sortBy: function sortBy(mapper, comparator) {
  4863. return reify(this, sortFactory(this, comparator, mapper));
  4864. },
  4865. take: function take(amount) {
  4866. return this.slice(0, Math.max(0, amount));
  4867. },
  4868. takeLast: function takeLast(amount) {
  4869. return this.slice(-Math.max(0, amount));
  4870. },
  4871. takeWhile: function takeWhile(predicate, context) {
  4872. return reify(this, takeWhileFactory(this, predicate, context));
  4873. },
  4874. takeUntil: function takeUntil(predicate, context) {
  4875. return this.takeWhile(not(predicate), context);
  4876. },
  4877. update: function update(fn) {
  4878. return fn(this);
  4879. },
  4880. valueSeq: function valueSeq() {
  4881. return this.toIndexedSeq();
  4882. },
  4883. // ### Hashable Object
  4884. hashCode: function hashCode() {
  4885. return this.__hash || (this.__hash = hashCollection(this));
  4886. },
  4887. // ### Internal
  4888. // abstract __iterate(fn, reverse)
  4889. // abstract __iterator(type, reverse)
  4890. });
  4891. var CollectionPrototype = Collection.prototype;
  4892. CollectionPrototype[IS_COLLECTION_SYMBOL] = true;
  4893. CollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.values;
  4894. CollectionPrototype.toJSON = CollectionPrototype.toArray;
  4895. CollectionPrototype.__toStringMapper = quoteString;
  4896. CollectionPrototype.inspect = CollectionPrototype.toSource = function () {
  4897. return this.toString();
  4898. };
  4899. CollectionPrototype.chain = CollectionPrototype.flatMap;
  4900. CollectionPrototype.contains = CollectionPrototype.includes;
  4901. mixin(KeyedCollection, {
  4902. // ### More sequential methods
  4903. flip: function flip() {
  4904. return reify(this, flipFactory(this));
  4905. },
  4906. mapEntries: function mapEntries(mapper, context) {
  4907. var this$1$1 = this;
  4908. var iterations = 0;
  4909. return reify(
  4910. this,
  4911. this.toSeq()
  4912. .map(function (v, k) { return mapper.call(context, [k, v], iterations++, this$1$1); })
  4913. .fromEntrySeq()
  4914. );
  4915. },
  4916. mapKeys: function mapKeys(mapper, context) {
  4917. var this$1$1 = this;
  4918. return reify(
  4919. this,
  4920. this.toSeq()
  4921. .flip()
  4922. .map(function (k, v) { return mapper.call(context, k, v, this$1$1); })
  4923. .flip()
  4924. );
  4925. },
  4926. });
  4927. var KeyedCollectionPrototype = KeyedCollection.prototype;
  4928. KeyedCollectionPrototype[IS_KEYED_SYMBOL] = true;
  4929. KeyedCollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.entries;
  4930. KeyedCollectionPrototype.toJSON = toObject;
  4931. KeyedCollectionPrototype.__toStringMapper = function (v, k) { return quoteString(k) + ': ' + quoteString(v); };
  4932. mixin(IndexedCollection, {
  4933. // ### Conversion to other types
  4934. toKeyedSeq: function toKeyedSeq() {
  4935. return new ToKeyedSequence(this, false);
  4936. },
  4937. // ### ES6 Collection methods (ES6 Array and Map)
  4938. filter: function filter(predicate, context) {
  4939. return reify(this, filterFactory(this, predicate, context, false));
  4940. },
  4941. findIndex: function findIndex(predicate, context) {
  4942. var entry = this.findEntry(predicate, context);
  4943. return entry ? entry[0] : -1;
  4944. },
  4945. indexOf: function indexOf(searchValue) {
  4946. var key = this.keyOf(searchValue);
  4947. return key === undefined ? -1 : key;
  4948. },
  4949. lastIndexOf: function lastIndexOf(searchValue) {
  4950. var key = this.lastKeyOf(searchValue);
  4951. return key === undefined ? -1 : key;
  4952. },
  4953. reverse: function reverse() {
  4954. return reify(this, reverseFactory(this, false));
  4955. },
  4956. slice: function slice(begin, end) {
  4957. return reify(this, sliceFactory(this, begin, end, false));
  4958. },
  4959. splice: function splice(index, removeNum /*, ...values*/) {
  4960. var numArgs = arguments.length;
  4961. removeNum = Math.max(removeNum || 0, 0);
  4962. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  4963. return this;
  4964. }
  4965. // If index is negative, it should resolve relative to the size of the
  4966. // collection. However size may be expensive to compute if not cached, so
  4967. // only call count() if the number is in fact negative.
  4968. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  4969. var spliced = this.slice(0, index);
  4970. return reify(
  4971. this,
  4972. numArgs === 1
  4973. ? spliced
  4974. : spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  4975. );
  4976. },
  4977. // ### More collection methods
  4978. findLastIndex: function findLastIndex(predicate, context) {
  4979. var entry = this.findLastEntry(predicate, context);
  4980. return entry ? entry[0] : -1;
  4981. },
  4982. first: function first(notSetValue) {
  4983. return this.get(0, notSetValue);
  4984. },
  4985. flatten: function flatten(depth) {
  4986. return reify(this, flattenFactory(this, depth, false));
  4987. },
  4988. get: function get(index, notSetValue) {
  4989. index = wrapIndex(this, index);
  4990. return index < 0 ||
  4991. this.size === Infinity ||
  4992. (this.size !== undefined && index > this.size)
  4993. ? notSetValue
  4994. : this.find(function (_, key) { return key === index; }, undefined, notSetValue);
  4995. },
  4996. has: function has(index) {
  4997. index = wrapIndex(this, index);
  4998. return (
  4999. index >= 0 &&
  5000. (this.size !== undefined
  5001. ? this.size === Infinity || index < this.size
  5002. : this.indexOf(index) !== -1)
  5003. );
  5004. },
  5005. interpose: function interpose(separator) {
  5006. return reify(this, interposeFactory(this, separator));
  5007. },
  5008. interleave: function interleave(/*...collections*/) {
  5009. var collections = [this].concat(arrCopy(arguments));
  5010. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, collections);
  5011. var interleaved = zipped.flatten(true);
  5012. if (zipped.size) {
  5013. interleaved.size = zipped.size * collections.length;
  5014. }
  5015. return reify(this, interleaved);
  5016. },
  5017. keySeq: function keySeq() {
  5018. return Range(0, this.size);
  5019. },
  5020. last: function last(notSetValue) {
  5021. return this.get(-1, notSetValue);
  5022. },
  5023. skipWhile: function skipWhile(predicate, context) {
  5024. return reify(this, skipWhileFactory(this, predicate, context, false));
  5025. },
  5026. zip: function zip(/*, ...collections */) {
  5027. var collections = [this].concat(arrCopy(arguments));
  5028. return reify(this, zipWithFactory(this, defaultZipper, collections));
  5029. },
  5030. zipAll: function zipAll(/*, ...collections */) {
  5031. var collections = [this].concat(arrCopy(arguments));
  5032. return reify(this, zipWithFactory(this, defaultZipper, collections, true));
  5033. },
  5034. zipWith: function zipWith(zipper /*, ...collections */) {
  5035. var collections = arrCopy(arguments);
  5036. collections[0] = this;
  5037. return reify(this, zipWithFactory(this, zipper, collections));
  5038. },
  5039. });
  5040. var IndexedCollectionPrototype = IndexedCollection.prototype;
  5041. IndexedCollectionPrototype[IS_INDEXED_SYMBOL] = true;
  5042. IndexedCollectionPrototype[IS_ORDERED_SYMBOL] = true;
  5043. mixin(SetCollection, {
  5044. // ### ES6 Collection methods (ES6 Array and Map)
  5045. get: function get(value, notSetValue) {
  5046. return this.has(value) ? value : notSetValue;
  5047. },
  5048. includes: function includes(value) {
  5049. return this.has(value);
  5050. },
  5051. // ### More sequential methods
  5052. keySeq: function keySeq() {
  5053. return this.valueSeq();
  5054. },
  5055. });
  5056. var SetCollectionPrototype = SetCollection.prototype;
  5057. SetCollectionPrototype.has = CollectionPrototype.includes;
  5058. SetCollectionPrototype.contains = SetCollectionPrototype.includes;
  5059. SetCollectionPrototype.keys = SetCollectionPrototype.values;
  5060. // Mixin subclasses
  5061. mixin(KeyedSeq, KeyedCollectionPrototype);
  5062. mixin(IndexedSeq, IndexedCollectionPrototype);
  5063. mixin(SetSeq, SetCollectionPrototype);
  5064. // #pragma Helper functions
  5065. function defaultZipper() {
  5066. return arrCopy(arguments);
  5067. }
  5068. /**
  5069. * True if `maybeOrderedSet` is an OrderedSet.
  5070. */
  5071. function isOrderedSet(maybeOrderedSet) {
  5072. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  5073. }
  5074. var OrderedSet = /*@__PURE__*/(function (Set) {
  5075. function OrderedSet(value) {
  5076. // eslint-disable-next-line no-constructor-return
  5077. return value === undefined || value === null
  5078. ? emptyOrderedSet()
  5079. : isOrderedSet(value)
  5080. ? value
  5081. : emptyOrderedSet().withMutations(function (set) {
  5082. var iter = SetCollection(value);
  5083. assertNotInfinite(iter.size);
  5084. iter.forEach(function (v) { return set.add(v); });
  5085. });
  5086. }
  5087. if ( Set ) OrderedSet.__proto__ = Set;
  5088. OrderedSet.prototype = Object.create( Set && Set.prototype );
  5089. OrderedSet.prototype.constructor = OrderedSet;
  5090. OrderedSet.of = function of (/*...values*/) {
  5091. return this(arguments);
  5092. };
  5093. OrderedSet.fromKeys = function fromKeys (value) {
  5094. return this(KeyedCollection(value).keySeq());
  5095. };
  5096. OrderedSet.prototype.toString = function toString () {
  5097. return this.__toString('OrderedSet {', '}');
  5098. };
  5099. return OrderedSet;
  5100. }(Set));
  5101. OrderedSet.isOrderedSet = isOrderedSet;
  5102. var OrderedSetPrototype = OrderedSet.prototype;
  5103. OrderedSetPrototype[IS_ORDERED_SYMBOL] = true;
  5104. OrderedSetPrototype.zip = IndexedCollectionPrototype.zip;
  5105. OrderedSetPrototype.zipWith = IndexedCollectionPrototype.zipWith;
  5106. OrderedSetPrototype.zipAll = IndexedCollectionPrototype.zipAll;
  5107. OrderedSetPrototype.__empty = emptyOrderedSet;
  5108. OrderedSetPrototype.__make = makeOrderedSet;
  5109. function makeOrderedSet(map, ownerID) {
  5110. var set = Object.create(OrderedSetPrototype);
  5111. set.size = map ? map.size : 0;
  5112. set._map = map;
  5113. set.__ownerID = ownerID;
  5114. return set;
  5115. }
  5116. var EMPTY_ORDERED_SET;
  5117. function emptyOrderedSet() {
  5118. return (
  5119. EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()))
  5120. );
  5121. }
  5122. /**
  5123. * Describes which item in a pair should be placed first when sorting
  5124. */
  5125. var PairSorting = {
  5126. LeftThenRight: -1,
  5127. RightThenLeft: 1,
  5128. };
  5129. function throwOnInvalidDefaultValues(defaultValues) {
  5130. if (isRecord(defaultValues)) {
  5131. throw new Error(
  5132. 'Can not call `Record` with an immutable Record as default values. Use a plain javascript object instead.'
  5133. );
  5134. }
  5135. if (isImmutable(defaultValues)) {
  5136. throw new Error(
  5137. 'Can not call `Record` with an immutable Collection as default values. Use a plain javascript object instead.'
  5138. );
  5139. }
  5140. if (defaultValues === null || typeof defaultValues !== 'object') {
  5141. throw new Error(
  5142. 'Can not call `Record` with a non-object as default values. Use a plain javascript object instead.'
  5143. );
  5144. }
  5145. }
  5146. var Record = function Record(defaultValues, name) {
  5147. var hasInitialized;
  5148. throwOnInvalidDefaultValues(defaultValues);
  5149. var RecordType = function Record(values) {
  5150. var this$1$1 = this;
  5151. if (values instanceof RecordType) {
  5152. return values;
  5153. }
  5154. if (!(this instanceof RecordType)) {
  5155. return new RecordType(values);
  5156. }
  5157. if (!hasInitialized) {
  5158. hasInitialized = true;
  5159. var keys = Object.keys(defaultValues);
  5160. var indices = (RecordTypePrototype._indices = {});
  5161. // Deprecated: left to attempt not to break any external code which
  5162. // relies on a ._name property existing on record instances.
  5163. // Use Record.getDescriptiveName() instead
  5164. RecordTypePrototype._name = name;
  5165. RecordTypePrototype._keys = keys;
  5166. RecordTypePrototype._defaultValues = defaultValues;
  5167. for (var i = 0; i < keys.length; i++) {
  5168. var propName = keys[i];
  5169. indices[propName] = i;
  5170. if (RecordTypePrototype[propName]) {
  5171. /* eslint-disable no-console */
  5172. // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
  5173. typeof console === 'object' &&
  5174. console.warn &&
  5175. console.warn(
  5176. 'Cannot define ' +
  5177. recordName(this) +
  5178. ' with property "' +
  5179. propName +
  5180. '" since that property name is part of the Record API.'
  5181. );
  5182. /* eslint-enable no-console */
  5183. } else {
  5184. setProp(RecordTypePrototype, propName);
  5185. }
  5186. }
  5187. }
  5188. this.__ownerID = undefined;
  5189. this._values = List().withMutations(function (l) {
  5190. l.setSize(this$1$1._keys.length);
  5191. KeyedCollection(values).forEach(function (v, k) {
  5192. l.set(this$1$1._indices[k], v === this$1$1._defaultValues[k] ? undefined : v);
  5193. });
  5194. });
  5195. return this;
  5196. };
  5197. var RecordTypePrototype = (RecordType.prototype =
  5198. Object.create(RecordPrototype));
  5199. RecordTypePrototype.constructor = RecordType;
  5200. if (name) {
  5201. RecordType.displayName = name;
  5202. }
  5203. // eslint-disable-next-line no-constructor-return
  5204. return RecordType;
  5205. };
  5206. Record.prototype.toString = function toString () {
  5207. var str = recordName(this) + ' { ';
  5208. var keys = this._keys;
  5209. var k;
  5210. for (var i = 0, l = keys.length; i !== l; i++) {
  5211. k = keys[i];
  5212. str += (i ? ', ' : '') + k + ': ' + quoteString(this.get(k));
  5213. }
  5214. return str + ' }';
  5215. };
  5216. Record.prototype.equals = function equals (other) {
  5217. return (
  5218. this === other ||
  5219. (isRecord(other) && recordSeq(this).equals(recordSeq(other)))
  5220. );
  5221. };
  5222. Record.prototype.hashCode = function hashCode () {
  5223. return recordSeq(this).hashCode();
  5224. };
  5225. // @pragma Access
  5226. Record.prototype.has = function has (k) {
  5227. return this._indices.hasOwnProperty(k);
  5228. };
  5229. Record.prototype.get = function get (k, notSetValue) {
  5230. if (!this.has(k)) {
  5231. return notSetValue;
  5232. }
  5233. var index = this._indices[k];
  5234. var value = this._values.get(index);
  5235. return value === undefined ? this._defaultValues[k] : value;
  5236. };
  5237. // @pragma Modification
  5238. Record.prototype.set = function set (k, v) {
  5239. if (this.has(k)) {
  5240. var newValues = this._values.set(
  5241. this._indices[k],
  5242. v === this._defaultValues[k] ? undefined : v
  5243. );
  5244. if (newValues !== this._values && !this.__ownerID) {
  5245. return makeRecord(this, newValues);
  5246. }
  5247. }
  5248. return this;
  5249. };
  5250. Record.prototype.remove = function remove (k) {
  5251. return this.set(k);
  5252. };
  5253. Record.prototype.clear = function clear () {
  5254. var newValues = this._values.clear().setSize(this._keys.length);
  5255. return this.__ownerID ? this : makeRecord(this, newValues);
  5256. };
  5257. Record.prototype.wasAltered = function wasAltered () {
  5258. return this._values.wasAltered();
  5259. };
  5260. Record.prototype.toSeq = function toSeq () {
  5261. return recordSeq(this);
  5262. };
  5263. Record.prototype.toJS = function toJS$1 () {
  5264. return toJS(this);
  5265. };
  5266. Record.prototype.entries = function entries () {
  5267. return this.__iterator(ITERATE_ENTRIES);
  5268. };
  5269. Record.prototype.__iterator = function __iterator (type, reverse) {
  5270. return recordSeq(this).__iterator(type, reverse);
  5271. };
  5272. Record.prototype.__iterate = function __iterate (fn, reverse) {
  5273. return recordSeq(this).__iterate(fn, reverse);
  5274. };
  5275. Record.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  5276. if (ownerID === this.__ownerID) {
  5277. return this;
  5278. }
  5279. var newValues = this._values.__ensureOwner(ownerID);
  5280. if (!ownerID) {
  5281. this.__ownerID = ownerID;
  5282. this._values = newValues;
  5283. return this;
  5284. }
  5285. return makeRecord(this, newValues, ownerID);
  5286. };
  5287. Record.isRecord = isRecord;
  5288. Record.getDescriptiveName = recordName;
  5289. var RecordPrototype = Record.prototype;
  5290. RecordPrototype[IS_RECORD_SYMBOL] = true;
  5291. RecordPrototype[DELETE] = RecordPrototype.remove;
  5292. RecordPrototype.deleteIn = RecordPrototype.removeIn = deleteIn;
  5293. RecordPrototype.getIn = getIn;
  5294. RecordPrototype.hasIn = CollectionPrototype.hasIn;
  5295. RecordPrototype.merge = merge$1;
  5296. RecordPrototype.mergeWith = mergeWith$1;
  5297. RecordPrototype.mergeIn = mergeIn;
  5298. RecordPrototype.mergeDeep = mergeDeep;
  5299. RecordPrototype.mergeDeepWith = mergeDeepWith;
  5300. RecordPrototype.mergeDeepIn = mergeDeepIn;
  5301. RecordPrototype.setIn = setIn;
  5302. RecordPrototype.update = update;
  5303. RecordPrototype.updateIn = updateIn$1;
  5304. RecordPrototype.withMutations = withMutations;
  5305. RecordPrototype.asMutable = asMutable;
  5306. RecordPrototype.asImmutable = asImmutable;
  5307. RecordPrototype[ITERATOR_SYMBOL] = RecordPrototype.entries;
  5308. RecordPrototype.toJSON = RecordPrototype.toObject =
  5309. CollectionPrototype.toObject;
  5310. RecordPrototype.inspect = RecordPrototype.toSource = function () {
  5311. return this.toString();
  5312. };
  5313. function makeRecord(likeRecord, values, ownerID) {
  5314. var record = Object.create(Object.getPrototypeOf(likeRecord));
  5315. record._values = values;
  5316. record.__ownerID = ownerID;
  5317. return record;
  5318. }
  5319. function recordName(record) {
  5320. return record.constructor.displayName || record.constructor.name || 'Record';
  5321. }
  5322. function recordSeq(record) {
  5323. return keyedSeqFromValue(record._keys.map(function (k) { return [k, record.get(k)]; }));
  5324. }
  5325. function setProp(prototype, name) {
  5326. try {
  5327. Object.defineProperty(prototype, name, {
  5328. get: function () {
  5329. return this.get(name);
  5330. },
  5331. set: function (value) {
  5332. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  5333. this.set(name, value);
  5334. },
  5335. });
  5336. // eslint-disable-next-line @typescript-eslint/no-unused-vars -- TODO enable eslint here
  5337. } catch (error) {
  5338. // Object.defineProperty failed. Probably IE8.
  5339. }
  5340. }
  5341. /**
  5342. * Returns a lazy Seq of `value` repeated `times` times. When `times` is
  5343. * undefined, returns an infinite sequence of `value`.
  5344. */
  5345. var Repeat = /*@__PURE__*/(function (IndexedSeq) {
  5346. function Repeat(value, times) {
  5347. if (!(this instanceof Repeat)) {
  5348. // eslint-disable-next-line no-constructor-return
  5349. return new Repeat(value, times);
  5350. }
  5351. this._value = value;
  5352. this.size = times === undefined ? Infinity : Math.max(0, times);
  5353. if (this.size === 0) {
  5354. if (EMPTY_REPEAT) {
  5355. // eslint-disable-next-line no-constructor-return
  5356. return EMPTY_REPEAT;
  5357. }
  5358. // eslint-disable-next-line @typescript-eslint/no-this-alias
  5359. EMPTY_REPEAT = this;
  5360. }
  5361. }
  5362. if ( IndexedSeq ) Repeat.__proto__ = IndexedSeq;
  5363. Repeat.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  5364. Repeat.prototype.constructor = Repeat;
  5365. Repeat.prototype.toString = function toString () {
  5366. if (this.size === 0) {
  5367. return 'Repeat []';
  5368. }
  5369. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  5370. };
  5371. Repeat.prototype.get = function get (index, notSetValue) {
  5372. return this.has(index) ? this._value : notSetValue;
  5373. };
  5374. Repeat.prototype.includes = function includes (searchValue) {
  5375. return is(this._value, searchValue);
  5376. };
  5377. Repeat.prototype.slice = function slice (begin, end) {
  5378. var size = this.size;
  5379. return wholeSlice(begin, end, size)
  5380. ? this
  5381. : new Repeat(
  5382. this._value,
  5383. resolveEnd(end, size) - resolveBegin(begin, size)
  5384. );
  5385. };
  5386. Repeat.prototype.reverse = function reverse () {
  5387. return this;
  5388. };
  5389. Repeat.prototype.indexOf = function indexOf (searchValue) {
  5390. if (is(this._value, searchValue)) {
  5391. return 0;
  5392. }
  5393. return -1;
  5394. };
  5395. Repeat.prototype.lastIndexOf = function lastIndexOf (searchValue) {
  5396. if (is(this._value, searchValue)) {
  5397. return this.size;
  5398. }
  5399. return -1;
  5400. };
  5401. Repeat.prototype.__iterate = function __iterate (fn, reverse) {
  5402. var size = this.size;
  5403. var i = 0;
  5404. while (i !== size) {
  5405. if (fn(this._value, reverse ? size - ++i : i++, this) === false) {
  5406. break;
  5407. }
  5408. }
  5409. return i;
  5410. };
  5411. Repeat.prototype.__iterator = function __iterator (type, reverse) {
  5412. var this$1$1 = this;
  5413. var size = this.size;
  5414. var i = 0;
  5415. return new Iterator(function () { return i === size
  5416. ? iteratorDone()
  5417. : iteratorValue(type, reverse ? size - ++i : i++, this$1$1._value); }
  5418. );
  5419. };
  5420. Repeat.prototype.equals = function equals (other) {
  5421. return other instanceof Repeat
  5422. ? is(this._value, other._value)
  5423. : deepEqual(this, other);
  5424. };
  5425. return Repeat;
  5426. }(IndexedSeq));
  5427. var EMPTY_REPEAT;
  5428. function fromJS(value, converter) {
  5429. return fromJSWith(
  5430. [],
  5431. converter || defaultConverter,
  5432. value,
  5433. '',
  5434. converter && converter.length > 2 ? [] : undefined,
  5435. { '': value }
  5436. );
  5437. }
  5438. function fromJSWith(stack, converter, value, key, keyPath, parentValue) {
  5439. if (
  5440. typeof value !== 'string' &&
  5441. !isImmutable(value) &&
  5442. (isArrayLike(value) || hasIterator(value) || isPlainObject(value))
  5443. ) {
  5444. if (~stack.indexOf(value)) {
  5445. throw new TypeError('Cannot convert circular structure to Immutable');
  5446. }
  5447. stack.push(value);
  5448. // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
  5449. keyPath && key !== '' && keyPath.push(key);
  5450. var converted = converter.call(
  5451. parentValue,
  5452. key,
  5453. Seq(value).map(function (v, k) { return fromJSWith(stack, converter, v, k, keyPath, value); }
  5454. ),
  5455. keyPath && keyPath.slice()
  5456. );
  5457. stack.pop();
  5458. // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
  5459. keyPath && keyPath.pop();
  5460. return converted;
  5461. }
  5462. return value;
  5463. }
  5464. function defaultConverter(k, v) {
  5465. // Effectively the opposite of "Collection.toSeq()"
  5466. return isIndexed(v) ? v.toList() : isKeyed(v) ? v.toMap() : v.toSet();
  5467. }
  5468. var version = "5.1.5";
  5469. /* eslint-disable import/order */
  5470. // Note: Iterable is deprecated
  5471. var Iterable = Collection;
  5472. 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 };