immutable.js 166 KB

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