immutable.js 168 KB

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