immutable.es.js 155 KB

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