immutable.js 167 KB

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