immutable.js 169 KB

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