immutable.js 169 KB

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