immutable.es.js 152 KB

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