12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044 |
- /**
- * MIT License
- *
- * Copyright (c) 2014-present, Lee Byron and other contributors.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Immutable = {}));
- }(this, (function (exports) { 'use strict';
- var DELETE = 'delete';
- // Constants describing the size of trie nodes.
- var SHIFT = 5; // Resulted in best performance after ______?
- var SIZE = 1 << SHIFT;
- var MASK = SIZE - 1;
- // A consistent shared value representing "not set" which equals nothing other
- // than itself, and nothing that could be provided externally.
- var NOT_SET = {};
- // Boolean references, Rough equivalent of `bool &`.
- function MakeRef() {
- return { value: false };
- }
- function SetRef(ref) {
- if (ref) {
- ref.value = true;
- }
- }
- // A function which returns a value representing an "owner" for transient writes
- // to tries. The return value will only ever equal itself, and will not equal
- // the return of any subsequent call of this function.
- function OwnerID() {}
- function ensureSize(iter) {
- if (iter.size === undefined) {
- iter.size = iter.__iterate(returnTrue);
- }
- return iter.size;
- }
- function wrapIndex(iter, index) {
- // This implements "is array index" which the ECMAString spec defines as:
- //
- // A String property name P is an array index if and only if
- // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
- // to 2^32−1.
- //
- // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
- if (typeof index !== 'number') {
- var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
- if ('' + uint32Index !== index || uint32Index === 4294967295) {
- return NaN;
- }
- index = uint32Index;
- }
- return index < 0 ? ensureSize(iter) + index : index;
- }
- function returnTrue() {
- return true;
- }
- function wholeSlice(begin, end, size) {
- return (
- ((begin === 0 && !isNeg(begin)) ||
- (size !== undefined && begin <= -size)) &&
- (end === undefined || (size !== undefined && end >= size))
- );
- }
- function resolveBegin(begin, size) {
- return resolveIndex(begin, size, 0);
- }
- function resolveEnd(end, size) {
- return resolveIndex(end, size, size);
- }
- function resolveIndex(index, size, defaultIndex) {
- // Sanitize indices using this shorthand for ToInt32(argument)
- // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
- return index === undefined
- ? defaultIndex
- : isNeg(index)
- ? size === Infinity
- ? size
- : Math.max(0, size + index) | 0
- : size === undefined || size === index
- ? index
- : Math.min(size, index) | 0;
- }
- function isNeg(value) {
- // Account for -0 which is negative, but not less than 0.
- return value < 0 || (value === 0 && 1 / value === -Infinity);
- }
- var IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
- function isCollection(maybeCollection) {
- return Boolean(maybeCollection && maybeCollection[IS_COLLECTION_SYMBOL]);
- }
- var IS_KEYED_SYMBOL = '@@__IMMUTABLE_KEYED__@@';
- function isKeyed(maybeKeyed) {
- return Boolean(maybeKeyed && maybeKeyed[IS_KEYED_SYMBOL]);
- }
- var IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';
- function isIndexed(maybeIndexed) {
- return Boolean(maybeIndexed && maybeIndexed[IS_INDEXED_SYMBOL]);
- }
- function isAssociative(maybeAssociative) {
- return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
- }
- var Collection = function Collection(value) {
- // eslint-disable-next-line no-constructor-return
- return isCollection(value) ? value : Seq(value);
- };
- var KeyedCollection = /*@__PURE__*/(function (Collection) {
- function KeyedCollection(value) {
- // eslint-disable-next-line no-constructor-return
- return isKeyed(value) ? value : KeyedSeq(value);
- }
- if ( Collection ) KeyedCollection.__proto__ = Collection;
- KeyedCollection.prototype = Object.create( Collection && Collection.prototype );
- KeyedCollection.prototype.constructor = KeyedCollection;
- return KeyedCollection;
- }(Collection));
- var IndexedCollection = /*@__PURE__*/(function (Collection) {
- function IndexedCollection(value) {
- // eslint-disable-next-line no-constructor-return
- return isIndexed(value) ? value : IndexedSeq(value);
- }
- if ( Collection ) IndexedCollection.__proto__ = Collection;
- IndexedCollection.prototype = Object.create( Collection && Collection.prototype );
- IndexedCollection.prototype.constructor = IndexedCollection;
- return IndexedCollection;
- }(Collection));
- var SetCollection = /*@__PURE__*/(function (Collection) {
- function SetCollection(value) {
- // eslint-disable-next-line no-constructor-return
- return isCollection(value) && !isAssociative(value) ? value : SetSeq(value);
- }
- if ( Collection ) SetCollection.__proto__ = Collection;
- SetCollection.prototype = Object.create( Collection && Collection.prototype );
- SetCollection.prototype.constructor = SetCollection;
- return SetCollection;
- }(Collection));
- Collection.Keyed = KeyedCollection;
- Collection.Indexed = IndexedCollection;
- Collection.Set = SetCollection;
- var IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
- function isSeq(maybeSeq) {
- return Boolean(maybeSeq && maybeSeq[IS_SEQ_SYMBOL]);
- }
- var IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
- function isRecord(maybeRecord) {
- return Boolean(maybeRecord && maybeRecord[IS_RECORD_SYMBOL]);
- }
- function isImmutable(maybeImmutable) {
- return isCollection(maybeImmutable) || isRecord(maybeImmutable);
- }
- var IS_ORDERED_SYMBOL = '@@__IMMUTABLE_ORDERED__@@';
- function isOrdered(maybeOrdered) {
- return Boolean(maybeOrdered && maybeOrdered[IS_ORDERED_SYMBOL]);
- }
- var ITERATE_KEYS = 0;
- var ITERATE_VALUES = 1;
- var ITERATE_ENTRIES = 2;
- var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
- var FAUX_ITERATOR_SYMBOL = '@@iterator';
- var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
- var Iterator = function Iterator(next) {
- this.next = next;
- };
- Iterator.prototype.toString = function toString () {
- return '[Iterator]';
- };
- Iterator.KEYS = ITERATE_KEYS;
- Iterator.VALUES = ITERATE_VALUES;
- Iterator.ENTRIES = ITERATE_ENTRIES;
- Iterator.prototype.inspect = Iterator.prototype.toSource = function () {
- return this.toString();
- };
- Iterator.prototype[ITERATOR_SYMBOL] = function () {
- return this;
- };
- function iteratorValue(type, k, v, iteratorResult) {
- var value = type === 0 ? k : type === 1 ? v : [k, v];
- iteratorResult
- ? (iteratorResult.value = value)
- : (iteratorResult = {
- value: value,
- done: false,
- });
- return iteratorResult;
- }
- function iteratorDone() {
- return { value: undefined, done: true };
- }
- function hasIterator(maybeIterable) {
- if (Array.isArray(maybeIterable)) {
- // IE11 trick as it does not support `Symbol.iterator`
- return true;
- }
- return !!getIteratorFn(maybeIterable);
- }
- function isIterator(maybeIterator) {
- return maybeIterator && typeof maybeIterator.next === 'function';
- }
- function getIterator(iterable) {
- var iteratorFn = getIteratorFn(iterable);
- return iteratorFn && iteratorFn.call(iterable);
- }
- function getIteratorFn(iterable) {
- var iteratorFn =
- iterable &&
- ((REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
- iterable[FAUX_ITERATOR_SYMBOL]);
- if (typeof iteratorFn === 'function') {
- return iteratorFn;
- }
- }
- function isEntriesIterable(maybeIterable) {
- var iteratorFn = getIteratorFn(maybeIterable);
- return iteratorFn && iteratorFn === maybeIterable.entries;
- }
- function isKeysIterable(maybeIterable) {
- var iteratorFn = getIteratorFn(maybeIterable);
- return iteratorFn && iteratorFn === maybeIterable.keys;
- }
- var hasOwnProperty = Object.prototype.hasOwnProperty;
- function isArrayLike(value) {
- if (Array.isArray(value) || typeof value === 'string') {
- return true;
- }
- return (
- value &&
- typeof value === 'object' &&
- Number.isInteger(value.length) &&
- value.length >= 0 &&
- (value.length === 0
- ? // Only {length: 0} is considered Array-like.
- Object.keys(value).length === 1
- : // An object is only Array-like if it has a property where the last value
- // in the array-like may be found (which could be undefined).
- value.hasOwnProperty(value.length - 1))
- );
- }
- var Seq = /*@__PURE__*/(function (Collection) {
- function Seq(value) {
- // eslint-disable-next-line no-constructor-return
- return value === undefined || value === null
- ? emptySequence()
- : isImmutable(value)
- ? value.toSeq()
- : seqFromValue(value);
- }
- if ( Collection ) Seq.__proto__ = Collection;
- Seq.prototype = Object.create( Collection && Collection.prototype );
- Seq.prototype.constructor = Seq;
- Seq.prototype.toSeq = function toSeq () {
- return this;
- };
- Seq.prototype.toString = function toString () {
- return this.__toString('Seq {', '}');
- };
- Seq.prototype.cacheResult = function cacheResult () {
- if (!this._cache && this.__iterateUncached) {
- this._cache = this.entrySeq().toArray();
- this.size = this._cache.length;
- }
- return this;
- };
- // abstract __iterateUncached(fn, reverse)
- Seq.prototype.__iterate = function __iterate (fn, reverse) {
- var cache = this._cache;
- if (cache) {
- var size = cache.length;
- var i = 0;
- while (i !== size) {
- var entry = cache[reverse ? size - ++i : i++];
- if (fn(entry[1], entry[0], this) === false) {
- break;
- }
- }
- return i;
- }
- return this.__iterateUncached(fn, reverse);
- };
- // abstract __iteratorUncached(type, reverse)
- Seq.prototype.__iterator = function __iterator (type, reverse) {
- var cache = this._cache;
- if (cache) {
- var size = cache.length;
- var i = 0;
- return new Iterator(function () {
- if (i === size) {
- return iteratorDone();
- }
- var entry = cache[reverse ? size - ++i : i++];
- return iteratorValue(type, entry[0], entry[1]);
- });
- }
- return this.__iteratorUncached(type, reverse);
- };
- return Seq;
- }(Collection));
- var KeyedSeq = /*@__PURE__*/(function (Seq) {
- function KeyedSeq(value) {
- // eslint-disable-next-line no-constructor-return
- return value === undefined || value === null
- ? emptySequence().toKeyedSeq()
- : isCollection(value)
- ? isKeyed(value)
- ? value.toSeq()
- : value.fromEntrySeq()
- : isRecord(value)
- ? value.toSeq()
- : keyedSeqFromValue(value);
- }
- if ( Seq ) KeyedSeq.__proto__ = Seq;
- KeyedSeq.prototype = Object.create( Seq && Seq.prototype );
- KeyedSeq.prototype.constructor = KeyedSeq;
- KeyedSeq.prototype.toKeyedSeq = function toKeyedSeq () {
- return this;
- };
- return KeyedSeq;
- }(Seq));
- var IndexedSeq = /*@__PURE__*/(function (Seq) {
- function IndexedSeq(value) {
- // eslint-disable-next-line no-constructor-return
- return value === undefined || value === null
- ? emptySequence()
- : isCollection(value)
- ? isKeyed(value)
- ? value.entrySeq()
- : value.toIndexedSeq()
- : isRecord(value)
- ? value.toSeq().entrySeq()
- : indexedSeqFromValue(value);
- }
- if ( Seq ) IndexedSeq.__proto__ = Seq;
- IndexedSeq.prototype = Object.create( Seq && Seq.prototype );
- IndexedSeq.prototype.constructor = IndexedSeq;
- IndexedSeq.of = function of (/*...values*/) {
- return IndexedSeq(arguments);
- };
- IndexedSeq.prototype.toIndexedSeq = function toIndexedSeq () {
- return this;
- };
- IndexedSeq.prototype.toString = function toString () {
- return this.__toString('Seq [', ']');
- };
- return IndexedSeq;
- }(Seq));
- var SetSeq = /*@__PURE__*/(function (Seq) {
- function SetSeq(value) {
- // eslint-disable-next-line no-constructor-return
- return (
- isCollection(value) && !isAssociative(value) ? value : IndexedSeq(value)
- ).toSetSeq();
- }
- if ( Seq ) SetSeq.__proto__ = Seq;
- SetSeq.prototype = Object.create( Seq && Seq.prototype );
- SetSeq.prototype.constructor = SetSeq;
- SetSeq.of = function of (/*...values*/) {
- return SetSeq(arguments);
- };
- SetSeq.prototype.toSetSeq = function toSetSeq () {
- return this;
- };
- return SetSeq;
- }(Seq));
- Seq.isSeq = isSeq;
- Seq.Keyed = KeyedSeq;
- Seq.Set = SetSeq;
- Seq.Indexed = IndexedSeq;
- Seq.prototype[IS_SEQ_SYMBOL] = true;
- // #pragma Root Sequences
- var ArraySeq = /*@__PURE__*/(function (IndexedSeq) {
- function ArraySeq(array) {
- this._array = array;
- this.size = array.length;
- }
- if ( IndexedSeq ) ArraySeq.__proto__ = IndexedSeq;
- ArraySeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
- ArraySeq.prototype.constructor = ArraySeq;
- ArraySeq.prototype.get = function get (index, notSetValue) {
- return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
- };
- ArraySeq.prototype.__iterate = function __iterate (fn, reverse) {
- var array = this._array;
- var size = array.length;
- var i = 0;
- while (i !== size) {
- var ii = reverse ? size - ++i : i++;
- if (fn(array[ii], ii, this) === false) {
- break;
- }
- }
- return i;
- };
- ArraySeq.prototype.__iterator = function __iterator (type, reverse) {
- var array = this._array;
- var size = array.length;
- var i = 0;
- return new Iterator(function () {
- if (i === size) {
- return iteratorDone();
- }
- var ii = reverse ? size - ++i : i++;
- return iteratorValue(type, ii, array[ii]);
- });
- };
- return ArraySeq;
- }(IndexedSeq));
- var ObjectSeq = /*@__PURE__*/(function (KeyedSeq) {
- function ObjectSeq(object) {
- var keys = Object.keys(object).concat(
- Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : []
- );
- this._object = object;
- this._keys = keys;
- this.size = keys.length;
- }
- if ( KeyedSeq ) ObjectSeq.__proto__ = KeyedSeq;
- ObjectSeq.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
- ObjectSeq.prototype.constructor = ObjectSeq;
- ObjectSeq.prototype.get = function get (key, notSetValue) {
- if (notSetValue !== undefined && !this.has(key)) {
- return notSetValue;
- }
- return this._object[key];
- };
- ObjectSeq.prototype.has = function has (key) {
- return hasOwnProperty.call(this._object, key);
- };
- ObjectSeq.prototype.__iterate = function __iterate (fn, reverse) {
- var object = this._object;
- var keys = this._keys;
- var size = keys.length;
- var i = 0;
- while (i !== size) {
- var key = keys[reverse ? size - ++i : i++];
- if (fn(object[key], key, this) === false) {
- break;
- }
- }
- return i;
- };
- ObjectSeq.prototype.__iterator = function __iterator (type, reverse) {
- var object = this._object;
- var keys = this._keys;
- var size = keys.length;
- var i = 0;
- return new Iterator(function () {
- if (i === size) {
- return iteratorDone();
- }
- var key = keys[reverse ? size - ++i : i++];
- return iteratorValue(type, key, object[key]);
- });
- };
- return ObjectSeq;
- }(KeyedSeq));
- ObjectSeq.prototype[IS_ORDERED_SYMBOL] = true;
- var CollectionSeq = /*@__PURE__*/(function (IndexedSeq) {
- function CollectionSeq(collection) {
- this._collection = collection;
- this.size = collection.length || collection.size;
- }
- if ( IndexedSeq ) CollectionSeq.__proto__ = IndexedSeq;
- CollectionSeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
- CollectionSeq.prototype.constructor = CollectionSeq;
- CollectionSeq.prototype.__iterateUncached = function __iterateUncached (fn, reverse) {
- if (reverse) {
- return this.cacheResult().__iterate(fn, reverse);
- }
- var collection = this._collection;
- var iterator = getIterator(collection);
- var iterations = 0;
- if (isIterator(iterator)) {
- var step;
- while (!(step = iterator.next()).done) {
- if (fn(step.value, iterations++, this) === false) {
- break;
- }
- }
- }
- return iterations;
- };
- CollectionSeq.prototype.__iteratorUncached = function __iteratorUncached (type, reverse) {
- if (reverse) {
- return this.cacheResult().__iterator(type, reverse);
- }
- var collection = this._collection;
- var iterator = getIterator(collection);
- if (!isIterator(iterator)) {
- return new Iterator(iteratorDone);
- }
- var iterations = 0;
- return new Iterator(function () {
- var step = iterator.next();
- return step.done ? step : iteratorValue(type, iterations++, step.value);
- });
- };
- return CollectionSeq;
- }(IndexedSeq));
- // # pragma Helper functions
- var EMPTY_SEQ;
- function emptySequence() {
- return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
- }
- function keyedSeqFromValue(value) {
- var seq = maybeIndexedSeqFromValue(value);
- if (seq) {
- return seq.fromEntrySeq();
- }
- if (typeof value === 'object') {
- return new ObjectSeq(value);
- }
- throw new TypeError(
- 'Expected Array or collection object of [k, v] entries, or keyed object: ' +
- value
- );
- }
- function indexedSeqFromValue(value) {
- var seq = maybeIndexedSeqFromValue(value);
- if (seq) {
- return seq;
- }
- throw new TypeError(
- 'Expected Array or collection object of values: ' + value
- );
- }
- function seqFromValue(value) {
- var seq = maybeIndexedSeqFromValue(value);
- if (seq) {
- return isEntriesIterable(value)
- ? seq.fromEntrySeq()
- : isKeysIterable(value)
- ? seq.toSetSeq()
- : seq;
- }
- if (typeof value === 'object') {
- return new ObjectSeq(value);
- }
- throw new TypeError(
- 'Expected Array or collection object of values, or keyed object: ' + value
- );
- }
- function maybeIndexedSeqFromValue(value) {
- return isArrayLike(value)
- ? new ArraySeq(value)
- : hasIterator(value)
- ? new CollectionSeq(value)
- : undefined;
- }
- var IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
- function isMap(maybeMap) {
- return Boolean(maybeMap && maybeMap[IS_MAP_SYMBOL]);
- }
- function isOrderedMap(maybeOrderedMap) {
- return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
- }
- function isValueObject(maybeValue) {
- return Boolean(
- maybeValue &&
- typeof maybeValue.equals === 'function' &&
- typeof maybeValue.hashCode === 'function'
- );
- }
- /**
- * An extension of the "same-value" algorithm as [described for use by ES6 Map
- * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
- *
- * NaN is considered the same as NaN, however -0 and 0 are considered the same
- * value, which is different from the algorithm described by
- * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
- *
- * This is extended further to allow Objects to describe the values they
- * represent, by way of `valueOf` or `equals` (and `hashCode`).
- *
- * Note: because of this extension, the key equality of Immutable.Map and the
- * value equality of Immutable.Set will differ from ES6 Map and Set.
- *
- * ### Defining custom values
- *
- * The easiest way to describe the value an object represents is by implementing
- * `valueOf`. For example, `Date` represents a value by returning a unix
- * timestamp for `valueOf`:
- *
- * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
- * var date2 = new Date(1234567890000);
- * date1.valueOf(); // 1234567890000
- * assert( date1 !== date2 );
- * assert( Immutable.is( date1, date2 ) );
- *
- * Note: overriding `valueOf` may have other implications if you use this object
- * where JavaScript expects a primitive, such as implicit string coercion.
- *
- * For more complex types, especially collections, implementing `valueOf` may
- * not be performant. An alternative is to implement `equals` and `hashCode`.
- *
- * `equals` takes another object, presumably of similar type, and returns true
- * if it is equal. Equality is symmetrical, so the same result should be
- * returned if this and the argument are flipped.
- *
- * assert( a.equals(b) === b.equals(a) );
- *
- * `hashCode` returns a 32bit integer number representing the object which will
- * be used to determine how to store the value object in a Map or Set. You must
- * provide both or neither methods, one must not exist without the other.
- *
- * Also, an important relationship between these methods must be upheld: if two
- * values are equal, they *must* return the same hashCode. If the values are not
- * equal, they might have the same hashCode; this is called a hash collision,
- * and while undesirable for performance reasons, it is acceptable.
- *
- * if (a.equals(b)) {
- * assert( a.hashCode() === b.hashCode() );
- * }
- *
- * All Immutable collections are Value Objects: they implement `equals()`
- * and `hashCode()`.
- */
- function is(valueA, valueB) {
- if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
- return true;
- }
- if (!valueA || !valueB) {
- return false;
- }
- if (
- typeof valueA.valueOf === 'function' &&
- typeof valueB.valueOf === 'function'
- ) {
- valueA = valueA.valueOf();
- valueB = valueB.valueOf();
- if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
- return true;
- }
- if (!valueA || !valueB) {
- return false;
- }
- }
- return !!(
- isValueObject(valueA) &&
- isValueObject(valueB) &&
- valueA.equals(valueB)
- );
- }
- var imul =
- typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2
- ? Math.imul
- : function imul(a, b) {
- a |= 0; // int
- b |= 0; // int
- var c = a & 0xffff;
- var d = b & 0xffff;
- // Shift by 0 fixes the sign on the high part.
- return (c * d + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0)) | 0; // int
- };
- // v8 has an optimization for storing 31-bit signed numbers.
- // Values which have either 00 or 11 as the high order bits qualify.
- // This function drops the highest order bit in a signed number, maintaining
- // the sign bit.
- function smi(i32) {
- return ((i32 >>> 1) & 0x40000000) | (i32 & 0xbfffffff);
- }
- var defaultValueOf = Object.prototype.valueOf;
- function hash(o) {
- if (o == null) {
- return hashNullish(o);
- }
- if (typeof o.hashCode === 'function') {
- // Drop any high bits from accidentally long hash codes.
- return smi(o.hashCode(o));
- }
- var v = valueOf(o);
- if (v == null) {
- return hashNullish(v);
- }
- switch (typeof v) {
- case 'boolean':
- // The hash values for built-in constants are a 1 value for each 5-byte
- // shift region expect for the first, which encodes the value. This
- // reduces the odds of a hash collision for these common values.
- return v ? 0x42108421 : 0x42108420;
- case 'number':
- return hashNumber(v);
- case 'string':
- return v.length > STRING_HASH_CACHE_MIN_STRLEN
- ? cachedHashString(v)
- : hashString(v);
- case 'object':
- case 'function':
- return hashJSObj(v);
- case 'symbol':
- return hashSymbol(v);
- default:
- if (typeof v.toString === 'function') {
- return hashString(v.toString());
- }
- throw new Error('Value type ' + typeof v + ' cannot be hashed.');
- }
- }
- function hashNullish(nullish) {
- return nullish === null ? 0x42108422 : /* undefined */ 0x42108423;
- }
- // Compress arbitrarily large numbers into smi hashes.
- function hashNumber(n) {
- if (n !== n || n === Infinity) {
- return 0;
- }
- var hash = n | 0;
- if (hash !== n) {
- hash ^= n * 0xffffffff;
- }
- while (n > 0xffffffff) {
- n /= 0xffffffff;
- hash ^= n;
- }
- return smi(hash);
- }
- function cachedHashString(string) {
- var hashed = stringHashCache[string];
- if (hashed === undefined) {
- hashed = hashString(string);
- if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
- STRING_HASH_CACHE_SIZE = 0;
- stringHashCache = {};
- }
- STRING_HASH_CACHE_SIZE++;
- stringHashCache[string] = hashed;
- }
- return hashed;
- }
- // http://jsperf.com/hashing-strings
- function hashString(string) {
- // This is the hash from JVM
- // The hash code for a string is computed as
- // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
- // where s[i] is the ith character of the string and n is the length of
- // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
- // (exclusive) by dropping high bits.
- var hashed = 0;
- for (var ii = 0; ii < string.length; ii++) {
- hashed = (31 * hashed + string.charCodeAt(ii)) | 0;
- }
- return smi(hashed);
- }
- function hashSymbol(sym) {
- var hashed = symbolMap[sym];
- if (hashed !== undefined) {
- return hashed;
- }
- hashed = nextHash();
- symbolMap[sym] = hashed;
- return hashed;
- }
- function hashJSObj(obj) {
- var hashed;
- if (usingWeakMap) {
- hashed = weakMap.get(obj);
- if (hashed !== undefined) {
- return hashed;
- }
- }
- hashed = obj[UID_HASH_KEY];
- if (hashed !== undefined) {
- return hashed;
- }
- if (!canDefineProperty) {
- hashed = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
- if (hashed !== undefined) {
- return hashed;
- }
- hashed = getIENodeHash(obj);
- if (hashed !== undefined) {
- return hashed;
- }
- }
- hashed = nextHash();
- if (usingWeakMap) {
- weakMap.set(obj, hashed);
- } else if (isExtensible !== undefined && isExtensible(obj) === false) {
- throw new Error('Non-extensible objects are not allowed as keys.');
- } else if (canDefineProperty) {
- Object.defineProperty(obj, UID_HASH_KEY, {
- enumerable: false,
- configurable: false,
- writable: false,
- value: hashed,
- });
- } else if (
- obj.propertyIsEnumerable !== undefined &&
- obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable
- ) {
- // Since we can't define a non-enumerable property on the object
- // we'll hijack one of the less-used non-enumerable properties to
- // save our hash on it. Since this is a function it will not show up in
- // `JSON.stringify` which is what we want.
- obj.propertyIsEnumerable = function () {
- return this.constructor.prototype.propertyIsEnumerable.apply(
- this,
- arguments
- );
- };
- obj.propertyIsEnumerable[UID_HASH_KEY] = hashed;
- } else if (obj.nodeType !== undefined) {
- // At this point we couldn't get the IE `uniqueID` to use as a hash
- // and we couldn't use a non-enumerable property to exploit the
- // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
- // itself.
- obj[UID_HASH_KEY] = hashed;
- } else {
- throw new Error('Unable to set a non-enumerable property on object.');
- }
- return hashed;
- }
- // Get references to ES5 object methods.
- var isExtensible = Object.isExtensible;
- // True if Object.defineProperty works as expected. IE8 fails this test.
- var canDefineProperty = (function () {
- try {
- Object.defineProperty({}, '@', {});
- return true;
- } catch (e) {
- return false;
- }
- })();
- // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
- // and avoid memory leaks from the IE cloneNode bug.
- function getIENodeHash(node) {
- if (node && node.nodeType > 0) {
- switch (node.nodeType) {
- case 1: // Element
- return node.uniqueID;
- case 9: // Document
- return node.documentElement && node.documentElement.uniqueID;
- }
- }
- }
- function valueOf(obj) {
- return obj.valueOf !== defaultValueOf && typeof obj.valueOf === 'function'
- ? obj.valueOf(obj)
- : obj;
- }
- function nextHash() {
- var nextHash = ++_objHashUID;
- if (_objHashUID & 0x40000000) {
- _objHashUID = 0;
- }
- return nextHash;
- }
- // If possible, use a WeakMap.
- var usingWeakMap = typeof WeakMap === 'function';
- var weakMap;
- if (usingWeakMap) {
- weakMap = new WeakMap();
- }
- var symbolMap = Object.create(null);
- var _objHashUID = 0;
- var UID_HASH_KEY = '__immutablehash__';
- if (typeof Symbol === 'function') {
- UID_HASH_KEY = Symbol(UID_HASH_KEY);
- }
- var STRING_HASH_CACHE_MIN_STRLEN = 16;
- var STRING_HASH_CACHE_MAX_SIZE = 255;
- var STRING_HASH_CACHE_SIZE = 0;
- var stringHashCache = {};
- var ToKeyedSequence = /*@__PURE__*/(function (KeyedSeq) {
- function ToKeyedSequence(indexed, useKeys) {
- this._iter = indexed;
- this._useKeys = useKeys;
- this.size = indexed.size;
- }
- if ( KeyedSeq ) ToKeyedSequence.__proto__ = KeyedSeq;
- ToKeyedSequence.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
- ToKeyedSequence.prototype.constructor = ToKeyedSequence;
- ToKeyedSequence.prototype.get = function get (key, notSetValue) {
- return this._iter.get(key, notSetValue);
- };
- ToKeyedSequence.prototype.has = function has (key) {
- return this._iter.has(key);
- };
- ToKeyedSequence.prototype.valueSeq = function valueSeq () {
- return this._iter.valueSeq();
- };
- ToKeyedSequence.prototype.reverse = function reverse () {
- var this$1$1 = this;
- var reversedSequence = reverseFactory(this, true);
- if (!this._useKeys) {
- reversedSequence.valueSeq = function () { return this$1$1._iter.toSeq().reverse(); };
- }
- return reversedSequence;
- };
- ToKeyedSequence.prototype.map = function map (mapper, context) {
- var this$1$1 = this;
- var mappedSequence = mapFactory(this, mapper, context);
- if (!this._useKeys) {
- mappedSequence.valueSeq = function () { return this$1$1._iter.toSeq().map(mapper, context); };
- }
- return mappedSequence;
- };
- ToKeyedSequence.prototype.__iterate = function __iterate (fn, reverse) {
- var this$1$1 = this;
- return this._iter.__iterate(function (v, k) { return fn(v, k, this$1$1); }, reverse);
- };
- ToKeyedSequence.prototype.__iterator = function __iterator (type, reverse) {
- return this._iter.__iterator(type, reverse);
- };
- return ToKeyedSequence;
- }(KeyedSeq));
- ToKeyedSequence.prototype[IS_ORDERED_SYMBOL] = true;
- var ToIndexedSequence = /*@__PURE__*/(function (IndexedSeq) {
- function ToIndexedSequence(iter) {
- this._iter = iter;
- this.size = iter.size;
- }
- if ( IndexedSeq ) ToIndexedSequence.__proto__ = IndexedSeq;
- ToIndexedSequence.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
- ToIndexedSequence.prototype.constructor = ToIndexedSequence;
- ToIndexedSequence.prototype.includes = function includes (value) {
- return this._iter.includes(value);
- };
- ToIndexedSequence.prototype.__iterate = function __iterate (fn, reverse) {
- var this$1$1 = this;
- var i = 0;
- reverse && ensureSize(this);
- return this._iter.__iterate(
- function (v) { return fn(v, reverse ? this$1$1.size - ++i : i++, this$1$1); },
- reverse
- );
- };
- ToIndexedSequence.prototype.__iterator = function __iterator (type, reverse) {
- var this$1$1 = this;
- var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
- var i = 0;
- reverse && ensureSize(this);
- return new Iterator(function () {
- var step = iterator.next();
- return step.done
- ? step
- : iteratorValue(
- type,
- reverse ? this$1$1.size - ++i : i++,
- step.value,
- step
- );
- });
- };
- return ToIndexedSequence;
- }(IndexedSeq));
- var ToSetSequence = /*@__PURE__*/(function (SetSeq) {
- function ToSetSequence(iter) {
- this._iter = iter;
- this.size = iter.size;
- }
- if ( SetSeq ) ToSetSequence.__proto__ = SetSeq;
- ToSetSequence.prototype = Object.create( SetSeq && SetSeq.prototype );
- ToSetSequence.prototype.constructor = ToSetSequence;
- ToSetSequence.prototype.has = function has (key) {
- return this._iter.includes(key);
- };
- ToSetSequence.prototype.__iterate = function __iterate (fn, reverse) {
- var this$1$1 = this;
- return this._iter.__iterate(function (v) { return fn(v, v, this$1$1); }, reverse);
- };
- ToSetSequence.prototype.__iterator = function __iterator (type, reverse) {
- var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
- return new Iterator(function () {
- var step = iterator.next();
- return step.done
- ? step
- : iteratorValue(type, step.value, step.value, step);
- });
- };
- return ToSetSequence;
- }(SetSeq));
- var FromEntriesSequence = /*@__PURE__*/(function (KeyedSeq) {
- function FromEntriesSequence(entries) {
- this._iter = entries;
- this.size = entries.size;
- }
- if ( KeyedSeq ) FromEntriesSequence.__proto__ = KeyedSeq;
- FromEntriesSequence.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
- FromEntriesSequence.prototype.constructor = FromEntriesSequence;
- FromEntriesSequence.prototype.entrySeq = function entrySeq () {
- return this._iter.toSeq();
- };
- FromEntriesSequence.prototype.__iterate = function __iterate (fn, reverse) {
- var this$1$1 = this;
- return this._iter.__iterate(function (entry) {
- // Check if entry exists first so array access doesn't throw for holes
- // in the parent iteration.
- if (entry) {
- validateEntry(entry);
- var indexedCollection = isCollection(entry);
- return fn(
- indexedCollection ? entry.get(1) : entry[1],
- indexedCollection ? entry.get(0) : entry[0],
- this$1$1
- );
- }
- }, reverse);
- };
- FromEntriesSequence.prototype.__iterator = function __iterator (type, reverse) {
- var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
- return new Iterator(function () {
- while (true) {
- var step = iterator.next();
- if (step.done) {
- return step;
- }
- var entry = step.value;
- // Check if entry exists first so array access doesn't throw for holes
- // in the parent iteration.
- if (entry) {
- validateEntry(entry);
- var indexedCollection = isCollection(entry);
- return iteratorValue(
- type,
- indexedCollection ? entry.get(0) : entry[0],
- indexedCollection ? entry.get(1) : entry[1],
- step
- );
- }
- }
- });
- };
- return FromEntriesSequence;
- }(KeyedSeq));
- ToIndexedSequence.prototype.cacheResult =
- ToKeyedSequence.prototype.cacheResult =
- ToSetSequence.prototype.cacheResult =
- FromEntriesSequence.prototype.cacheResult =
- cacheResultThrough;
- function flipFactory(collection) {
- var flipSequence = makeSequence(collection);
- flipSequence._iter = collection;
- flipSequence.size = collection.size;
- flipSequence.flip = function () { return collection; };
- flipSequence.reverse = function () {
- var reversedSequence = collection.reverse.apply(this); // super.reverse()
- reversedSequence.flip = function () { return collection.reverse(); };
- return reversedSequence;
- };
- flipSequence.has = function (key) { return collection.includes(key); };
- flipSequence.includes = function (key) { return collection.has(key); };
- flipSequence.cacheResult = cacheResultThrough;
- flipSequence.__iterateUncached = function (fn, reverse) {
- var this$1$1 = this;
- return collection.__iterate(function (v, k) { return fn(k, v, this$1$1) !== false; }, reverse);
- };
- flipSequence.__iteratorUncached = function (type, reverse) {
- if (type === ITERATE_ENTRIES) {
- var iterator = collection.__iterator(type, reverse);
- return new Iterator(function () {
- var step = iterator.next();
- if (!step.done) {
- var k = step.value[0];
- step.value[0] = step.value[1];
- step.value[1] = k;
- }
- return step;
- });
- }
- return collection.__iterator(
- type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
- reverse
- );
- };
- return flipSequence;
- }
- function mapFactory(collection, mapper, context) {
- var mappedSequence = makeSequence(collection);
- mappedSequence.size = collection.size;
- mappedSequence.has = function (key) { return collection.has(key); };
- mappedSequence.get = function (key, notSetValue) {
- var v = collection.get(key, NOT_SET);
- return v === NOT_SET
- ? notSetValue
- : mapper.call(context, v, key, collection);
- };
- mappedSequence.__iterateUncached = function (fn, reverse) {
- var this$1$1 = this;
- return collection.__iterate(
- function (v, k, c) { return fn(mapper.call(context, v, k, c), k, this$1$1) !== false; },
- reverse
- );
- };
- mappedSequence.__iteratorUncached = function (type, reverse) {
- var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
- return new Iterator(function () {
- var step = iterator.next();
- if (step.done) {
- return step;
- }
- var entry = step.value;
- var key = entry[0];
- return iteratorValue(
- type,
- key,
- mapper.call(context, entry[1], key, collection),
- step
- );
- });
- };
- return mappedSequence;
- }
- function reverseFactory(collection, useKeys) {
- var this$1$1 = this;
- var reversedSequence = makeSequence(collection);
- reversedSequence._iter = collection;
- reversedSequence.size = collection.size;
- reversedSequence.reverse = function () { return collection; };
- if (collection.flip) {
- reversedSequence.flip = function () {
- var flipSequence = flipFactory(collection);
- flipSequence.reverse = function () { return collection.flip(); };
- return flipSequence;
- };
- }
- reversedSequence.get = function (key, notSetValue) { return collection.get(useKeys ? key : -1 - key, notSetValue); };
- reversedSequence.has = function (key) { return collection.has(useKeys ? key : -1 - key); };
- reversedSequence.includes = function (value) { return collection.includes(value); };
- reversedSequence.cacheResult = cacheResultThrough;
- reversedSequence.__iterate = function (fn, reverse) {
- var this$1$1 = this;
- var i = 0;
- reverse && ensureSize(collection);
- return collection.__iterate(
- function (v, k) { return fn(v, useKeys ? k : reverse ? this$1$1.size - ++i : i++, this$1$1); },
- !reverse
- );
- };
- reversedSequence.__iterator = function (type, reverse) {
- var i = 0;
- reverse && ensureSize(collection);
- var iterator = collection.__iterator(ITERATE_ENTRIES, !reverse);
- return new Iterator(function () {
- var step = iterator.next();
- if (step.done) {
- return step;
- }
- var entry = step.value;
- return iteratorValue(
- type,
- useKeys ? entry[0] : reverse ? this$1$1.size - ++i : i++,
- entry[1],
- step
- );
- });
- };
- return reversedSequence;
- }
- function filterFactory(collection, predicate, context, useKeys) {
- var filterSequence = makeSequence(collection);
- if (useKeys) {
- filterSequence.has = function (key) {
- var v = collection.get(key, NOT_SET);
- return v !== NOT_SET && !!predicate.call(context, v, key, collection);
- };
- filterSequence.get = function (key, notSetValue) {
- var v = collection.get(key, NOT_SET);
- return v !== NOT_SET && predicate.call(context, v, key, collection)
- ? v
- : notSetValue;
- };
- }
- filterSequence.__iterateUncached = function (fn, reverse) {
- var this$1$1 = this;
- var iterations = 0;
- collection.__iterate(function (v, k, c) {
- if (predicate.call(context, v, k, c)) {
- iterations++;
- return fn(v, useKeys ? k : iterations - 1, this$1$1);
- }
- }, reverse);
- return iterations;
- };
- filterSequence.__iteratorUncached = function (type, reverse) {
- var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
- var iterations = 0;
- return new Iterator(function () {
- while (true) {
- var step = iterator.next();
- if (step.done) {
- return step;
- }
- var entry = step.value;
- var key = entry[0];
- var value = entry[1];
- if (predicate.call(context, value, key, collection)) {
- return iteratorValue(type, useKeys ? key : iterations++, value, step);
- }
- }
- });
- };
- return filterSequence;
- }
- function countByFactory(collection, grouper, context) {
- var groups = Map().asMutable();
- collection.__iterate(function (v, k) {
- groups.update(grouper.call(context, v, k, collection), 0, function (a) { return a + 1; });
- });
- return groups.asImmutable();
- }
- function groupByFactory(collection, grouper, context) {
- var isKeyedIter = isKeyed(collection);
- var groups = (isOrdered(collection) ? OrderedMap() : Map()).asMutable();
- collection.__iterate(function (v, k) {
- groups.update(
- grouper.call(context, v, k, collection),
- function (a) { return ((a = a || []), a.push(isKeyedIter ? [k, v] : v), a); }
- );
- });
- var coerce = collectionClass(collection);
- return groups.map(function (arr) { return reify(collection, coerce(arr)); }).asImmutable();
- }
- function partitionFactory(collection, predicate, context) {
- var isKeyedIter = isKeyed(collection);
- var groups = [[], []];
- collection.__iterate(function (v, k) {
- groups[predicate.call(context, v, k, collection) ? 1 : 0].push(
- isKeyedIter ? [k, v] : v
- );
- });
- var coerce = collectionClass(collection);
- return groups.map(function (arr) { return reify(collection, coerce(arr)); });
- }
- function sliceFactory(collection, begin, end, useKeys) {
- var originalSize = collection.size;
- if (wholeSlice(begin, end, originalSize)) {
- return collection;
- }
- // begin or end can not be resolved if they were provided as negative numbers and
- // this collection's size is unknown. In that case, cache first so there is
- // a known size and these do not resolve to NaN.
- if (typeof originalSize === 'undefined' && (begin < 0 || end < 0)) {
- return sliceFactory(collection.toSeq().cacheResult(), begin, end, useKeys);
- }
- var resolvedBegin = resolveBegin(begin, originalSize);
- var resolvedEnd = resolveEnd(end, originalSize);
- // Note: resolvedEnd is undefined when the original sequence's length is
- // unknown and this slice did not supply an end and should contain all
- // elements after resolvedBegin.
- // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
- var resolvedSize = resolvedEnd - resolvedBegin;
- var sliceSize;
- if (resolvedSize === resolvedSize) {
- sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
- }
- var sliceSeq = makeSequence(collection);
- // If collection.size is undefined, the size of the realized sliceSeq is
- // unknown at this point unless the number of items to slice is 0
- sliceSeq.size =
- sliceSize === 0 ? sliceSize : (collection.size && sliceSize) || undefined;
- if (!useKeys && isSeq(collection) && sliceSize >= 0) {
- sliceSeq.get = function (index, notSetValue) {
- index = wrapIndex(this, index);
- return index >= 0 && index < sliceSize
- ? collection.get(index + resolvedBegin, notSetValue)
- : notSetValue;
- };
- }
- sliceSeq.__iterateUncached = function (fn, reverse) {
- var this$1$1 = this;
- if (sliceSize === 0) {
- return 0;
- }
- if (reverse) {
- return this.cacheResult().__iterate(fn, reverse);
- }
- var skipped = 0;
- var isSkipping = true;
- var iterations = 0;
- collection.__iterate(function (v, k) {
- if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
- iterations++;
- return (
- fn(v, useKeys ? k : iterations - 1, this$1$1) !== false &&
- iterations !== sliceSize
- );
- }
- });
- return iterations;
- };
- sliceSeq.__iteratorUncached = function (type, reverse) {
- if (sliceSize !== 0 && reverse) {
- return this.cacheResult().__iterator(type, reverse);
- }
- // Don't bother instantiating parent iterator if taking 0.
- if (sliceSize === 0) {
- return new Iterator(iteratorDone);
- }
- var iterator = collection.__iterator(type, reverse);
- var skipped = 0;
- var iterations = 0;
- return new Iterator(function () {
- while (skipped++ < resolvedBegin) {
- iterator.next();
- }
- if (++iterations > sliceSize) {
- return iteratorDone();
- }
- var step = iterator.next();
- if (useKeys || type === ITERATE_VALUES || step.done) {
- return step;
- }
- if (type === ITERATE_KEYS) {
- return iteratorValue(type, iterations - 1, undefined, step);
- }
- return iteratorValue(type, iterations - 1, step.value[1], step);
- });
- };
- return sliceSeq;
- }
- function takeWhileFactory(collection, predicate, context) {
- var takeSequence = makeSequence(collection);
- takeSequence.__iterateUncached = function (fn, reverse) {
- var this$1$1 = this;
- if (reverse) {
- return this.cacheResult().__iterate(fn, reverse);
- }
- var iterations = 0;
- collection.__iterate(
- function (v, k, c) { return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$1$1); }
- );
- return iterations;
- };
- takeSequence.__iteratorUncached = function (type, reverse) {
- var this$1$1 = this;
- if (reverse) {
- return this.cacheResult().__iterator(type, reverse);
- }
- var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
- var iterating = true;
- return new Iterator(function () {
- if (!iterating) {
- return iteratorDone();
- }
- var step = iterator.next();
- if (step.done) {
- return step;
- }
- var entry = step.value;
- var k = entry[0];
- var v = entry[1];
- if (!predicate.call(context, v, k, this$1$1)) {
- iterating = false;
- return iteratorDone();
- }
- return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
- });
- };
- return takeSequence;
- }
- function skipWhileFactory(collection, predicate, context, useKeys) {
- var skipSequence = makeSequence(collection);
- skipSequence.__iterateUncached = function (fn, reverse) {
- var this$1$1 = this;
- if (reverse) {
- return this.cacheResult().__iterate(fn, reverse);
- }
- var isSkipping = true;
- var iterations = 0;
- collection.__iterate(function (v, k, c) {
- if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
- iterations++;
- return fn(v, useKeys ? k : iterations - 1, this$1$1);
- }
- });
- return iterations;
- };
- skipSequence.__iteratorUncached = function (type, reverse) {
- var this$1$1 = this;
- if (reverse) {
- return this.cacheResult().__iterator(type, reverse);
- }
- var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
- var skipping = true;
- var iterations = 0;
- return new Iterator(function () {
- var step;
- var k;
- var v;
- do {
- step = iterator.next();
- if (step.done) {
- if (useKeys || type === ITERATE_VALUES) {
- return step;
- }
- if (type === ITERATE_KEYS) {
- return iteratorValue(type, iterations++, undefined, step);
- }
- return iteratorValue(type, iterations++, step.value[1], step);
- }
- var entry = step.value;
- k = entry[0];
- v = entry[1];
- skipping && (skipping = predicate.call(context, v, k, this$1$1));
- } while (skipping);
- return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
- });
- };
- return skipSequence;
- }
- function concatFactory(collection, values) {
- var isKeyedCollection = isKeyed(collection);
- var iters = [collection]
- .concat(values)
- .map(function (v) {
- if (!isCollection(v)) {
- v = isKeyedCollection
- ? keyedSeqFromValue(v)
- : indexedSeqFromValue(Array.isArray(v) ? v : [v]);
- } else if (isKeyedCollection) {
- v = KeyedCollection(v);
- }
- return v;
- })
- .filter(function (v) { return v.size !== 0; });
- if (iters.length === 0) {
- return collection;
- }
- if (iters.length === 1) {
- var singleton = iters[0];
- if (
- singleton === collection ||
- (isKeyedCollection && isKeyed(singleton)) ||
- (isIndexed(collection) && isIndexed(singleton))
- ) {
- return singleton;
- }
- }
- var concatSeq = new ArraySeq(iters);
- if (isKeyedCollection) {
- concatSeq = concatSeq.toKeyedSeq();
- } else if (!isIndexed(collection)) {
- concatSeq = concatSeq.toSetSeq();
- }
- concatSeq = concatSeq.flatten(true);
- concatSeq.size = iters.reduce(function (sum, seq) {
- if (sum !== undefined) {
- var size = seq.size;
- if (size !== undefined) {
- return sum + size;
- }
- }
- }, 0);
- return concatSeq;
- }
- function flattenFactory(collection, depth, useKeys) {
- var flatSequence = makeSequence(collection);
- flatSequence.__iterateUncached = function (fn, reverse) {
- if (reverse) {
- return this.cacheResult().__iterate(fn, reverse);
- }
- var iterations = 0;
- var stopped = false;
- function flatDeep(iter, currentDepth) {
- iter.__iterate(function (v, k) {
- if ((!depth || currentDepth < depth) && isCollection(v)) {
- flatDeep(v, currentDepth + 1);
- } else {
- iterations++;
- if (fn(v, useKeys ? k : iterations - 1, flatSequence) === false) {
- stopped = true;
- }
- }
- return !stopped;
- }, reverse);
- }
- flatDeep(collection, 0);
- return iterations;
- };
- flatSequence.__iteratorUncached = function (type, reverse) {
- if (reverse) {
- return this.cacheResult().__iterator(type, reverse);
- }
- var iterator = collection.__iterator(type, reverse);
- var stack = [];
- var iterations = 0;
- return new Iterator(function () {
- while (iterator) {
- var step = iterator.next();
- if (step.done !== false) {
- iterator = stack.pop();
- continue;
- }
- var v = step.value;
- if (type === ITERATE_ENTRIES) {
- v = v[1];
- }
- if ((!depth || stack.length < depth) && isCollection(v)) {
- stack.push(iterator);
- iterator = v.__iterator(type, reverse);
- } else {
- return useKeys ? step : iteratorValue(type, iterations++, v, step);
- }
- }
- return iteratorDone();
- });
- };
- return flatSequence;
- }
- function flatMapFactory(collection, mapper, context) {
- var coerce = collectionClass(collection);
- return collection
- .toSeq()
- .map(function (v, k) { return coerce(mapper.call(context, v, k, collection)); })
- .flatten(true);
- }
- function interposeFactory(collection, separator) {
- var interposedSequence = makeSequence(collection);
- interposedSequence.size = collection.size && collection.size * 2 - 1;
- interposedSequence.__iterateUncached = function (fn, reverse) {
- var this$1$1 = this;
- var iterations = 0;
- collection.__iterate(
- function (v) { return (!iterations || fn(separator, iterations++, this$1$1) !== false) &&
- fn(v, iterations++, this$1$1) !== false; },
- reverse
- );
- return iterations;
- };
- interposedSequence.__iteratorUncached = function (type, reverse) {
- var iterator = collection.__iterator(ITERATE_VALUES, reverse);
- var iterations = 0;
- var step;
- return new Iterator(function () {
- if (!step || iterations % 2) {
- step = iterator.next();
- if (step.done) {
- return step;
- }
- }
- return iterations % 2
- ? iteratorValue(type, iterations++, separator)
- : iteratorValue(type, iterations++, step.value, step);
- });
- };
- return interposedSequence;
- }
- function sortFactory(collection, comparator, mapper) {
- if (!comparator) {
- comparator = defaultComparator;
- }
- var isKeyedCollection = isKeyed(collection);
- var index = 0;
- var entries = collection
- .toSeq()
- .map(function (v, k) { return [k, v, index++, mapper ? mapper(v, k, collection) : v]; })
- .valueSeq()
- .toArray();
- entries
- .sort(function (a, b) { return comparator(a[3], b[3]) || a[2] - b[2]; })
- .forEach(
- isKeyedCollection
- ? function (v, i) {
- entries[i].length = 2;
- }
- : function (v, i) {
- entries[i] = v[1];
- }
- );
- return isKeyedCollection
- ? KeyedSeq(entries)
- : isIndexed(collection)
- ? IndexedSeq(entries)
- : SetSeq(entries);
- }
- function maxFactory(collection, comparator, mapper) {
- if (!comparator) {
- comparator = defaultComparator;
- }
- if (mapper) {
- var entry = collection
- .toSeq()
- .map(function (v, k) { return [v, mapper(v, k, collection)]; })
- .reduce(function (a, b) { return (maxCompare(comparator, a[1], b[1]) ? b : a); });
- return entry && entry[0];
- }
- return collection.reduce(function (a, b) { return (maxCompare(comparator, a, b) ? b : a); });
- }
- function maxCompare(comparator, a, b) {
- var comp = comparator(b, a);
- // b is considered the new max if the comparator declares them equal, but
- // they are not equal and b is in fact a nullish value.
- return (
- (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) ||
- comp > 0
- );
- }
- function zipWithFactory(keyIter, zipper, iters, zipAll) {
- var zipSequence = makeSequence(keyIter);
- var sizes = new ArraySeq(iters).map(function (i) { return i.size; });
- zipSequence.size = zipAll ? sizes.max() : sizes.min();
- // Note: this a generic base implementation of __iterate in terms of
- // __iterator which may be more generically useful in the future.
- zipSequence.__iterate = function (fn, reverse) {
- /* generic:
- var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
- var step;
- var iterations = 0;
- while (!(step = iterator.next()).done) {
- iterations++;
- if (fn(step.value[1], step.value[0], this) === false) {
- break;
- }
- }
- return iterations;
- */
- // indexed:
- var iterator = this.__iterator(ITERATE_VALUES, reverse);
- var step;
- var iterations = 0;
- while (!(step = iterator.next()).done) {
- if (fn(step.value, iterations++, this) === false) {
- break;
- }
- }
- return iterations;
- };
- zipSequence.__iteratorUncached = function (type, reverse) {
- var iterators = iters.map(
- function (i) { return ((i = Collection(i)), getIterator(reverse ? i.reverse() : i)); }
- );
- var iterations = 0;
- var isDone = false;
- return new Iterator(function () {
- var steps;
- if (!isDone) {
- steps = iterators.map(function (i) { return i.next(); });
- isDone = zipAll ? steps.every(function (s) { return s.done; }) : steps.some(function (s) { return s.done; });
- }
- if (isDone) {
- return iteratorDone();
- }
- return iteratorValue(
- type,
- iterations++,
- zipper.apply(
- null,
- steps.map(function (s) { return s.value; })
- )
- );
- });
- };
- return zipSequence;
- }
- // #pragma Helper Functions
- function reify(iter, seq) {
- return iter === seq ? iter : isSeq(iter) ? seq : iter.constructor(seq);
- }
- function validateEntry(entry) {
- if (entry !== Object(entry)) {
- throw new TypeError('Expected [K, V] tuple: ' + entry);
- }
- }
- function collectionClass(collection) {
- return isKeyed(collection)
- ? KeyedCollection
- : isIndexed(collection)
- ? IndexedCollection
- : SetCollection;
- }
- function makeSequence(collection) {
- return Object.create(
- (isKeyed(collection)
- ? KeyedSeq
- : isIndexed(collection)
- ? IndexedSeq
- : SetSeq
- ).prototype
- );
- }
- function cacheResultThrough() {
- if (this._iter.cacheResult) {
- this._iter.cacheResult();
- this.size = this._iter.size;
- return this;
- }
- return Seq.prototype.cacheResult.call(this);
- }
- function defaultComparator(a, b) {
- if (a === undefined && b === undefined) {
- return 0;
- }
- if (a === undefined) {
- return 1;
- }
- if (b === undefined) {
- return -1;
- }
- return a > b ? 1 : a < b ? -1 : 0;
- }
- function arrCopy(arr, offset) {
- offset = offset || 0;
- var len = Math.max(0, arr.length - offset);
- var newArr = new Array(len);
- for (var ii = 0; ii < len; ii++) {
- newArr[ii] = arr[ii + offset];
- }
- return newArr;
- }
- function invariant(condition, error) {
- if (!condition) { throw new Error(error); }
- }
- function assertNotInfinite(size) {
- invariant(
- size !== Infinity,
- 'Cannot perform this action with an infinite size.'
- );
- }
- function coerceKeyPath(keyPath) {
- if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
- return keyPath;
- }
- if (isOrdered(keyPath)) {
- return keyPath.toArray();
- }
- throw new TypeError(
- 'Invalid keyPath: expected Ordered Collection or Array: ' + keyPath
- );
- }
- var toString = Object.prototype.toString;
- function isPlainObject(value) {
- // The base prototype's toString deals with Argument objects and native namespaces like Math
- if (
- !value ||
- typeof value !== 'object' ||
- toString.call(value) !== '[object Object]'
- ) {
- return false;
- }
- var proto = Object.getPrototypeOf(value);
- if (proto === null) {
- return true;
- }
- // Iteratively going up the prototype chain is needed for cross-realm environments (differing contexts, iframes, etc)
- var parentProto = proto;
- var nextProto = Object.getPrototypeOf(proto);
- while (nextProto !== null) {
- parentProto = nextProto;
- nextProto = Object.getPrototypeOf(parentProto);
- }
- return parentProto === proto;
- }
- /**
- * Returns true if the value is a potentially-persistent data structure, either
- * provided by Immutable.js or a plain Array or Object.
- */
- function isDataStructure(value) {
- return (
- typeof value === 'object' &&
- (isImmutable(value) || Array.isArray(value) || isPlainObject(value))
- );
- }
- function quoteString(value) {
- try {
- return typeof value === 'string' ? JSON.stringify(value) : String(value);
- } catch (_ignoreError) {
- return JSON.stringify(value);
- }
- }
- function has(collection, key) {
- return isImmutable(collection)
- ? collection.has(key)
- : isDataStructure(collection) && hasOwnProperty.call(collection, key);
- }
- function get(collection, key, notSetValue) {
- return isImmutable(collection)
- ? collection.get(key, notSetValue)
- : !has(collection, key)
- ? notSetValue
- : typeof collection.get === 'function'
- ? collection.get(key)
- : collection[key];
- }
- function shallowCopy(from) {
- if (Array.isArray(from)) {
- return arrCopy(from);
- }
- var to = {};
- for (var key in from) {
- if (hasOwnProperty.call(from, key)) {
- to[key] = from[key];
- }
- }
- return to;
- }
- function remove(collection, key) {
- if (!isDataStructure(collection)) {
- throw new TypeError(
- 'Cannot update non-data-structure value: ' + collection
- );
- }
- if (isImmutable(collection)) {
- if (!collection.remove) {
- throw new TypeError(
- 'Cannot update immutable value without .remove() method: ' + collection
- );
- }
- return collection.remove(key);
- }
- if (!hasOwnProperty.call(collection, key)) {
- return collection;
- }
- var collectionCopy = shallowCopy(collection);
- if (Array.isArray(collectionCopy)) {
- collectionCopy.splice(key, 1);
- } else {
- delete collectionCopy[key];
- }
- return collectionCopy;
- }
- function set(collection, key, value) {
- if (!isDataStructure(collection)) {
- throw new TypeError(
- 'Cannot update non-data-structure value: ' + collection
- );
- }
- if (isImmutable(collection)) {
- if (!collection.set) {
- throw new TypeError(
- 'Cannot update immutable value without .set() method: ' + collection
- );
- }
- return collection.set(key, value);
- }
- if (hasOwnProperty.call(collection, key) && value === collection[key]) {
- return collection;
- }
- var collectionCopy = shallowCopy(collection);
- collectionCopy[key] = value;
- return collectionCopy;
- }
- function updateIn$1(collection, keyPath, notSetValue, updater) {
- if (!updater) {
- updater = notSetValue;
- notSetValue = undefined;
- }
- var updatedValue = updateInDeeply(
- isImmutable(collection),
- collection,
- coerceKeyPath(keyPath),
- 0,
- notSetValue,
- updater
- );
- return updatedValue === NOT_SET ? notSetValue : updatedValue;
- }
- function updateInDeeply(
- inImmutable,
- existing,
- keyPath,
- i,
- notSetValue,
- updater
- ) {
- var wasNotSet = existing === NOT_SET;
- if (i === keyPath.length) {
- var existingValue = wasNotSet ? notSetValue : existing;
- var newValue = updater(existingValue);
- return newValue === existingValue ? existing : newValue;
- }
- if (!wasNotSet && !isDataStructure(existing)) {
- throw new TypeError(
- 'Cannot update within non-data-structure value in path [' +
- keyPath.slice(0, i).map(quoteString) +
- ']: ' +
- existing
- );
- }
- var key = keyPath[i];
- var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
- var nextUpdated = updateInDeeply(
- nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
- nextExisting,
- keyPath,
- i + 1,
- notSetValue,
- updater
- );
- return nextUpdated === nextExisting
- ? existing
- : nextUpdated === NOT_SET
- ? remove(existing, key)
- : set(
- wasNotSet ? (inImmutable ? emptyMap() : {}) : existing,
- key,
- nextUpdated
- );
- }
- function setIn$1(collection, keyPath, value) {
- return updateIn$1(collection, keyPath, NOT_SET, function () { return value; });
- }
- function setIn(keyPath, v) {
- return setIn$1(this, keyPath, v);
- }
- function removeIn(collection, keyPath) {
- return updateIn$1(collection, keyPath, function () { return NOT_SET; });
- }
- function deleteIn(keyPath) {
- return removeIn(this, keyPath);
- }
- function update$1(collection, key, notSetValue, updater) {
- return updateIn$1(collection, [key], notSetValue, updater);
- }
- function update(key, notSetValue, updater) {
- return arguments.length === 1
- ? key(this)
- : update$1(this, key, notSetValue, updater);
- }
- function updateIn(keyPath, notSetValue, updater) {
- return updateIn$1(this, keyPath, notSetValue, updater);
- }
- function merge$1() {
- var iters = [], len = arguments.length;
- while ( len-- ) iters[ len ] = arguments[ len ];
- return mergeIntoKeyedWith(this, iters);
- }
- function mergeWith$1(merger) {
- var iters = [], len = arguments.length - 1;
- while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
- if (typeof merger !== 'function') {
- throw new TypeError('Invalid merger function: ' + merger);
- }
- return mergeIntoKeyedWith(this, iters, merger);
- }
- function mergeIntoKeyedWith(collection, collections, merger) {
- var iters = [];
- for (var ii = 0; ii < collections.length; ii++) {
- var collection$1 = KeyedCollection(collections[ii]);
- if (collection$1.size !== 0) {
- iters.push(collection$1);
- }
- }
- if (iters.length === 0) {
- return collection;
- }
- if (
- collection.toSeq().size === 0 &&
- !collection.__ownerID &&
- iters.length === 1
- ) {
- return collection.constructor(iters[0]);
- }
- return collection.withMutations(function (collection) {
- var mergeIntoCollection = merger
- ? function (value, key) {
- update$1(collection, key, NOT_SET, function (oldVal) { return oldVal === NOT_SET ? value : merger(oldVal, value, key); }
- );
- }
- : function (value, key) {
- collection.set(key, value);
- };
- for (var ii = 0; ii < iters.length; ii++) {
- iters[ii].forEach(mergeIntoCollection);
- }
- });
- }
- function merge(collection) {
- var sources = [], len = arguments.length - 1;
- while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
- return mergeWithSources(collection, sources);
- }
- function mergeWith(merger, collection) {
- var sources = [], len = arguments.length - 2;
- while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
- return mergeWithSources(collection, sources, merger);
- }
- function mergeDeep$1(collection) {
- var sources = [], len = arguments.length - 1;
- while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
- return mergeDeepWithSources(collection, sources);
- }
- function mergeDeepWith$1(merger, collection) {
- var sources = [], len = arguments.length - 2;
- while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
- return mergeDeepWithSources(collection, sources, merger);
- }
- function mergeDeepWithSources(collection, sources, merger) {
- return mergeWithSources(collection, sources, deepMergerWith(merger));
- }
- function mergeWithSources(collection, sources, merger) {
- if (!isDataStructure(collection)) {
- throw new TypeError(
- 'Cannot merge into non-data-structure value: ' + collection
- );
- }
- if (isImmutable(collection)) {
- return typeof merger === 'function' && collection.mergeWith
- ? collection.mergeWith.apply(collection, [ merger ].concat( sources ))
- : collection.merge
- ? collection.merge.apply(collection, sources)
- : collection.concat.apply(collection, sources);
- }
- var isArray = Array.isArray(collection);
- var merged = collection;
- var Collection = isArray ? IndexedCollection : KeyedCollection;
- var mergeItem = isArray
- ? function (value) {
- // Copy on write
- if (merged === collection) {
- merged = shallowCopy(merged);
- }
- merged.push(value);
- }
- : function (value, key) {
- var hasVal = hasOwnProperty.call(merged, key);
- var nextVal =
- hasVal && merger ? merger(merged[key], value, key) : value;
- if (!hasVal || nextVal !== merged[key]) {
- // Copy on write
- if (merged === collection) {
- merged = shallowCopy(merged);
- }
- merged[key] = nextVal;
- }
- };
- for (var i = 0; i < sources.length; i++) {
- Collection(sources[i]).forEach(mergeItem);
- }
- return merged;
- }
- function deepMergerWith(merger) {
- function deepMerger(oldValue, newValue, key) {
- return isDataStructure(oldValue) &&
- isDataStructure(newValue) &&
- areMergeable(oldValue, newValue)
- ? mergeWithSources(oldValue, [newValue], deepMerger)
- : merger
- ? merger(oldValue, newValue, key)
- : newValue;
- }
- return deepMerger;
- }
- /**
- * It's unclear what the desired behavior is for merging two collections that
- * fall into separate categories between keyed, indexed, or set-like, so we only
- * consider them mergeable if they fall into the same category.
- */
- function areMergeable(oldDataStructure, newDataStructure) {
- var oldSeq = Seq(oldDataStructure);
- var newSeq = Seq(newDataStructure);
- // This logic assumes that a sequence can only fall into one of the three
- // categories mentioned above (since there's no `isSetLike()` method).
- return (
- isIndexed(oldSeq) === isIndexed(newSeq) &&
- isKeyed(oldSeq) === isKeyed(newSeq)
- );
- }
- function mergeDeep() {
- var iters = [], len = arguments.length;
- while ( len-- ) iters[ len ] = arguments[ len ];
- return mergeDeepWithSources(this, iters);
- }
- function mergeDeepWith(merger) {
- var iters = [], len = arguments.length - 1;
- while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
- return mergeDeepWithSources(this, iters, merger);
- }
- function mergeIn(keyPath) {
- var iters = [], len = arguments.length - 1;
- while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
- return updateIn$1(this, keyPath, emptyMap(), function (m) { return mergeWithSources(m, iters); });
- }
- function mergeDeepIn(keyPath) {
- var iters = [], len = arguments.length - 1;
- while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
- return updateIn$1(this, keyPath, emptyMap(), function (m) { return mergeDeepWithSources(m, iters); }
- );
- }
- function withMutations(fn) {
- var mutable = this.asMutable();
- fn(mutable);
- return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
- }
- function asMutable() {
- return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
- }
- function asImmutable() {
- return this.__ensureOwner();
- }
- function wasAltered() {
- return this.__altered;
- }
- var Map = /*@__PURE__*/(function (KeyedCollection) {
- function Map(value) {
- // eslint-disable-next-line no-constructor-return
- return value === undefined || value === null
- ? emptyMap()
- : isMap(value) && !isOrdered(value)
- ? value
- : emptyMap().withMutations(function (map) {
- var iter = KeyedCollection(value);
- assertNotInfinite(iter.size);
- iter.forEach(function (v, k) { return map.set(k, v); });
- });
- }
- if ( KeyedCollection ) Map.__proto__ = KeyedCollection;
- Map.prototype = Object.create( KeyedCollection && KeyedCollection.prototype );
- Map.prototype.constructor = Map;
- Map.of = function of () {
- var keyValues = [], len = arguments.length;
- while ( len-- ) keyValues[ len ] = arguments[ len ];
- return emptyMap().withMutations(function (map) {
- for (var i = 0; i < keyValues.length; i += 2) {
- if (i + 1 >= keyValues.length) {
- throw new Error('Missing value for key: ' + keyValues[i]);
- }
- map.set(keyValues[i], keyValues[i + 1]);
- }
- });
- };
- Map.prototype.toString = function toString () {
- return this.__toString('Map {', '}');
- };
- // @pragma Access
- Map.prototype.get = function get (k, notSetValue) {
- return this._root
- ? this._root.get(0, undefined, k, notSetValue)
- : notSetValue;
- };
- // @pragma Modification
- Map.prototype.set = function set (k, v) {
- return updateMap(this, k, v);
- };
- Map.prototype.remove = function remove (k) {
- return updateMap(this, k, NOT_SET);
- };
- Map.prototype.deleteAll = function deleteAll (keys) {
- var collection = Collection(keys);
- if (collection.size === 0) {
- return this;
- }
- return this.withMutations(function (map) {
- collection.forEach(function (key) { return map.remove(key); });
- });
- };
- Map.prototype.clear = function clear () {
- if (this.size === 0) {
- return this;
- }
- if (this.__ownerID) {
- this.size = 0;
- this._root = null;
- this.__hash = undefined;
- this.__altered = true;
- return this;
- }
- return emptyMap();
- };
- // @pragma Composition
- Map.prototype.sort = function sort (comparator) {
- // Late binding
- return OrderedMap(sortFactory(this, comparator));
- };
- Map.prototype.sortBy = function sortBy (mapper, comparator) {
- // Late binding
- return OrderedMap(sortFactory(this, comparator, mapper));
- };
- Map.prototype.map = function map (mapper, context) {
- var this$1$1 = this;
- return this.withMutations(function (map) {
- map.forEach(function (value, key) {
- map.set(key, mapper.call(context, value, key, this$1$1));
- });
- });
- };
- // @pragma Mutability
- Map.prototype.__iterator = function __iterator (type, reverse) {
- return new MapIterator(this, type, reverse);
- };
- Map.prototype.__iterate = function __iterate (fn, reverse) {
- var this$1$1 = this;
- var iterations = 0;
- this._root &&
- this._root.iterate(function (entry) {
- iterations++;
- return fn(entry[1], entry[0], this$1$1);
- }, reverse);
- return iterations;
- };
- Map.prototype.__ensureOwner = function __ensureOwner (ownerID) {
- if (ownerID === this.__ownerID) {
- return this;
- }
- if (!ownerID) {
- if (this.size === 0) {
- return emptyMap();
- }
- this.__ownerID = ownerID;
- this.__altered = false;
- return this;
- }
- return makeMap(this.size, this._root, ownerID, this.__hash);
- };
- return Map;
- }(KeyedCollection));
- Map.isMap = isMap;
- var MapPrototype = Map.prototype;
- MapPrototype[IS_MAP_SYMBOL] = true;
- MapPrototype[DELETE] = MapPrototype.remove;
- MapPrototype.removeAll = MapPrototype.deleteAll;
- MapPrototype.setIn = setIn;
- MapPrototype.removeIn = MapPrototype.deleteIn = deleteIn;
- MapPrototype.update = update;
- MapPrototype.updateIn = updateIn;
- MapPrototype.merge = MapPrototype.concat = merge$1;
- MapPrototype.mergeWith = mergeWith$1;
- MapPrototype.mergeDeep = mergeDeep;
- MapPrototype.mergeDeepWith = mergeDeepWith;
- MapPrototype.mergeIn = mergeIn;
- MapPrototype.mergeDeepIn = mergeDeepIn;
- MapPrototype.withMutations = withMutations;
- MapPrototype.wasAltered = wasAltered;
- MapPrototype.asImmutable = asImmutable;
- MapPrototype['@@transducer/init'] = MapPrototype.asMutable = asMutable;
- MapPrototype['@@transducer/step'] = function (result, arr) {
- return result.set(arr[0], arr[1]);
- };
- MapPrototype['@@transducer/result'] = function (obj) {
- return obj.asImmutable();
- };
- // #pragma Trie Nodes
- var ArrayMapNode = function ArrayMapNode(ownerID, entries) {
- this.ownerID = ownerID;
- this.entries = entries;
- };
- ArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
- var entries = this.entries;
- for (var ii = 0, len = entries.length; ii < len; ii++) {
- if (is(key, entries[ii][0])) {
- return entries[ii][1];
- }
- }
- return notSetValue;
- };
- ArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
- var removed = value === NOT_SET;
- var entries = this.entries;
- var idx = 0;
- var len = entries.length;
- for (; idx < len; idx++) {
- if (is(key, entries[idx][0])) {
- break;
- }
- }
- var exists = idx < len;
- if (exists ? entries[idx][1] === value : removed) {
- return this;
- }
- SetRef(didAlter);
- (removed || !exists) && SetRef(didChangeSize);
- if (removed && entries.length === 1) {
- return; // undefined
- }
- if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
- return createNodes(ownerID, entries, key, value);
- }
- var isEditable = ownerID && ownerID === this.ownerID;
- var newEntries = isEditable ? entries : arrCopy(entries);
- if (exists) {
- if (removed) {
- idx === len - 1
- ? newEntries.pop()
- : (newEntries[idx] = newEntries.pop());
- } else {
- newEntries[idx] = [key, value];
- }
- } else {
- newEntries.push([key, value]);
- }
- if (isEditable) {
- this.entries = newEntries;
- return this;
- }
- return new ArrayMapNode(ownerID, newEntries);
- };
- var BitmapIndexedNode = function BitmapIndexedNode(ownerID, bitmap, nodes) {
- this.ownerID = ownerID;
- this.bitmap = bitmap;
- this.nodes = nodes;
- };
- BitmapIndexedNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
- if (keyHash === undefined) {
- keyHash = hash(key);
- }
- var bit = 1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK);
- var bitmap = this.bitmap;
- return (bitmap & bit) === 0
- ? notSetValue
- : this.nodes[popCount(bitmap & (bit - 1))].get(
- shift + SHIFT,
- keyHash,
- key,
- notSetValue
- );
- };
- BitmapIndexedNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
- if (keyHash === undefined) {
- keyHash = hash(key);
- }
- var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
- var bit = 1 << keyHashFrag;
- var bitmap = this.bitmap;
- var exists = (bitmap & bit) !== 0;
- if (!exists && value === NOT_SET) {
- return this;
- }
- var idx = popCount(bitmap & (bit - 1));
- var nodes = this.nodes;
- var node = exists ? nodes[idx] : undefined;
- var newNode = updateNode(
- node,
- ownerID,
- shift + SHIFT,
- keyHash,
- key,
- value,
- didChangeSize,
- didAlter
- );
- if (newNode === node) {
- return this;
- }
- if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
- return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
- }
- if (
- exists &&
- !newNode &&
- nodes.length === 2 &&
- isLeafNode(nodes[idx ^ 1])
- ) {
- return nodes[idx ^ 1];
- }
- if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
- return newNode;
- }
- var isEditable = ownerID && ownerID === this.ownerID;
- var newBitmap = exists ? (newNode ? bitmap : bitmap ^ bit) : bitmap | bit;
- var newNodes = exists
- ? newNode
- ? setAt(nodes, idx, newNode, isEditable)
- : spliceOut(nodes, idx, isEditable)
- : spliceIn(nodes, idx, newNode, isEditable);
- if (isEditable) {
- this.bitmap = newBitmap;
- this.nodes = newNodes;
- return this;
- }
- return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
- };
- var HashArrayMapNode = function HashArrayMapNode(ownerID, count, nodes) {
- this.ownerID = ownerID;
- this.count = count;
- this.nodes = nodes;
- };
- HashArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
- if (keyHash === undefined) {
- keyHash = hash(key);
- }
- var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
- var node = this.nodes[idx];
- return node
- ? node.get(shift + SHIFT, keyHash, key, notSetValue)
- : notSetValue;
- };
- HashArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
- if (keyHash === undefined) {
- keyHash = hash(key);
- }
- var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
- var removed = value === NOT_SET;
- var nodes = this.nodes;
- var node = nodes[idx];
- if (removed && !node) {
- return this;
- }
- var newNode = updateNode(
- node,
- ownerID,
- shift + SHIFT,
- keyHash,
- key,
- value,
- didChangeSize,
- didAlter
- );
- if (newNode === node) {
- return this;
- }
- var newCount = this.count;
- if (!node) {
- newCount++;
- } else if (!newNode) {
- newCount--;
- if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
- return packNodes(ownerID, nodes, newCount, idx);
- }
- }
- var isEditable = ownerID && ownerID === this.ownerID;
- var newNodes = setAt(nodes, idx, newNode, isEditable);
- if (isEditable) {
- this.count = newCount;
- this.nodes = newNodes;
- return this;
- }
- return new HashArrayMapNode(ownerID, newCount, newNodes);
- };
- var HashCollisionNode = function HashCollisionNode(ownerID, keyHash, entries) {
- this.ownerID = ownerID;
- this.keyHash = keyHash;
- this.entries = entries;
- };
- HashCollisionNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
- var entries = this.entries;
- for (var ii = 0, len = entries.length; ii < len; ii++) {
- if (is(key, entries[ii][0])) {
- return entries[ii][1];
- }
- }
- return notSetValue;
- };
- HashCollisionNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
- if (keyHash === undefined) {
- keyHash = hash(key);
- }
- var removed = value === NOT_SET;
- if (keyHash !== this.keyHash) {
- if (removed) {
- return this;
- }
- SetRef(didAlter);
- SetRef(didChangeSize);
- return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
- }
- var entries = this.entries;
- var idx = 0;
- var len = entries.length;
- for (; idx < len; idx++) {
- if (is(key, entries[idx][0])) {
- break;
- }
- }
- var exists = idx < len;
- if (exists ? entries[idx][1] === value : removed) {
- return this;
- }
- SetRef(didAlter);
- (removed || !exists) && SetRef(didChangeSize);
- if (removed && len === 2) {
- return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
- }
- var isEditable = ownerID && ownerID === this.ownerID;
- var newEntries = isEditable ? entries : arrCopy(entries);
- if (exists) {
- if (removed) {
- idx === len - 1
- ? newEntries.pop()
- : (newEntries[idx] = newEntries.pop());
- } else {
- newEntries[idx] = [key, value];
- }
- } else {
- newEntries.push([key, value]);
- }
- if (isEditable) {
- this.entries = newEntries;
- return this;
- }
- return new HashCollisionNode(ownerID, this.keyHash, newEntries);
- };
- var ValueNode = function ValueNode(ownerID, keyHash, entry) {
- this.ownerID = ownerID;
- this.keyHash = keyHash;
- this.entry = entry;
- };
- ValueNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
- return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
- };
- ValueNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
- var removed = value === NOT_SET;
- var keyMatch = is(key, this.entry[0]);
- if (keyMatch ? value === this.entry[1] : removed) {
- return this;
- }
- SetRef(didAlter);
- if (removed) {
- SetRef(didChangeSize);
- return; // undefined
- }
- if (keyMatch) {
- if (ownerID && ownerID === this.ownerID) {
- this.entry[1] = value;
- return this;
- }
- return new ValueNode(ownerID, this.keyHash, [key, value]);
- }
- SetRef(didChangeSize);
- return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
- };
- // #pragma Iterators
- ArrayMapNode.prototype.iterate = HashCollisionNode.prototype.iterate =
- function (fn, reverse) {
- var entries = this.entries;
- for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
- if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
- return false;
- }
- }
- };
- BitmapIndexedNode.prototype.iterate = HashArrayMapNode.prototype.iterate =
- function (fn, reverse) {
- var nodes = this.nodes;
- for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
- var node = nodes[reverse ? maxIndex - ii : ii];
- if (node && node.iterate(fn, reverse) === false) {
- return false;
- }
- }
- };
- // eslint-disable-next-line no-unused-vars
- ValueNode.prototype.iterate = function (fn, reverse) {
- return fn(this.entry);
- };
- var MapIterator = /*@__PURE__*/(function (Iterator) {
- function MapIterator(map, type, reverse) {
- this._type = type;
- this._reverse = reverse;
- this._stack = map._root && mapIteratorFrame(map._root);
- }
- if ( Iterator ) MapIterator.__proto__ = Iterator;
- MapIterator.prototype = Object.create( Iterator && Iterator.prototype );
- MapIterator.prototype.constructor = MapIterator;
- MapIterator.prototype.next = function next () {
- var type = this._type;
- var stack = this._stack;
- while (stack) {
- var node = stack.node;
- var index = stack.index++;
- var maxIndex = (void 0);
- if (node.entry) {
- if (index === 0) {
- return mapIteratorValue(type, node.entry);
- }
- } else if (node.entries) {
- maxIndex = node.entries.length - 1;
- if (index <= maxIndex) {
- return mapIteratorValue(
- type,
- node.entries[this._reverse ? maxIndex - index : index]
- );
- }
- } else {
- maxIndex = node.nodes.length - 1;
- if (index <= maxIndex) {
- var subNode = node.nodes[this._reverse ? maxIndex - index : index];
- if (subNode) {
- if (subNode.entry) {
- return mapIteratorValue(type, subNode.entry);
- }
- stack = this._stack = mapIteratorFrame(subNode, stack);
- }
- continue;
- }
- }
- stack = this._stack = this._stack.__prev;
- }
- return iteratorDone();
- };
- return MapIterator;
- }(Iterator));
- function mapIteratorValue(type, entry) {
- return iteratorValue(type, entry[0], entry[1]);
- }
- function mapIteratorFrame(node, prev) {
- return {
- node: node,
- index: 0,
- __prev: prev,
- };
- }
- function makeMap(size, root, ownerID, hash) {
- var map = Object.create(MapPrototype);
- map.size = size;
- map._root = root;
- map.__ownerID = ownerID;
- map.__hash = hash;
- map.__altered = false;
- return map;
- }
- var EMPTY_MAP;
- function emptyMap() {
- return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
- }
- function updateMap(map, k, v) {
- var newRoot;
- var newSize;
- if (!map._root) {
- if (v === NOT_SET) {
- return map;
- }
- newSize = 1;
- newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
- } else {
- var didChangeSize = MakeRef();
- var didAlter = MakeRef();
- newRoot = updateNode(
- map._root,
- map.__ownerID,
- 0,
- undefined,
- k,
- v,
- didChangeSize,
- didAlter
- );
- if (!didAlter.value) {
- return map;
- }
- newSize = map.size + (didChangeSize.value ? (v === NOT_SET ? -1 : 1) : 0);
- }
- if (map.__ownerID) {
- map.size = newSize;
- map._root = newRoot;
- map.__hash = undefined;
- map.__altered = true;
- return map;
- }
- return newRoot ? makeMap(newSize, newRoot) : emptyMap();
- }
- function updateNode(
- node,
- ownerID,
- shift,
- keyHash,
- key,
- value,
- didChangeSize,
- didAlter
- ) {
- if (!node) {
- if (value === NOT_SET) {
- return node;
- }
- SetRef(didAlter);
- SetRef(didChangeSize);
- return new ValueNode(ownerID, keyHash, [key, value]);
- }
- return node.update(
- ownerID,
- shift,
- keyHash,
- key,
- value,
- didChangeSize,
- didAlter
- );
- }
- function isLeafNode(node) {
- return (
- node.constructor === ValueNode || node.constructor === HashCollisionNode
- );
- }
- function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
- if (node.keyHash === keyHash) {
- return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
- }
- var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
- var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
- var newNode;
- var nodes =
- idx1 === idx2
- ? [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)]
- : ((newNode = new ValueNode(ownerID, keyHash, entry)),
- idx1 < idx2 ? [node, newNode] : [newNode, node]);
- return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
- }
- function createNodes(ownerID, entries, key, value) {
- if (!ownerID) {
- ownerID = new OwnerID();
- }
- var node = new ValueNode(ownerID, hash(key), [key, value]);
- for (var ii = 0; ii < entries.length; ii++) {
- var entry = entries[ii];
- node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
- }
- return node;
- }
- function packNodes(ownerID, nodes, count, excluding) {
- var bitmap = 0;
- var packedII = 0;
- var packedNodes = new Array(count);
- for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
- var node = nodes[ii];
- if (node !== undefined && ii !== excluding) {
- bitmap |= bit;
- packedNodes[packedII++] = node;
- }
- }
- return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
- }
- function expandNodes(ownerID, nodes, bitmap, including, node) {
- var count = 0;
- var expandedNodes = new Array(SIZE);
- for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
- expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
- }
- expandedNodes[including] = node;
- return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
- }
- function popCount(x) {
- x -= (x >> 1) & 0x55555555;
- x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
- x = (x + (x >> 4)) & 0x0f0f0f0f;
- x += x >> 8;
- x += x >> 16;
- return x & 0x7f;
- }
- function setAt(array, idx, val, canEdit) {
- var newArray = canEdit ? array : arrCopy(array);
- newArray[idx] = val;
- return newArray;
- }
- function spliceIn(array, idx, val, canEdit) {
- var newLen = array.length + 1;
- if (canEdit && idx + 1 === newLen) {
- array[idx] = val;
- return array;
- }
- var newArray = new Array(newLen);
- var after = 0;
- for (var ii = 0; ii < newLen; ii++) {
- if (ii === idx) {
- newArray[ii] = val;
- after = -1;
- } else {
- newArray[ii] = array[ii + after];
- }
- }
- return newArray;
- }
- function spliceOut(array, idx, canEdit) {
- var newLen = array.length - 1;
- if (canEdit && idx === newLen) {
- array.pop();
- return array;
- }
- var newArray = new Array(newLen);
- var after = 0;
- for (var ii = 0; ii < newLen; ii++) {
- if (ii === idx) {
- after = 1;
- }
- newArray[ii] = array[ii + after];
- }
- return newArray;
- }
- var MAX_ARRAY_MAP_SIZE = SIZE / 4;
- var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
- var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
- var IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
- function isList(maybeList) {
- return Boolean(maybeList && maybeList[IS_LIST_SYMBOL]);
- }
- var List = /*@__PURE__*/(function (IndexedCollection) {
- function List(value) {
- var empty = emptyList();
- if (value === undefined || value === null) {
- // eslint-disable-next-line no-constructor-return
- return empty;
- }
- if (isList(value)) {
- // eslint-disable-next-line no-constructor-return
- return value;
- }
- var iter = IndexedCollection(value);
- var size = iter.size;
- if (size === 0) {
- // eslint-disable-next-line no-constructor-return
- return empty;
- }
- assertNotInfinite(size);
- if (size > 0 && size < SIZE) {
- // eslint-disable-next-line no-constructor-return
- return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
- }
- // eslint-disable-next-line no-constructor-return
- return empty.withMutations(function (list) {
- list.setSize(size);
- iter.forEach(function (v, i) { return list.set(i, v); });
- });
- }
- if ( IndexedCollection ) List.__proto__ = IndexedCollection;
- List.prototype = Object.create( IndexedCollection && IndexedCollection.prototype );
- List.prototype.constructor = List;
- List.of = function of (/*...values*/) {
- return this(arguments);
- };
- List.prototype.toString = function toString () {
- return this.__toString('List [', ']');
- };
- // @pragma Access
- List.prototype.get = function get (index, notSetValue) {
- index = wrapIndex(this, index);
- if (index >= 0 && index < this.size) {
- index += this._origin;
- var node = listNodeFor(this, index);
- return node && node.array[index & MASK];
- }
- return notSetValue;
- };
- // @pragma Modification
- List.prototype.set = function set (index, value) {
- return updateList(this, index, value);
- };
- List.prototype.remove = function remove (index) {
- return !this.has(index)
- ? this
- : index === 0
- ? this.shift()
- : index === this.size - 1
- ? this.pop()
- : this.splice(index, 1);
- };
- List.prototype.insert = function insert (index, value) {
- return this.splice(index, 0, value);
- };
- List.prototype.clear = function clear () {
- if (this.size === 0) {
- return this;
- }
- if (this.__ownerID) {
- this.size = this._origin = this._capacity = 0;
- this._level = SHIFT;
- this._root = this._tail = this.__hash = undefined;
- this.__altered = true;
- return this;
- }
- return emptyList();
- };
- List.prototype.push = function push (/*...values*/) {
- var values = arguments;
- var oldSize = this.size;
- return this.withMutations(function (list) {
- setListBounds(list, 0, oldSize + values.length);
- for (var ii = 0; ii < values.length; ii++) {
- list.set(oldSize + ii, values[ii]);
- }
- });
- };
- List.prototype.pop = function pop () {
- return setListBounds(this, 0, -1);
- };
- List.prototype.unshift = function unshift (/*...values*/) {
- var values = arguments;
- return this.withMutations(function (list) {
- setListBounds(list, -values.length);
- for (var ii = 0; ii < values.length; ii++) {
- list.set(ii, values[ii]);
- }
- });
- };
- List.prototype.shift = function shift () {
- return setListBounds(this, 1);
- };
- // @pragma Composition
- List.prototype.concat = function concat (/*...collections*/) {
- var arguments$1 = arguments;
- var seqs = [];
- for (var i = 0; i < arguments.length; i++) {
- var argument = arguments$1[i];
- var seq = IndexedCollection(
- typeof argument !== 'string' && hasIterator(argument)
- ? argument
- : [argument]
- );
- if (seq.size !== 0) {
- seqs.push(seq);
- }
- }
- if (seqs.length === 0) {
- return this;
- }
- if (this.size === 0 && !this.__ownerID && seqs.length === 1) {
- return this.constructor(seqs[0]);
- }
- return this.withMutations(function (list) {
- seqs.forEach(function (seq) { return seq.forEach(function (value) { return list.push(value); }); });
- });
- };
- List.prototype.setSize = function setSize (size) {
- return setListBounds(this, 0, size);
- };
- List.prototype.map = function map (mapper, context) {
- var this$1$1 = this;
- return this.withMutations(function (list) {
- for (var i = 0; i < this$1$1.size; i++) {
- list.set(i, mapper.call(context, list.get(i), i, this$1$1));
- }
- });
- };
- // @pragma Iteration
- List.prototype.slice = function slice (begin, end) {
- var size = this.size;
- if (wholeSlice(begin, end, size)) {
- return this;
- }
- return setListBounds(
- this,
- resolveBegin(begin, size),
- resolveEnd(end, size)
- );
- };
- List.prototype.__iterator = function __iterator (type, reverse) {
- var index = reverse ? this.size : 0;
- var values = iterateList(this, reverse);
- return new Iterator(function () {
- var value = values();
- return value === DONE
- ? iteratorDone()
- : iteratorValue(type, reverse ? --index : index++, value);
- });
- };
- List.prototype.__iterate = function __iterate (fn, reverse) {
- var index = reverse ? this.size : 0;
- var values = iterateList(this, reverse);
- var value;
- while ((value = values()) !== DONE) {
- if (fn(value, reverse ? --index : index++, this) === false) {
- break;
- }
- }
- return index;
- };
- List.prototype.__ensureOwner = function __ensureOwner (ownerID) {
- if (ownerID === this.__ownerID) {
- return this;
- }
- if (!ownerID) {
- if (this.size === 0) {
- return emptyList();
- }
- this.__ownerID = ownerID;
- this.__altered = false;
- return this;
- }
- return makeList(
- this._origin,
- this._capacity,
- this._level,
- this._root,
- this._tail,
- ownerID,
- this.__hash
- );
- };
- return List;
- }(IndexedCollection));
- List.isList = isList;
- var ListPrototype = List.prototype;
- ListPrototype[IS_LIST_SYMBOL] = true;
- ListPrototype[DELETE] = ListPrototype.remove;
- ListPrototype.merge = ListPrototype.concat;
- ListPrototype.setIn = setIn;
- ListPrototype.deleteIn = ListPrototype.removeIn = deleteIn;
- ListPrototype.update = update;
- ListPrototype.updateIn = updateIn;
- ListPrototype.mergeIn = mergeIn;
- ListPrototype.mergeDeepIn = mergeDeepIn;
- ListPrototype.withMutations = withMutations;
- ListPrototype.wasAltered = wasAltered;
- ListPrototype.asImmutable = asImmutable;
- ListPrototype['@@transducer/init'] = ListPrototype.asMutable = asMutable;
- ListPrototype['@@transducer/step'] = function (result, arr) {
- return result.push(arr);
- };
- ListPrototype['@@transducer/result'] = function (obj) {
- return obj.asImmutable();
- };
- var VNode = function VNode(array, ownerID) {
- this.array = array;
- this.ownerID = ownerID;
- };
- // TODO: seems like these methods are very similar
- VNode.prototype.removeBefore = function removeBefore (ownerID, level, index) {
- if (index === level ? 1 << level : this.array.length === 0) {
- return this;
- }
- var originIndex = (index >>> level) & MASK;
- if (originIndex >= this.array.length) {
- return new VNode([], ownerID);
- }
- var removingFirst = originIndex === 0;
- var newChild;
- if (level > 0) {
- var oldChild = this.array[originIndex];
- newChild =
- oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
- if (newChild === oldChild && removingFirst) {
- return this;
- }
- }
- if (removingFirst && !newChild) {
- return this;
- }
- var editable = editableVNode(this, ownerID);
- if (!removingFirst) {
- for (var ii = 0; ii < originIndex; ii++) {
- editable.array[ii] = undefined;
- }
- }
- if (newChild) {
- editable.array[originIndex] = newChild;
- }
- return editable;
- };
- VNode.prototype.removeAfter = function removeAfter (ownerID, level, index) {
- if (index === (level ? 1 << level : 0) || this.array.length === 0) {
- return this;
- }
- var sizeIndex = ((index - 1) >>> level) & MASK;
- if (sizeIndex >= this.array.length) {
- return this;
- }
- var newChild;
- if (level > 0) {
- var oldChild = this.array[sizeIndex];
- newChild =
- oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
- if (newChild === oldChild && sizeIndex === this.array.length - 1) {
- return this;
- }
- }
- var editable = editableVNode(this, ownerID);
- editable.array.splice(sizeIndex + 1);
- if (newChild) {
- editable.array[sizeIndex] = newChild;
- }
- return editable;
- };
- var DONE = {};
- function iterateList(list, reverse) {
- var left = list._origin;
- var right = list._capacity;
- var tailPos = getTailOffset(right);
- var tail = list._tail;
- return iterateNodeOrLeaf(list._root, list._level, 0);
- function iterateNodeOrLeaf(node, level, offset) {
- return level === 0
- ? iterateLeaf(node, offset)
- : iterateNode(node, level, offset);
- }
- function iterateLeaf(node, offset) {
- var array = offset === tailPos ? tail && tail.array : node && node.array;
- var from = offset > left ? 0 : left - offset;
- var to = right - offset;
- if (to > SIZE) {
- to = SIZE;
- }
- return function () {
- if (from === to) {
- return DONE;
- }
- var idx = reverse ? --to : from++;
- return array && array[idx];
- };
- }
- function iterateNode(node, level, offset) {
- var values;
- var array = node && node.array;
- var from = offset > left ? 0 : (left - offset) >> level;
- var to = ((right - offset) >> level) + 1;
- if (to > SIZE) {
- to = SIZE;
- }
- return function () {
- while (true) {
- if (values) {
- var value = values();
- if (value !== DONE) {
- return value;
- }
- values = null;
- }
- if (from === to) {
- return DONE;
- }
- var idx = reverse ? --to : from++;
- values = iterateNodeOrLeaf(
- array && array[idx],
- level - SHIFT,
- offset + (idx << level)
- );
- }
- };
- }
- }
- function makeList(origin, capacity, level, root, tail, ownerID, hash) {
- var list = Object.create(ListPrototype);
- list.size = capacity - origin;
- list._origin = origin;
- list._capacity = capacity;
- list._level = level;
- list._root = root;
- list._tail = tail;
- list.__ownerID = ownerID;
- list.__hash = hash;
- list.__altered = false;
- return list;
- }
- var EMPTY_LIST;
- function emptyList() {
- return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
- }
- function updateList(list, index, value) {
- index = wrapIndex(list, index);
- if (index !== index) {
- return list;
- }
- if (index >= list.size || index < 0) {
- return list.withMutations(function (list) {
- index < 0
- ? setListBounds(list, index).set(0, value)
- : setListBounds(list, 0, index + 1).set(index, value);
- });
- }
- index += list._origin;
- var newTail = list._tail;
- var newRoot = list._root;
- var didAlter = MakeRef();
- if (index >= getTailOffset(list._capacity)) {
- newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
- } else {
- newRoot = updateVNode(
- newRoot,
- list.__ownerID,
- list._level,
- index,
- value,
- didAlter
- );
- }
- if (!didAlter.value) {
- return list;
- }
- if (list.__ownerID) {
- list._root = newRoot;
- list._tail = newTail;
- list.__hash = undefined;
- list.__altered = true;
- return list;
- }
- return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
- }
- function updateVNode(node, ownerID, level, index, value, didAlter) {
- var idx = (index >>> level) & MASK;
- var nodeHas = node && idx < node.array.length;
- if (!nodeHas && value === undefined) {
- return node;
- }
- var newNode;
- if (level > 0) {
- var lowerNode = node && node.array[idx];
- var newLowerNode = updateVNode(
- lowerNode,
- ownerID,
- level - SHIFT,
- index,
- value,
- didAlter
- );
- if (newLowerNode === lowerNode) {
- return node;
- }
- newNode = editableVNode(node, ownerID);
- newNode.array[idx] = newLowerNode;
- return newNode;
- }
- if (nodeHas && node.array[idx] === value) {
- return node;
- }
- if (didAlter) {
- SetRef(didAlter);
- }
- newNode = editableVNode(node, ownerID);
- if (value === undefined && idx === newNode.array.length - 1) {
- newNode.array.pop();
- } else {
- newNode.array[idx] = value;
- }
- return newNode;
- }
- function editableVNode(node, ownerID) {
- if (ownerID && node && ownerID === node.ownerID) {
- return node;
- }
- return new VNode(node ? node.array.slice() : [], ownerID);
- }
- function listNodeFor(list, rawIndex) {
- if (rawIndex >= getTailOffset(list._capacity)) {
- return list._tail;
- }
- if (rawIndex < 1 << (list._level + SHIFT)) {
- var node = list._root;
- var level = list._level;
- while (node && level > 0) {
- node = node.array[(rawIndex >>> level) & MASK];
- level -= SHIFT;
- }
- return node;
- }
- }
- function setListBounds(list, begin, end) {
- // Sanitize begin & end using this shorthand for ToInt32(argument)
- // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
- if (begin !== undefined) {
- begin |= 0;
- }
- if (end !== undefined) {
- end |= 0;
- }
- var owner = list.__ownerID || new OwnerID();
- var oldOrigin = list._origin;
- var oldCapacity = list._capacity;
- var newOrigin = oldOrigin + begin;
- var newCapacity =
- end === undefined
- ? oldCapacity
- : end < 0
- ? oldCapacity + end
- : oldOrigin + end;
- if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
- return list;
- }
- // If it's going to end after it starts, it's empty.
- if (newOrigin >= newCapacity) {
- return list.clear();
- }
- var newLevel = list._level;
- var newRoot = list._root;
- // New origin might need creating a higher root.
- var offsetShift = 0;
- while (newOrigin + offsetShift < 0) {
- newRoot = new VNode(
- newRoot && newRoot.array.length ? [undefined, newRoot] : [],
- owner
- );
- newLevel += SHIFT;
- offsetShift += 1 << newLevel;
- }
- if (offsetShift) {
- newOrigin += offsetShift;
- oldOrigin += offsetShift;
- newCapacity += offsetShift;
- oldCapacity += offsetShift;
- }
- var oldTailOffset = getTailOffset(oldCapacity);
- var newTailOffset = getTailOffset(newCapacity);
- // New size might need creating a higher root.
- while (newTailOffset >= 1 << (newLevel + SHIFT)) {
- newRoot = new VNode(
- newRoot && newRoot.array.length ? [newRoot] : [],
- owner
- );
- newLevel += SHIFT;
- }
- // Locate or create the new tail.
- var oldTail = list._tail;
- var newTail =
- newTailOffset < oldTailOffset
- ? listNodeFor(list, newCapacity - 1)
- : newTailOffset > oldTailOffset
- ? new VNode([], owner)
- : oldTail;
- // Merge Tail into tree.
- if (
- oldTail &&
- newTailOffset > oldTailOffset &&
- newOrigin < oldCapacity &&
- oldTail.array.length
- ) {
- newRoot = editableVNode(newRoot, owner);
- var node = newRoot;
- for (var level = newLevel; level > SHIFT; level -= SHIFT) {
- var idx = (oldTailOffset >>> level) & MASK;
- node = node.array[idx] = editableVNode(node.array[idx], owner);
- }
- node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
- }
- // If the size has been reduced, there's a chance the tail needs to be trimmed.
- if (newCapacity < oldCapacity) {
- newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
- }
- // If the new origin is within the tail, then we do not need a root.
- if (newOrigin >= newTailOffset) {
- newOrigin -= newTailOffset;
- newCapacity -= newTailOffset;
- newLevel = SHIFT;
- newRoot = null;
- newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
- // Otherwise, if the root has been trimmed, garbage collect.
- } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
- offsetShift = 0;
- // Identify the new top root node of the subtree of the old root.
- while (newRoot) {
- var beginIndex = (newOrigin >>> newLevel) & MASK;
- if ((beginIndex !== newTailOffset >>> newLevel) & MASK) {
- break;
- }
- if (beginIndex) {
- offsetShift += (1 << newLevel) * beginIndex;
- }
- newLevel -= SHIFT;
- newRoot = newRoot.array[beginIndex];
- }
- // Trim the new sides of the new root.
- if (newRoot && newOrigin > oldOrigin) {
- newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
- }
- if (newRoot && newTailOffset < oldTailOffset) {
- newRoot = newRoot.removeAfter(
- owner,
- newLevel,
- newTailOffset - offsetShift
- );
- }
- if (offsetShift) {
- newOrigin -= offsetShift;
- newCapacity -= offsetShift;
- }
- }
- if (list.__ownerID) {
- list.size = newCapacity - newOrigin;
- list._origin = newOrigin;
- list._capacity = newCapacity;
- list._level = newLevel;
- list._root = newRoot;
- list._tail = newTail;
- list.__hash = undefined;
- list.__altered = true;
- return list;
- }
- return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
- }
- function getTailOffset(size) {
- return size < SIZE ? 0 : ((size - 1) >>> SHIFT) << SHIFT;
- }
- var OrderedMap = /*@__PURE__*/(function (Map) {
- function OrderedMap(value) {
- // eslint-disable-next-line no-constructor-return
- return value === undefined || value === null
- ? emptyOrderedMap()
- : isOrderedMap(value)
- ? value
- : emptyOrderedMap().withMutations(function (map) {
- var iter = KeyedCollection(value);
- assertNotInfinite(iter.size);
- iter.forEach(function (v, k) { return map.set(k, v); });
- });
- }
- if ( Map ) OrderedMap.__proto__ = Map;
- OrderedMap.prototype = Object.create( Map && Map.prototype );
- OrderedMap.prototype.constructor = OrderedMap;
- OrderedMap.of = function of (/*...values*/) {
- return this(arguments);
- };
- OrderedMap.prototype.toString = function toString () {
- return this.__toString('OrderedMap {', '}');
- };
- // @pragma Access
- OrderedMap.prototype.get = function get (k, notSetValue) {
- var index = this._map.get(k);
- return index !== undefined ? this._list.get(index)[1] : notSetValue;
- };
- // @pragma Modification
- OrderedMap.prototype.clear = function clear () {
- if (this.size === 0) {
- return this;
- }
- if (this.__ownerID) {
- this.size = 0;
- this._map.clear();
- this._list.clear();
- this.__altered = true;
- return this;
- }
- return emptyOrderedMap();
- };
- OrderedMap.prototype.set = function set (k, v) {
- return updateOrderedMap(this, k, v);
- };
- OrderedMap.prototype.remove = function remove (k) {
- return updateOrderedMap(this, k, NOT_SET);
- };
- OrderedMap.prototype.__iterate = function __iterate (fn, reverse) {
- var this$1$1 = this;
- return this._list.__iterate(
- function (entry) { return entry && fn(entry[1], entry[0], this$1$1); },
- reverse
- );
- };
- OrderedMap.prototype.__iterator = function __iterator (type, reverse) {
- return this._list.fromEntrySeq().__iterator(type, reverse);
- };
- OrderedMap.prototype.__ensureOwner = function __ensureOwner (ownerID) {
- if (ownerID === this.__ownerID) {
- return this;
- }
- var newMap = this._map.__ensureOwner(ownerID);
- var newList = this._list.__ensureOwner(ownerID);
- if (!ownerID) {
- if (this.size === 0) {
- return emptyOrderedMap();
- }
- this.__ownerID = ownerID;
- this.__altered = false;
- this._map = newMap;
- this._list = newList;
- return this;
- }
- return makeOrderedMap(newMap, newList, ownerID, this.__hash);
- };
- return OrderedMap;
- }(Map));
- OrderedMap.isOrderedMap = isOrderedMap;
- OrderedMap.prototype[IS_ORDERED_SYMBOL] = true;
- OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
- function makeOrderedMap(map, list, ownerID, hash) {
- var omap = Object.create(OrderedMap.prototype);
- omap.size = map ? map.size : 0;
- omap._map = map;
- omap._list = list;
- omap.__ownerID = ownerID;
- omap.__hash = hash;
- omap.__altered = false;
- return omap;
- }
- var EMPTY_ORDERED_MAP;
- function emptyOrderedMap() {
- return (
- EMPTY_ORDERED_MAP ||
- (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()))
- );
- }
- function updateOrderedMap(omap, k, v) {
- var map = omap._map;
- var list = omap._list;
- var i = map.get(k);
- var has = i !== undefined;
- var newMap;
- var newList;
- if (v === NOT_SET) {
- // removed
- if (!has) {
- return omap;
- }
- if (list.size >= SIZE && list.size >= map.size * 2) {
- newList = list.filter(function (entry, idx) { return entry !== undefined && i !== idx; });
- newMap = newList
- .toKeyedSeq()
- .map(function (entry) { return entry[0]; })
- .flip()
- .toMap();
- if (omap.__ownerID) {
- newMap.__ownerID = newList.__ownerID = omap.__ownerID;
- }
- } else {
- newMap = map.remove(k);
- newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
- }
- } else if (has) {
- if (v === list.get(i)[1]) {
- return omap;
- }
- newMap = map;
- newList = list.set(i, [k, v]);
- } else {
- newMap = map.set(k, list.size);
- newList = list.set(list.size, [k, v]);
- }
- if (omap.__ownerID) {
- omap.size = newMap.size;
- omap._map = newMap;
- omap._list = newList;
- omap.__hash = undefined;
- omap.__altered = true;
- return omap;
- }
- return makeOrderedMap(newMap, newList);
- }
- var IS_STACK_SYMBOL = '@@__IMMUTABLE_STACK__@@';
- function isStack(maybeStack) {
- return Boolean(maybeStack && maybeStack[IS_STACK_SYMBOL]);
- }
- var Stack = /*@__PURE__*/(function (IndexedCollection) {
- function Stack(value) {
- // eslint-disable-next-line no-constructor-return
- return value === undefined || value === null
- ? emptyStack()
- : isStack(value)
- ? value
- : emptyStack().pushAll(value);
- }
- if ( IndexedCollection ) Stack.__proto__ = IndexedCollection;
- Stack.prototype = Object.create( IndexedCollection && IndexedCollection.prototype );
- Stack.prototype.constructor = Stack;
- Stack.of = function of (/*...values*/) {
- return this(arguments);
- };
- Stack.prototype.toString = function toString () {
- return this.__toString('Stack [', ']');
- };
- // @pragma Access
- Stack.prototype.get = function get (index, notSetValue) {
- var head = this._head;
- index = wrapIndex(this, index);
- while (head && index--) {
- head = head.next;
- }
- return head ? head.value : notSetValue;
- };
- Stack.prototype.peek = function peek () {
- return this._head && this._head.value;
- };
- // @pragma Modification
- Stack.prototype.push = function push (/*...values*/) {
- var arguments$1 = arguments;
- if (arguments.length === 0) {
- return this;
- }
- var newSize = this.size + arguments.length;
- var head = this._head;
- for (var ii = arguments.length - 1; ii >= 0; ii--) {
- head = {
- value: arguments$1[ii],
- next: head,
- };
- }
- if (this.__ownerID) {
- this.size = newSize;
- this._head = head;
- this.__hash = undefined;
- this.__altered = true;
- return this;
- }
- return makeStack(newSize, head);
- };
- Stack.prototype.pushAll = function pushAll (iter) {
- iter = IndexedCollection(iter);
- if (iter.size === 0) {
- return this;
- }
- if (this.size === 0 && isStack(iter)) {
- return iter;
- }
- assertNotInfinite(iter.size);
- var newSize = this.size;
- var head = this._head;
- iter.__iterate(function (value) {
- newSize++;
- head = {
- value: value,
- next: head,
- };
- }, /* reverse */ true);
- if (this.__ownerID) {
- this.size = newSize;
- this._head = head;
- this.__hash = undefined;
- this.__altered = true;
- return this;
- }
- return makeStack(newSize, head);
- };
- Stack.prototype.pop = function pop () {
- return this.slice(1);
- };
- Stack.prototype.clear = function clear () {
- if (this.size === 0) {
- return this;
- }
- if (this.__ownerID) {
- this.size = 0;
- this._head = undefined;
- this.__hash = undefined;
- this.__altered = true;
- return this;
- }
- return emptyStack();
- };
- Stack.prototype.slice = function slice (begin, end) {
- if (wholeSlice(begin, end, this.size)) {
- return this;
- }
- var resolvedBegin = resolveBegin(begin, this.size);
- var resolvedEnd = resolveEnd(end, this.size);
- if (resolvedEnd !== this.size) {
- // super.slice(begin, end);
- return IndexedCollection.prototype.slice.call(this, begin, end);
- }
- var newSize = this.size - resolvedBegin;
- var head = this._head;
- while (resolvedBegin--) {
- head = head.next;
- }
- if (this.__ownerID) {
- this.size = newSize;
- this._head = head;
- this.__hash = undefined;
- this.__altered = true;
- return this;
- }
- return makeStack(newSize, head);
- };
- // @pragma Mutability
- Stack.prototype.__ensureOwner = function __ensureOwner (ownerID) {
- if (ownerID === this.__ownerID) {
- return this;
- }
- if (!ownerID) {
- if (this.size === 0) {
- return emptyStack();
- }
- this.__ownerID = ownerID;
- this.__altered = false;
- return this;
- }
- return makeStack(this.size, this._head, ownerID, this.__hash);
- };
- // @pragma Iteration
- Stack.prototype.__iterate = function __iterate (fn, reverse) {
- var this$1$1 = this;
- if (reverse) {
- return new ArraySeq(this.toArray()).__iterate(
- function (v, k) { return fn(v, k, this$1$1); },
- reverse
- );
- }
- var iterations = 0;
- var node = this._head;
- while (node) {
- if (fn(node.value, iterations++, this) === false) {
- break;
- }
- node = node.next;
- }
- return iterations;
- };
- Stack.prototype.__iterator = function __iterator (type, reverse) {
- if (reverse) {
- return new ArraySeq(this.toArray()).__iterator(type, reverse);
- }
- var iterations = 0;
- var node = this._head;
- return new Iterator(function () {
- if (node) {
- var value = node.value;
- node = node.next;
- return iteratorValue(type, iterations++, value);
- }
- return iteratorDone();
- });
- };
- return Stack;
- }(IndexedCollection));
- Stack.isStack = isStack;
- var StackPrototype = Stack.prototype;
- StackPrototype[IS_STACK_SYMBOL] = true;
- StackPrototype.shift = StackPrototype.pop;
- StackPrototype.unshift = StackPrototype.push;
- StackPrototype.unshiftAll = StackPrototype.pushAll;
- StackPrototype.withMutations = withMutations;
- StackPrototype.wasAltered = wasAltered;
- StackPrototype.asImmutable = asImmutable;
- StackPrototype['@@transducer/init'] = StackPrototype.asMutable = asMutable;
- StackPrototype['@@transducer/step'] = function (result, arr) {
- return result.unshift(arr);
- };
- StackPrototype['@@transducer/result'] = function (obj) {
- return obj.asImmutable();
- };
- function makeStack(size, head, ownerID, hash) {
- var map = Object.create(StackPrototype);
- map.size = size;
- map._head = head;
- map.__ownerID = ownerID;
- map.__hash = hash;
- map.__altered = false;
- return map;
- }
- var EMPTY_STACK;
- function emptyStack() {
- return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
- }
- var IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
- function isSet(maybeSet) {
- return Boolean(maybeSet && maybeSet[IS_SET_SYMBOL]);
- }
- function isOrderedSet(maybeOrderedSet) {
- return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
- }
- function deepEqual(a, b) {
- if (a === b) {
- return true;
- }
- if (
- !isCollection(b) ||
- (a.size !== undefined && b.size !== undefined && a.size !== b.size) ||
- (a.__hash !== undefined &&
- b.__hash !== undefined &&
- a.__hash !== b.__hash) ||
- isKeyed(a) !== isKeyed(b) ||
- isIndexed(a) !== isIndexed(b) ||
- isOrdered(a) !== isOrdered(b)
- ) {
- return false;
- }
- if (a.size === 0 && b.size === 0) {
- return true;
- }
- var notAssociative = !isAssociative(a);
- if (isOrdered(a)) {
- var entries = a.entries();
- return (
- b.every(function (v, k) {
- var entry = entries.next().value;
- return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
- }) && entries.next().done
- );
- }
- var flipped = false;
- if (a.size === undefined) {
- if (b.size === undefined) {
- if (typeof a.cacheResult === 'function') {
- a.cacheResult();
- }
- } else {
- flipped = true;
- var _ = a;
- a = b;
- b = _;
- }
- }
- var allEqual = true;
- var bSize = b.__iterate(function (v, k) {
- if (
- notAssociative
- ? !a.has(v)
- : flipped
- ? !is(v, a.get(k, NOT_SET))
- : !is(a.get(k, NOT_SET), v)
- ) {
- allEqual = false;
- return false;
- }
- });
- return allEqual && a.size === bSize;
- }
- function mixin(ctor, methods) {
- var keyCopier = function (key) {
- ctor.prototype[key] = methods[key];
- };
- Object.keys(methods).forEach(keyCopier);
- Object.getOwnPropertySymbols &&
- Object.getOwnPropertySymbols(methods).forEach(keyCopier);
- return ctor;
- }
- function toJS(value) {
- if (!value || typeof value !== 'object') {
- return value;
- }
- if (!isCollection(value)) {
- if (!isDataStructure(value)) {
- return value;
- }
- value = Seq(value);
- }
- if (isKeyed(value)) {
- var result$1 = {};
- value.__iterate(function (v, k) {
- result$1[k] = toJS(v);
- });
- return result$1;
- }
- var result = [];
- value.__iterate(function (v) {
- result.push(toJS(v));
- });
- return result;
- }
- var Set = /*@__PURE__*/(function (SetCollection) {
- function Set(value) {
- // eslint-disable-next-line no-constructor-return
- return value === undefined || value === null
- ? emptySet()
- : isSet(value) && !isOrdered(value)
- ? value
- : emptySet().withMutations(function (set) {
- var iter = SetCollection(value);
- assertNotInfinite(iter.size);
- iter.forEach(function (v) { return set.add(v); });
- });
- }
- if ( SetCollection ) Set.__proto__ = SetCollection;
- Set.prototype = Object.create( SetCollection && SetCollection.prototype );
- Set.prototype.constructor = Set;
- Set.of = function of (/*...values*/) {
- return this(arguments);
- };
- Set.fromKeys = function fromKeys (value) {
- return this(KeyedCollection(value).keySeq());
- };
- Set.intersect = function intersect (sets) {
- sets = Collection(sets).toArray();
- return sets.length
- ? SetPrototype.intersect.apply(Set(sets.pop()), sets)
- : emptySet();
- };
- Set.union = function union (sets) {
- sets = Collection(sets).toArray();
- return sets.length
- ? SetPrototype.union.apply(Set(sets.pop()), sets)
- : emptySet();
- };
- Set.prototype.toString = function toString () {
- return this.__toString('Set {', '}');
- };
- // @pragma Access
- Set.prototype.has = function has (value) {
- return this._map.has(value);
- };
- // @pragma Modification
- Set.prototype.add = function add (value) {
- return updateSet(this, this._map.set(value, value));
- };
- Set.prototype.remove = function remove (value) {
- return updateSet(this, this._map.remove(value));
- };
- Set.prototype.clear = function clear () {
- return updateSet(this, this._map.clear());
- };
- // @pragma Composition
- Set.prototype.map = function map (mapper, context) {
- var this$1$1 = this;
- // keep track if the set is altered by the map function
- var didChanges = false;
- var newMap = updateSet(
- this,
- this._map.mapEntries(function (ref) {
- var v = ref[1];
- var mapped = mapper.call(context, v, v, this$1$1);
- if (mapped !== v) {
- didChanges = true;
- }
- return [mapped, mapped];
- }, context)
- );
- return didChanges ? newMap : this;
- };
- Set.prototype.union = function union () {
- var iters = [], len = arguments.length;
- while ( len-- ) iters[ len ] = arguments[ len ];
- iters = iters.filter(function (x) { return x.size !== 0; });
- if (iters.length === 0) {
- return this;
- }
- if (this.size === 0 && !this.__ownerID && iters.length === 1) {
- return this.constructor(iters[0]);
- }
- return this.withMutations(function (set) {
- for (var ii = 0; ii < iters.length; ii++) {
- if (typeof iters[ii] === 'string') {
- set.add(iters[ii]);
- } else {
- SetCollection(iters[ii]).forEach(function (value) { return set.add(value); });
- }
- }
- });
- };
- Set.prototype.intersect = function intersect () {
- var iters = [], len = arguments.length;
- while ( len-- ) iters[ len ] = arguments[ len ];
- if (iters.length === 0) {
- return this;
- }
- iters = iters.map(function (iter) { return SetCollection(iter); });
- var toRemove = [];
- this.forEach(function (value) {
- if (!iters.every(function (iter) { return iter.includes(value); })) {
- toRemove.push(value);
- }
- });
- return this.withMutations(function (set) {
- toRemove.forEach(function (value) {
- set.remove(value);
- });
- });
- };
- Set.prototype.subtract = function subtract () {
- var iters = [], len = arguments.length;
- while ( len-- ) iters[ len ] = arguments[ len ];
- if (iters.length === 0) {
- return this;
- }
- iters = iters.map(function (iter) { return SetCollection(iter); });
- var toRemove = [];
- this.forEach(function (value) {
- if (iters.some(function (iter) { return iter.includes(value); })) {
- toRemove.push(value);
- }
- });
- return this.withMutations(function (set) {
- toRemove.forEach(function (value) {
- set.remove(value);
- });
- });
- };
- Set.prototype.sort = function sort (comparator) {
- // Late binding
- return OrderedSet(sortFactory(this, comparator));
- };
- Set.prototype.sortBy = function sortBy (mapper, comparator) {
- // Late binding
- return OrderedSet(sortFactory(this, comparator, mapper));
- };
- Set.prototype.wasAltered = function wasAltered () {
- return this._map.wasAltered();
- };
- Set.prototype.__iterate = function __iterate (fn, reverse) {
- var this$1$1 = this;
- return this._map.__iterate(function (k) { return fn(k, k, this$1$1); }, reverse);
- };
- Set.prototype.__iterator = function __iterator (type, reverse) {
- return this._map.__iterator(type, reverse);
- };
- Set.prototype.__ensureOwner = function __ensureOwner (ownerID) {
- if (ownerID === this.__ownerID) {
- return this;
- }
- var newMap = this._map.__ensureOwner(ownerID);
- if (!ownerID) {
- if (this.size === 0) {
- return this.__empty();
- }
- this.__ownerID = ownerID;
- this._map = newMap;
- return this;
- }
- return this.__make(newMap, ownerID);
- };
- return Set;
- }(SetCollection));
- Set.isSet = isSet;
- var SetPrototype = Set.prototype;
- SetPrototype[IS_SET_SYMBOL] = true;
- SetPrototype[DELETE] = SetPrototype.remove;
- SetPrototype.merge = SetPrototype.concat = SetPrototype.union;
- SetPrototype.withMutations = withMutations;
- SetPrototype.asImmutable = asImmutable;
- SetPrototype['@@transducer/init'] = SetPrototype.asMutable = asMutable;
- SetPrototype['@@transducer/step'] = function (result, arr) {
- return result.add(arr);
- };
- SetPrototype['@@transducer/result'] = function (obj) {
- return obj.asImmutable();
- };
- SetPrototype.__empty = emptySet;
- SetPrototype.__make = makeSet;
- function updateSet(set, newMap) {
- if (set.__ownerID) {
- set.size = newMap.size;
- set._map = newMap;
- return set;
- }
- return newMap === set._map
- ? set
- : newMap.size === 0
- ? set.__empty()
- : set.__make(newMap);
- }
- function makeSet(map, ownerID) {
- var set = Object.create(SetPrototype);
- set.size = map ? map.size : 0;
- set._map = map;
- set.__ownerID = ownerID;
- return set;
- }
- var EMPTY_SET;
- function emptySet() {
- return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
- }
- /**
- * Returns a lazy seq of nums from start (inclusive) to end
- * (exclusive), by step, where start defaults to 0, step to 1, and end to
- * infinity. When start is equal to end, returns empty list.
- */
- var Range = /*@__PURE__*/(function (IndexedSeq) {
- function Range(start, end, step) {
- if (!(this instanceof Range)) {
- // eslint-disable-next-line no-constructor-return
- return new Range(start, end, step);
- }
- invariant(step !== 0, 'Cannot step a Range by 0');
- start = start || 0;
- if (end === undefined) {
- end = Infinity;
- }
- step = step === undefined ? 1 : Math.abs(step);
- if (end < start) {
- step = -step;
- }
- this._start = start;
- this._end = end;
- this._step = step;
- this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
- if (this.size === 0) {
- if (EMPTY_RANGE) {
- // eslint-disable-next-line no-constructor-return
- return EMPTY_RANGE;
- }
- EMPTY_RANGE = this;
- }
- }
- if ( IndexedSeq ) Range.__proto__ = IndexedSeq;
- Range.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
- Range.prototype.constructor = Range;
- Range.prototype.toString = function toString () {
- if (this.size === 0) {
- return 'Range []';
- }
- return (
- 'Range [ ' +
- this._start +
- '...' +
- this._end +
- (this._step !== 1 ? ' by ' + this._step : '') +
- ' ]'
- );
- };
- Range.prototype.get = function get (index, notSetValue) {
- return this.has(index)
- ? this._start + wrapIndex(this, index) * this._step
- : notSetValue;
- };
- Range.prototype.includes = function includes (searchValue) {
- var possibleIndex = (searchValue - this._start) / this._step;
- return (
- possibleIndex >= 0 &&
- possibleIndex < this.size &&
- possibleIndex === Math.floor(possibleIndex)
- );
- };
- Range.prototype.slice = function slice (begin, end) {
- if (wholeSlice(begin, end, this.size)) {
- return this;
- }
- begin = resolveBegin(begin, this.size);
- end = resolveEnd(end, this.size);
- if (end <= begin) {
- return new Range(0, 0);
- }
- return new Range(
- this.get(begin, this._end),
- this.get(end, this._end),
- this._step
- );
- };
- Range.prototype.indexOf = function indexOf (searchValue) {
- var offsetValue = searchValue - this._start;
- if (offsetValue % this._step === 0) {
- var index = offsetValue / this._step;
- if (index >= 0 && index < this.size) {
- return index;
- }
- }
- return -1;
- };
- Range.prototype.lastIndexOf = function lastIndexOf (searchValue) {
- return this.indexOf(searchValue);
- };
- Range.prototype.__iterate = function __iterate (fn, reverse) {
- var size = this.size;
- var step = this._step;
- var value = reverse ? this._start + (size - 1) * step : this._start;
- var i = 0;
- while (i !== size) {
- if (fn(value, reverse ? size - ++i : i++, this) === false) {
- break;
- }
- value += reverse ? -step : step;
- }
- return i;
- };
- Range.prototype.__iterator = function __iterator (type, reverse) {
- var size = this.size;
- var step = this._step;
- var value = reverse ? this._start + (size - 1) * step : this._start;
- var i = 0;
- return new Iterator(function () {
- if (i === size) {
- return iteratorDone();
- }
- var v = value;
- value += reverse ? -step : step;
- return iteratorValue(type, reverse ? size - ++i : i++, v);
- });
- };
- Range.prototype.equals = function equals (other) {
- return other instanceof Range
- ? this._start === other._start &&
- this._end === other._end &&
- this._step === other._step
- : deepEqual(this, other);
- };
- return Range;
- }(IndexedSeq));
- var EMPTY_RANGE;
- function getIn$1(collection, searchKeyPath, notSetValue) {
- var keyPath = coerceKeyPath(searchKeyPath);
- var i = 0;
- while (i !== keyPath.length) {
- collection = get(collection, keyPath[i++], NOT_SET);
- if (collection === NOT_SET) {
- return notSetValue;
- }
- }
- return collection;
- }
- function getIn(searchKeyPath, notSetValue) {
- return getIn$1(this, searchKeyPath, notSetValue);
- }
- function hasIn$1(collection, keyPath) {
- return getIn$1(collection, keyPath, NOT_SET) !== NOT_SET;
- }
- function hasIn(searchKeyPath) {
- return hasIn$1(this, searchKeyPath);
- }
- function toObject() {
- assertNotInfinite(this.size);
- var object = {};
- this.__iterate(function (v, k) {
- object[k] = v;
- });
- return object;
- }
- // Note: all of these methods are deprecated.
- Collection.isIterable = isCollection;
- Collection.isKeyed = isKeyed;
- Collection.isIndexed = isIndexed;
- Collection.isAssociative = isAssociative;
- Collection.isOrdered = isOrdered;
- Collection.Iterator = Iterator;
- mixin(Collection, {
- // ### Conversion to other types
- toArray: function toArray() {
- assertNotInfinite(this.size);
- var array = new Array(this.size || 0);
- var useTuples = isKeyed(this);
- var i = 0;
- this.__iterate(function (v, k) {
- // Keyed collections produce an array of tuples.
- array[i++] = useTuples ? [k, v] : v;
- });
- return array;
- },
- toIndexedSeq: function toIndexedSeq() {
- return new ToIndexedSequence(this);
- },
- toJS: function toJS$1() {
- return toJS(this);
- },
- toKeyedSeq: function toKeyedSeq() {
- return new ToKeyedSequence(this, true);
- },
- toMap: function toMap() {
- // Use Late Binding here to solve the circular dependency.
- return Map(this.toKeyedSeq());
- },
- toObject: toObject,
- toOrderedMap: function toOrderedMap() {
- // Use Late Binding here to solve the circular dependency.
- return OrderedMap(this.toKeyedSeq());
- },
- toOrderedSet: function toOrderedSet() {
- // Use Late Binding here to solve the circular dependency.
- return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
- },
- toSet: function toSet() {
- // Use Late Binding here to solve the circular dependency.
- return Set(isKeyed(this) ? this.valueSeq() : this);
- },
- toSetSeq: function toSetSeq() {
- return new ToSetSequence(this);
- },
- toSeq: function toSeq() {
- return isIndexed(this)
- ? this.toIndexedSeq()
- : isKeyed(this)
- ? this.toKeyedSeq()
- : this.toSetSeq();
- },
- toStack: function toStack() {
- // Use Late Binding here to solve the circular dependency.
- return Stack(isKeyed(this) ? this.valueSeq() : this);
- },
- toList: function toList() {
- // Use Late Binding here to solve the circular dependency.
- return List(isKeyed(this) ? this.valueSeq() : this);
- },
- // ### Common JavaScript methods and properties
- toString: function toString() {
- return '[Collection]';
- },
- __toString: function __toString(head, tail) {
- if (this.size === 0) {
- return head + tail;
- }
- return (
- head +
- ' ' +
- this.toSeq().map(this.__toStringMapper).join(', ') +
- ' ' +
- tail
- );
- },
- // ### ES6 Collection methods (ES6 Array and Map)
- concat: function concat() {
- var values = [], len = arguments.length;
- while ( len-- ) values[ len ] = arguments[ len ];
- return reify(this, concatFactory(this, values));
- },
- includes: function includes(searchValue) {
- return this.some(function (value) { return is(value, searchValue); });
- },
- entries: function entries() {
- return this.__iterator(ITERATE_ENTRIES);
- },
- every: function every(predicate, context) {
- assertNotInfinite(this.size);
- var returnValue = true;
- this.__iterate(function (v, k, c) {
- if (!predicate.call(context, v, k, c)) {
- returnValue = false;
- return false;
- }
- });
- return returnValue;
- },
- filter: function filter(predicate, context) {
- return reify(this, filterFactory(this, predicate, context, true));
- },
- partition: function partition(predicate, context) {
- return partitionFactory(this, predicate, context);
- },
- find: function find(predicate, context, notSetValue) {
- var entry = this.findEntry(predicate, context);
- return entry ? entry[1] : notSetValue;
- },
- forEach: function forEach(sideEffect, context) {
- assertNotInfinite(this.size);
- return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
- },
- join: function join(separator) {
- assertNotInfinite(this.size);
- separator = separator !== undefined ? '' + separator : ',';
- var joined = '';
- var isFirst = true;
- this.__iterate(function (v) {
- isFirst ? (isFirst = false) : (joined += separator);
- joined += v !== null && v !== undefined ? v.toString() : '';
- });
- return joined;
- },
- keys: function keys() {
- return this.__iterator(ITERATE_KEYS);
- },
- map: function map(mapper, context) {
- return reify(this, mapFactory(this, mapper, context));
- },
- reduce: function reduce$1(reducer, initialReduction, context) {
- return reduce(
- this,
- reducer,
- initialReduction,
- context,
- arguments.length < 2,
- false
- );
- },
- reduceRight: function reduceRight(reducer, initialReduction, context) {
- return reduce(
- this,
- reducer,
- initialReduction,
- context,
- arguments.length < 2,
- true
- );
- },
- reverse: function reverse() {
- return reify(this, reverseFactory(this, true));
- },
- slice: function slice(begin, end) {
- return reify(this, sliceFactory(this, begin, end, true));
- },
- some: function some(predicate, context) {
- assertNotInfinite(this.size);
- var returnValue = false;
- this.__iterate(function (v, k, c) {
- if (predicate.call(context, v, k, c)) {
- returnValue = true;
- return false;
- }
- });
- return returnValue;
- },
- sort: function sort(comparator) {
- return reify(this, sortFactory(this, comparator));
- },
- values: function values() {
- return this.__iterator(ITERATE_VALUES);
- },
- // ### More sequential methods
- butLast: function butLast() {
- return this.slice(0, -1);
- },
- isEmpty: function isEmpty() {
- return this.size !== undefined ? this.size === 0 : !this.some(function () { return true; });
- },
- count: function count(predicate, context) {
- return ensureSize(
- predicate ? this.toSeq().filter(predicate, context) : this
- );
- },
- countBy: function countBy(grouper, context) {
- return countByFactory(this, grouper, context);
- },
- equals: function equals(other) {
- return deepEqual(this, other);
- },
- entrySeq: function entrySeq() {
- var collection = this;
- if (collection._cache) {
- // We cache as an entries array, so we can just return the cache!
- return new ArraySeq(collection._cache);
- }
- var entriesSequence = collection.toSeq().map(entryMapper).toIndexedSeq();
- entriesSequence.fromEntrySeq = function () { return collection.toSeq(); };
- return entriesSequence;
- },
- filterNot: function filterNot(predicate, context) {
- return this.filter(not(predicate), context);
- },
- findEntry: function findEntry(predicate, context, notSetValue) {
- var found = notSetValue;
- this.__iterate(function (v, k, c) {
- if (predicate.call(context, v, k, c)) {
- found = [k, v];
- return false;
- }
- });
- return found;
- },
- findKey: function findKey(predicate, context) {
- var entry = this.findEntry(predicate, context);
- return entry && entry[0];
- },
- findLast: function findLast(predicate, context, notSetValue) {
- return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
- },
- findLastEntry: function findLastEntry(predicate, context, notSetValue) {
- return this.toKeyedSeq()
- .reverse()
- .findEntry(predicate, context, notSetValue);
- },
- findLastKey: function findLastKey(predicate, context) {
- return this.toKeyedSeq().reverse().findKey(predicate, context);
- },
- first: function first(notSetValue) {
- return this.find(returnTrue, null, notSetValue);
- },
- flatMap: function flatMap(mapper, context) {
- return reify(this, flatMapFactory(this, mapper, context));
- },
- flatten: function flatten(depth) {
- return reify(this, flattenFactory(this, depth, true));
- },
- fromEntrySeq: function fromEntrySeq() {
- return new FromEntriesSequence(this);
- },
- get: function get(searchKey, notSetValue) {
- return this.find(function (_, key) { return is(key, searchKey); }, undefined, notSetValue);
- },
- getIn: getIn,
- groupBy: function groupBy(grouper, context) {
- return groupByFactory(this, grouper, context);
- },
- has: function has(searchKey) {
- return this.get(searchKey, NOT_SET) !== NOT_SET;
- },
- hasIn: hasIn,
- isSubset: function isSubset(iter) {
- iter = typeof iter.includes === 'function' ? iter : Collection(iter);
- return this.every(function (value) { return iter.includes(value); });
- },
- isSuperset: function isSuperset(iter) {
- iter = typeof iter.isSubset === 'function' ? iter : Collection(iter);
- return iter.isSubset(this);
- },
- keyOf: function keyOf(searchValue) {
- return this.findKey(function (value) { return is(value, searchValue); });
- },
- keySeq: function keySeq() {
- return this.toSeq().map(keyMapper).toIndexedSeq();
- },
- last: function last(notSetValue) {
- return this.toSeq().reverse().first(notSetValue);
- },
- lastKeyOf: function lastKeyOf(searchValue) {
- return this.toKeyedSeq().reverse().keyOf(searchValue);
- },
- max: function max(comparator) {
- return maxFactory(this, comparator);
- },
- maxBy: function maxBy(mapper, comparator) {
- return maxFactory(this, comparator, mapper);
- },
- min: function min(comparator) {
- return maxFactory(
- this,
- comparator ? neg(comparator) : defaultNegComparator
- );
- },
- minBy: function minBy(mapper, comparator) {
- return maxFactory(
- this,
- comparator ? neg(comparator) : defaultNegComparator,
- mapper
- );
- },
- rest: function rest() {
- return this.slice(1);
- },
- skip: function skip(amount) {
- return amount === 0 ? this : this.slice(Math.max(0, amount));
- },
- skipLast: function skipLast(amount) {
- return amount === 0 ? this : this.slice(0, -Math.max(0, amount));
- },
- skipWhile: function skipWhile(predicate, context) {
- return reify(this, skipWhileFactory(this, predicate, context, true));
- },
- skipUntil: function skipUntil(predicate, context) {
- return this.skipWhile(not(predicate), context);
- },
- sortBy: function sortBy(mapper, comparator) {
- return reify(this, sortFactory(this, comparator, mapper));
- },
- take: function take(amount) {
- return this.slice(0, Math.max(0, amount));
- },
- takeLast: function takeLast(amount) {
- return this.slice(-Math.max(0, amount));
- },
- takeWhile: function takeWhile(predicate, context) {
- return reify(this, takeWhileFactory(this, predicate, context));
- },
- takeUntil: function takeUntil(predicate, context) {
- return this.takeWhile(not(predicate), context);
- },
- update: function update(fn) {
- return fn(this);
- },
- valueSeq: function valueSeq() {
- return this.toIndexedSeq();
- },
- // ### Hashable Object
- hashCode: function hashCode() {
- return this.__hash || (this.__hash = hashCollection(this));
- },
- // ### Internal
- // abstract __iterate(fn, reverse)
- // abstract __iterator(type, reverse)
- });
- var CollectionPrototype = Collection.prototype;
- CollectionPrototype[IS_COLLECTION_SYMBOL] = true;
- CollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.values;
- CollectionPrototype.toJSON = CollectionPrototype.toArray;
- CollectionPrototype.__toStringMapper = quoteString;
- CollectionPrototype.inspect = CollectionPrototype.toSource = function () {
- return this.toString();
- };
- CollectionPrototype.chain = CollectionPrototype.flatMap;
- CollectionPrototype.contains = CollectionPrototype.includes;
- mixin(KeyedCollection, {
- // ### More sequential methods
- flip: function flip() {
- return reify(this, flipFactory(this));
- },
- mapEntries: function mapEntries(mapper, context) {
- var this$1$1 = this;
- var iterations = 0;
- return reify(
- this,
- this.toSeq()
- .map(function (v, k) { return mapper.call(context, [k, v], iterations++, this$1$1); })
- .fromEntrySeq()
- );
- },
- mapKeys: function mapKeys(mapper, context) {
- var this$1$1 = this;
- return reify(
- this,
- this.toSeq()
- .flip()
- .map(function (k, v) { return mapper.call(context, k, v, this$1$1); })
- .flip()
- );
- },
- });
- var KeyedCollectionPrototype = KeyedCollection.prototype;
- KeyedCollectionPrototype[IS_KEYED_SYMBOL] = true;
- KeyedCollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.entries;
- KeyedCollectionPrototype.toJSON = toObject;
- KeyedCollectionPrototype.__toStringMapper = function (v, k) { return quoteString(k) + ': ' + quoteString(v); };
- mixin(IndexedCollection, {
- // ### Conversion to other types
- toKeyedSeq: function toKeyedSeq() {
- return new ToKeyedSequence(this, false);
- },
- // ### ES6 Collection methods (ES6 Array and Map)
- filter: function filter(predicate, context) {
- return reify(this, filterFactory(this, predicate, context, false));
- },
- findIndex: function findIndex(predicate, context) {
- var entry = this.findEntry(predicate, context);
- return entry ? entry[0] : -1;
- },
- indexOf: function indexOf(searchValue) {
- var key = this.keyOf(searchValue);
- return key === undefined ? -1 : key;
- },
- lastIndexOf: function lastIndexOf(searchValue) {
- var key = this.lastKeyOf(searchValue);
- return key === undefined ? -1 : key;
- },
- reverse: function reverse() {
- return reify(this, reverseFactory(this, false));
- },
- slice: function slice(begin, end) {
- return reify(this, sliceFactory(this, begin, end, false));
- },
- splice: function splice(index, removeNum /*, ...values*/) {
- var numArgs = arguments.length;
- removeNum = Math.max(removeNum || 0, 0);
- if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
- return this;
- }
- // If index is negative, it should resolve relative to the size of the
- // collection. However size may be expensive to compute if not cached, so
- // only call count() if the number is in fact negative.
- index = resolveBegin(index, index < 0 ? this.count() : this.size);
- var spliced = this.slice(0, index);
- return reify(
- this,
- numArgs === 1
- ? spliced
- : spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
- );
- },
- // ### More collection methods
- findLastIndex: function findLastIndex(predicate, context) {
- var entry = this.findLastEntry(predicate, context);
- return entry ? entry[0] : -1;
- },
- first: function first(notSetValue) {
- return this.get(0, notSetValue);
- },
- flatten: function flatten(depth) {
- return reify(this, flattenFactory(this, depth, false));
- },
- get: function get(index, notSetValue) {
- index = wrapIndex(this, index);
- return index < 0 ||
- this.size === Infinity ||
- (this.size !== undefined && index > this.size)
- ? notSetValue
- : this.find(function (_, key) { return key === index; }, undefined, notSetValue);
- },
- has: function has(index) {
- index = wrapIndex(this, index);
- return (
- index >= 0 &&
- (this.size !== undefined
- ? this.size === Infinity || index < this.size
- : this.indexOf(index) !== -1)
- );
- },
- interpose: function interpose(separator) {
- return reify(this, interposeFactory(this, separator));
- },
- interleave: function interleave(/*...collections*/) {
- var collections = [this].concat(arrCopy(arguments));
- var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, collections);
- var interleaved = zipped.flatten(true);
- if (zipped.size) {
- interleaved.size = zipped.size * collections.length;
- }
- return reify(this, interleaved);
- },
- keySeq: function keySeq() {
- return Range(0, this.size);
- },
- last: function last(notSetValue) {
- return this.get(-1, notSetValue);
- },
- skipWhile: function skipWhile(predicate, context) {
- return reify(this, skipWhileFactory(this, predicate, context, false));
- },
- zip: function zip(/*, ...collections */) {
- var collections = [this].concat(arrCopy(arguments));
- return reify(this, zipWithFactory(this, defaultZipper, collections));
- },
- zipAll: function zipAll(/*, ...collections */) {
- var collections = [this].concat(arrCopy(arguments));
- return reify(this, zipWithFactory(this, defaultZipper, collections, true));
- },
- zipWith: function zipWith(zipper /*, ...collections */) {
- var collections = arrCopy(arguments);
- collections[0] = this;
- return reify(this, zipWithFactory(this, zipper, collections));
- },
- });
- var IndexedCollectionPrototype = IndexedCollection.prototype;
- IndexedCollectionPrototype[IS_INDEXED_SYMBOL] = true;
- IndexedCollectionPrototype[IS_ORDERED_SYMBOL] = true;
- mixin(SetCollection, {
- // ### ES6 Collection methods (ES6 Array and Map)
- get: function get(value, notSetValue) {
- return this.has(value) ? value : notSetValue;
- },
- includes: function includes(value) {
- return this.has(value);
- },
- // ### More sequential methods
- keySeq: function keySeq() {
- return this.valueSeq();
- },
- });
- var SetCollectionPrototype = SetCollection.prototype;
- SetCollectionPrototype.has = CollectionPrototype.includes;
- SetCollectionPrototype.contains = SetCollectionPrototype.includes;
- SetCollectionPrototype.keys = SetCollectionPrototype.values;
- // Mixin subclasses
- mixin(KeyedSeq, KeyedCollectionPrototype);
- mixin(IndexedSeq, IndexedCollectionPrototype);
- mixin(SetSeq, SetCollectionPrototype);
- // #pragma Helper functions
- function reduce(collection, reducer, reduction, context, useFirst, reverse) {
- assertNotInfinite(collection.size);
- collection.__iterate(function (v, k, c) {
- if (useFirst) {
- useFirst = false;
- reduction = v;
- } else {
- reduction = reducer.call(context, reduction, v, k, c);
- }
- }, reverse);
- return reduction;
- }
- function keyMapper(v, k) {
- return k;
- }
- function entryMapper(v, k) {
- return [k, v];
- }
- function not(predicate) {
- return function () {
- return !predicate.apply(this, arguments);
- };
- }
- function neg(predicate) {
- return function () {
- return -predicate.apply(this, arguments);
- };
- }
- function defaultZipper() {
- return arrCopy(arguments);
- }
- function defaultNegComparator(a, b) {
- return a < b ? 1 : a > b ? -1 : 0;
- }
- function hashCollection(collection) {
- if (collection.size === Infinity) {
- return 0;
- }
- var ordered = isOrdered(collection);
- var keyed = isKeyed(collection);
- var h = ordered ? 1 : 0;
- var size = collection.__iterate(
- keyed
- ? ordered
- ? function (v, k) {
- h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
- }
- : function (v, k) {
- h = (h + hashMerge(hash(v), hash(k))) | 0;
- }
- : ordered
- ? function (v) {
- h = (31 * h + hash(v)) | 0;
- }
- : function (v) {
- h = (h + hash(v)) | 0;
- }
- );
- return murmurHashOfSize(size, h);
- }
- function murmurHashOfSize(size, h) {
- h = imul(h, 0xcc9e2d51);
- h = imul((h << 15) | (h >>> -15), 0x1b873593);
- h = imul((h << 13) | (h >>> -13), 5);
- h = ((h + 0xe6546b64) | 0) ^ size;
- h = imul(h ^ (h >>> 16), 0x85ebca6b);
- h = imul(h ^ (h >>> 13), 0xc2b2ae35);
- h = smi(h ^ (h >>> 16));
- return h;
- }
- function hashMerge(a, b) {
- return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
- }
- var OrderedSet = /*@__PURE__*/(function (Set) {
- function OrderedSet(value) {
- // eslint-disable-next-line no-constructor-return
- return value === undefined || value === null
- ? emptyOrderedSet()
- : isOrderedSet(value)
- ? value
- : emptyOrderedSet().withMutations(function (set) {
- var iter = SetCollection(value);
- assertNotInfinite(iter.size);
- iter.forEach(function (v) { return set.add(v); });
- });
- }
- if ( Set ) OrderedSet.__proto__ = Set;
- OrderedSet.prototype = Object.create( Set && Set.prototype );
- OrderedSet.prototype.constructor = OrderedSet;
- OrderedSet.of = function of (/*...values*/) {
- return this(arguments);
- };
- OrderedSet.fromKeys = function fromKeys (value) {
- return this(KeyedCollection(value).keySeq());
- };
- OrderedSet.prototype.toString = function toString () {
- return this.__toString('OrderedSet {', '}');
- };
- return OrderedSet;
- }(Set));
- OrderedSet.isOrderedSet = isOrderedSet;
- var OrderedSetPrototype = OrderedSet.prototype;
- OrderedSetPrototype[IS_ORDERED_SYMBOL] = true;
- OrderedSetPrototype.zip = IndexedCollectionPrototype.zip;
- OrderedSetPrototype.zipWith = IndexedCollectionPrototype.zipWith;
- OrderedSetPrototype.zipAll = IndexedCollectionPrototype.zipAll;
- OrderedSetPrototype.__empty = emptyOrderedSet;
- OrderedSetPrototype.__make = makeOrderedSet;
- function makeOrderedSet(map, ownerID) {
- var set = Object.create(OrderedSetPrototype);
- set.size = map ? map.size : 0;
- set._map = map;
- set.__ownerID = ownerID;
- return set;
- }
- var EMPTY_ORDERED_SET;
- function emptyOrderedSet() {
- return (
- EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()))
- );
- }
- var PairSorting = {
- LeftThenRight: -1,
- RightThenLeft: +1,
- };
- function throwOnInvalidDefaultValues(defaultValues) {
- if (isRecord(defaultValues)) {
- throw new Error(
- 'Can not call `Record` with an immutable Record as default values. Use a plain javascript object instead.'
- );
- }
- if (isImmutable(defaultValues)) {
- throw new Error(
- 'Can not call `Record` with an immutable Collection as default values. Use a plain javascript object instead.'
- );
- }
- if (defaultValues === null || typeof defaultValues !== 'object') {
- throw new Error(
- 'Can not call `Record` with a non-object as default values. Use a plain javascript object instead.'
- );
- }
- }
- var Record = function Record(defaultValues, name) {
- var hasInitialized;
- throwOnInvalidDefaultValues(defaultValues);
- var RecordType = function Record(values) {
- var this$1$1 = this;
- if (values instanceof RecordType) {
- return values;
- }
- if (!(this instanceof RecordType)) {
- return new RecordType(values);
- }
- if (!hasInitialized) {
- hasInitialized = true;
- var keys = Object.keys(defaultValues);
- var indices = (RecordTypePrototype._indices = {});
- // Deprecated: left to attempt not to break any external code which
- // relies on a ._name property existing on record instances.
- // Use Record.getDescriptiveName() instead
- RecordTypePrototype._name = name;
- RecordTypePrototype._keys = keys;
- RecordTypePrototype._defaultValues = defaultValues;
- for (var i = 0; i < keys.length; i++) {
- var propName = keys[i];
- indices[propName] = i;
- if (RecordTypePrototype[propName]) {
- /* eslint-disable no-console */
- typeof console === 'object' &&
- console.warn &&
- console.warn(
- 'Cannot define ' +
- recordName(this) +
- ' with property "' +
- propName +
- '" since that property name is part of the Record API.'
- );
- /* eslint-enable no-console */
- } else {
- setProp(RecordTypePrototype, propName);
- }
- }
- }
- this.__ownerID = undefined;
- this._values = List().withMutations(function (l) {
- l.setSize(this$1$1._keys.length);
- KeyedCollection(values).forEach(function (v, k) {
- l.set(this$1$1._indices[k], v === this$1$1._defaultValues[k] ? undefined : v);
- });
- });
- return this;
- };
- var RecordTypePrototype = (RecordType.prototype =
- Object.create(RecordPrototype));
- RecordTypePrototype.constructor = RecordType;
- if (name) {
- RecordType.displayName = name;
- }
- // eslint-disable-next-line no-constructor-return
- return RecordType;
- };
- Record.prototype.toString = function toString () {
- var str = recordName(this) + ' { ';
- var keys = this._keys;
- var k;
- for (var i = 0, l = keys.length; i !== l; i++) {
- k = keys[i];
- str += (i ? ', ' : '') + k + ': ' + quoteString(this.get(k));
- }
- return str + ' }';
- };
- Record.prototype.equals = function equals (other) {
- return (
- this === other ||
- (isRecord(other) && recordSeq(this).equals(recordSeq(other)))
- );
- };
- Record.prototype.hashCode = function hashCode () {
- return recordSeq(this).hashCode();
- };
- // @pragma Access
- Record.prototype.has = function has (k) {
- return this._indices.hasOwnProperty(k);
- };
- Record.prototype.get = function get (k, notSetValue) {
- if (!this.has(k)) {
- return notSetValue;
- }
- var index = this._indices[k];
- var value = this._values.get(index);
- return value === undefined ? this._defaultValues[k] : value;
- };
- // @pragma Modification
- Record.prototype.set = function set (k, v) {
- if (this.has(k)) {
- var newValues = this._values.set(
- this._indices[k],
- v === this._defaultValues[k] ? undefined : v
- );
- if (newValues !== this._values && !this.__ownerID) {
- return makeRecord(this, newValues);
- }
- }
- return this;
- };
- Record.prototype.remove = function remove (k) {
- return this.set(k);
- };
- Record.prototype.clear = function clear () {
- var newValues = this._values.clear().setSize(this._keys.length);
- return this.__ownerID ? this : makeRecord(this, newValues);
- };
- Record.prototype.wasAltered = function wasAltered () {
- return this._values.wasAltered();
- };
- Record.prototype.toSeq = function toSeq () {
- return recordSeq(this);
- };
- Record.prototype.toJS = function toJS$1 () {
- return toJS(this);
- };
- Record.prototype.entries = function entries () {
- return this.__iterator(ITERATE_ENTRIES);
- };
- Record.prototype.__iterator = function __iterator (type, reverse) {
- return recordSeq(this).__iterator(type, reverse);
- };
- Record.prototype.__iterate = function __iterate (fn, reverse) {
- return recordSeq(this).__iterate(fn, reverse);
- };
- Record.prototype.__ensureOwner = function __ensureOwner (ownerID) {
- if (ownerID === this.__ownerID) {
- return this;
- }
- var newValues = this._values.__ensureOwner(ownerID);
- if (!ownerID) {
- this.__ownerID = ownerID;
- this._values = newValues;
- return this;
- }
- return makeRecord(this, newValues, ownerID);
- };
- Record.isRecord = isRecord;
- Record.getDescriptiveName = recordName;
- var RecordPrototype = Record.prototype;
- RecordPrototype[IS_RECORD_SYMBOL] = true;
- RecordPrototype[DELETE] = RecordPrototype.remove;
- RecordPrototype.deleteIn = RecordPrototype.removeIn = deleteIn;
- RecordPrototype.getIn = getIn;
- RecordPrototype.hasIn = CollectionPrototype.hasIn;
- RecordPrototype.merge = merge$1;
- RecordPrototype.mergeWith = mergeWith$1;
- RecordPrototype.mergeIn = mergeIn;
- RecordPrototype.mergeDeep = mergeDeep;
- RecordPrototype.mergeDeepWith = mergeDeepWith;
- RecordPrototype.mergeDeepIn = mergeDeepIn;
- RecordPrototype.setIn = setIn;
- RecordPrototype.update = update;
- RecordPrototype.updateIn = updateIn;
- RecordPrototype.withMutations = withMutations;
- RecordPrototype.asMutable = asMutable;
- RecordPrototype.asImmutable = asImmutable;
- RecordPrototype[ITERATOR_SYMBOL] = RecordPrototype.entries;
- RecordPrototype.toJSON = RecordPrototype.toObject =
- CollectionPrototype.toObject;
- RecordPrototype.inspect = RecordPrototype.toSource = function () {
- return this.toString();
- };
- function makeRecord(likeRecord, values, ownerID) {
- var record = Object.create(Object.getPrototypeOf(likeRecord));
- record._values = values;
- record.__ownerID = ownerID;
- return record;
- }
- function recordName(record) {
- return record.constructor.displayName || record.constructor.name || 'Record';
- }
- function recordSeq(record) {
- return keyedSeqFromValue(record._keys.map(function (k) { return [k, record.get(k)]; }));
- }
- function setProp(prototype, name) {
- try {
- Object.defineProperty(prototype, name, {
- get: function () {
- return this.get(name);
- },
- set: function (value) {
- invariant(this.__ownerID, 'Cannot set on an immutable record.');
- this.set(name, value);
- },
- });
- } catch (error) {
- // Object.defineProperty failed. Probably IE8.
- }
- }
- /**
- * Returns a lazy Seq of `value` repeated `times` times. When `times` is
- * undefined, returns an infinite sequence of `value`.
- */
- var Repeat = /*@__PURE__*/(function (IndexedSeq) {
- function Repeat(value, times) {
- if (!(this instanceof Repeat)) {
- // eslint-disable-next-line no-constructor-return
- return new Repeat(value, times);
- }
- this._value = value;
- this.size = times === undefined ? Infinity : Math.max(0, times);
- if (this.size === 0) {
- if (EMPTY_REPEAT) {
- // eslint-disable-next-line no-constructor-return
- return EMPTY_REPEAT;
- }
- EMPTY_REPEAT = this;
- }
- }
- if ( IndexedSeq ) Repeat.__proto__ = IndexedSeq;
- Repeat.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
- Repeat.prototype.constructor = Repeat;
- Repeat.prototype.toString = function toString () {
- if (this.size === 0) {
- return 'Repeat []';
- }
- return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
- };
- Repeat.prototype.get = function get (index, notSetValue) {
- return this.has(index) ? this._value : notSetValue;
- };
- Repeat.prototype.includes = function includes (searchValue) {
- return is(this._value, searchValue);
- };
- Repeat.prototype.slice = function slice (begin, end) {
- var size = this.size;
- return wholeSlice(begin, end, size)
- ? this
- : new Repeat(
- this._value,
- resolveEnd(end, size) - resolveBegin(begin, size)
- );
- };
- Repeat.prototype.reverse = function reverse () {
- return this;
- };
- Repeat.prototype.indexOf = function indexOf (searchValue) {
- if (is(this._value, searchValue)) {
- return 0;
- }
- return -1;
- };
- Repeat.prototype.lastIndexOf = function lastIndexOf (searchValue) {
- if (is(this._value, searchValue)) {
- return this.size;
- }
- return -1;
- };
- Repeat.prototype.__iterate = function __iterate (fn, reverse) {
- var size = this.size;
- var i = 0;
- while (i !== size) {
- if (fn(this._value, reverse ? size - ++i : i++, this) === false) {
- break;
- }
- }
- return i;
- };
- Repeat.prototype.__iterator = function __iterator (type, reverse) {
- var this$1$1 = this;
- var size = this.size;
- var i = 0;
- return new Iterator(function () { return i === size
- ? iteratorDone()
- : iteratorValue(type, reverse ? size - ++i : i++, this$1$1._value); }
- );
- };
- Repeat.prototype.equals = function equals (other) {
- return other instanceof Repeat
- ? is(this._value, other._value)
- : deepEqual(this, other);
- };
- return Repeat;
- }(IndexedSeq));
- var EMPTY_REPEAT;
- function fromJS(value, converter) {
- return fromJSWith(
- [],
- converter || defaultConverter,
- value,
- '',
- converter && converter.length > 2 ? [] : undefined,
- { '': value }
- );
- }
- function fromJSWith(stack, converter, value, key, keyPath, parentValue) {
- if (
- typeof value !== 'string' &&
- !isImmutable(value) &&
- (isArrayLike(value) || hasIterator(value) || isPlainObject(value))
- ) {
- if (~stack.indexOf(value)) {
- throw new TypeError('Cannot convert circular structure to Immutable');
- }
- stack.push(value);
- keyPath && key !== '' && keyPath.push(key);
- var converted = converter.call(
- parentValue,
- key,
- Seq(value).map(function (v, k) { return fromJSWith(stack, converter, v, k, keyPath, value); }
- ),
- keyPath && keyPath.slice()
- );
- stack.pop();
- keyPath && keyPath.pop();
- return converted;
- }
- return value;
- }
- function defaultConverter(k, v) {
- // Effectively the opposite of "Collection.toSeq()"
- return isIndexed(v) ? v.toList() : isKeyed(v) ? v.toMap() : v.toSet();
- }
- var version = "4.3.7";
- var Immutable = {
- version: version,
- Collection: Collection,
- // Note: Iterable is deprecated
- Iterable: Collection,
- Seq: Seq,
- Map: Map,
- OrderedMap: OrderedMap,
- List: List,
- Stack: Stack,
- Set: Set,
- OrderedSet: OrderedSet,
- PairSorting: PairSorting,
- Record: Record,
- Range: Range,
- Repeat: Repeat,
- is: is,
- fromJS: fromJS,
- hash: hash,
- isImmutable: isImmutable,
- isCollection: isCollection,
- isKeyed: isKeyed,
- isIndexed: isIndexed,
- isAssociative: isAssociative,
- isOrdered: isOrdered,
- isValueObject: isValueObject,
- isPlainObject: isPlainObject,
- isSeq: isSeq,
- isList: isList,
- isMap: isMap,
- isOrderedMap: isOrderedMap,
- isStack: isStack,
- isSet: isSet,
- isOrderedSet: isOrderedSet,
- isRecord: isRecord,
- get: get,
- getIn: getIn$1,
- has: has,
- hasIn: hasIn$1,
- merge: merge,
- mergeDeep: mergeDeep$1,
- mergeWith: mergeWith,
- mergeDeepWith: mergeDeepWith$1,
- remove: remove,
- removeIn: removeIn,
- set: set,
- setIn: setIn$1,
- update: update$1,
- updateIn: updateIn$1,
- };
- // Note: Iterable is deprecated
- var Iterable = Collection;
- exports.Collection = Collection;
- exports.Iterable = Iterable;
- exports.List = List;
- exports.Map = Map;
- exports.OrderedMap = OrderedMap;
- exports.OrderedSet = OrderedSet;
- exports.PairSorting = PairSorting;
- exports.Range = Range;
- exports.Record = Record;
- exports.Repeat = Repeat;
- exports.Seq = Seq;
- exports.Set = Set;
- exports.Stack = Stack;
- exports.default = Immutable;
- exports.fromJS = fromJS;
- exports.get = get;
- exports.getIn = getIn$1;
- exports.has = has;
- exports.hasIn = hasIn$1;
- exports.hash = hash;
- exports.is = is;
- exports.isAssociative = isAssociative;
- exports.isCollection = isCollection;
- exports.isImmutable = isImmutable;
- exports.isIndexed = isIndexed;
- exports.isKeyed = isKeyed;
- exports.isList = isList;
- exports.isMap = isMap;
- exports.isOrdered = isOrdered;
- exports.isOrderedMap = isOrderedMap;
- exports.isOrderedSet = isOrderedSet;
- exports.isPlainObject = isPlainObject;
- exports.isRecord = isRecord;
- exports.isSeq = isSeq;
- exports.isSet = isSet;
- exports.isStack = isStack;
- exports.isValueObject = isValueObject;
- exports.merge = merge;
- exports.mergeDeep = mergeDeep$1;
- exports.mergeDeepWith = mergeDeepWith$1;
- exports.mergeWith = mergeWith;
- exports.remove = remove;
- exports.removeIn = removeIn;
- exports.set = set;
- exports.setIn = setIn$1;
- exports.update = update$1;
- exports.updateIn = updateIn$1;
- exports.version = version;
- Object.defineProperty(exports, '__esModule', { value: true });
- })));
|