immutable.es.js 156 KB

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