immutable.js 198 KB

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