immutable.es.js 156 KB

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