immutable.js 163 KB

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