partial.lenses.js 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('infestines')) :
  3. typeof define === 'function' && define.amd ? define(['exports', 'infestines'], factory) :
  4. (factory((global.L = {}),global.I));
  5. }(this, (function (exports,I) { 'use strict';
  6. var LENGTH = 'length';
  7. var addU = function addU(x, y) {
  8. return x + y;
  9. };
  10. var multiplyU = function multiplyU(x, y) {
  11. return x * y;
  12. };
  13. var add = /*#__PURE__*/I.curry(addU);
  14. var multiply = /*#__PURE__*/I.curry(multiplyU);
  15. var divideBy = /*#__PURE__*/I.curry(function (d, n) {
  16. return n / d;
  17. });
  18. var negate = function negate(x) {
  19. return -x;
  20. };
  21. var ltU = function ltU(x, y) {
  22. return x < y;
  23. };
  24. var gtU = function gtU(x, y) {
  25. return x > y;
  26. };
  27. var isInstanceOf = /*#__PURE__*/I.curry(I.isInstanceOfU);
  28. var protoless = function protoless(o) {
  29. return I.assign(I.create(null), o);
  30. };
  31. var protoless0 = /*#__PURE__*/I.freeze( /*#__PURE__*/protoless(I.object0));
  32. var replace = /*#__PURE__*/I.curry(function (p, r, s) {
  33. return s.replace(p, r);
  34. });
  35. function isPrimitiveData(x) {
  36. switch (typeof x) {
  37. case 'boolean':
  38. case 'number':
  39. case 'string':
  40. return true;
  41. default:
  42. return false;
  43. }
  44. }
  45. var iterator = Symbol.iterator;
  46. var dep = function dep(xs2xsyC) {
  47. return function (xsy) {
  48. return I.arityN(xsy[LENGTH], I.defineNameU(function () {
  49. return xs2xsyC.apply(undefined, arguments)(xsy).apply(undefined, arguments);
  50. }, xsy.name));
  51. };
  52. };
  53. var fn = function fn(xsC, yC) {
  54. return function (xsy) {
  55. return I.arityN(xsy[LENGTH], I.defineNameU(function () {
  56. for (var _len = arguments.length, xs = Array(_len), _key = 0; _key < _len; _key++) {
  57. xs[_key] = arguments[_key];
  58. }
  59. return yC(xsy.apply(null, xsC(xs)));
  60. }, xsy.name));
  61. };
  62. };
  63. var res = function res(yC) {
  64. return fn(I.id, yC);
  65. };
  66. var args = function args(xsC) {
  67. return fn(xsC, I.id);
  68. };
  69. var nth = function nth(i, xC) {
  70. return function (xs) {
  71. var ys = xs.slice(0);
  72. ys[i] = xC(ys[i]);
  73. return ys;
  74. };
  75. };
  76. var par = function par(i, xC) {
  77. return args(nth(i, xC));
  78. };
  79. var and = function and() {
  80. for (var _len2 = arguments.length, xCs = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  81. xCs[_key2] = arguments[_key2];
  82. }
  83. return function (x) {
  84. for (var i = 0, n = xCs[LENGTH]; i < n; ++i) {
  85. x = xCs[i](x);
  86. }return x;
  87. };
  88. };
  89. var or = function or() {
  90. for (var _len3 = arguments.length, xCs = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  91. xCs[_key3] = arguments[_key3];
  92. }
  93. return function (x) {
  94. var es = null;
  95. for (var i = 0, n = xCs[LENGTH]; i < n; ++i) {
  96. try {
  97. return xCs[i](x);
  98. } catch (e) {
  99. es = e;
  100. }
  101. }
  102. throw es;
  103. };
  104. };
  105. var ef = function ef(xE) {
  106. return I.defineNameU(function (x) {
  107. xE(x);
  108. return x;
  109. }, xE.name);
  110. };
  111. var tup = function tup() {
  112. for (var _len4 = arguments.length, xCs = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  113. xCs[_key4] = arguments[_key4];
  114. }
  115. return function (xs) {
  116. if (xs[LENGTH] !== xCs[LENGTH]) throw Error('Expected array of ' + xCs[LENGTH] + ' elements, but got ' + xs[LENGTH]);
  117. return and.apply(null, xCs.map(function (xC, i) {
  118. return nth(i, xC);
  119. }))(xs);
  120. };
  121. };
  122. var arr = function arr(xC) {
  123. return function (xs) {
  124. return xs.map(xC);
  125. };
  126. };
  127. //
  128. var id = function id(x) {
  129. return x;
  130. };
  131. var setName = I.defineNameU;
  132. var copyName = function (to, from) {
  133. return I.defineNameU(to, from.name);
  134. };
  135. var toRegExpU = function toRegExpU(str, flags) {
  136. return I.isString(str) ? new RegExp(replace(/[|\\{}()[\]^$+*?.]/g, '\\$&', str), flags) : str;
  137. };
  138. //
  139. var isPair = function isPair(x) {
  140. return I.isArray(x) && x[LENGTH] === 2;
  141. };
  142. //
  143. var inserterOp = /*#__PURE__*/I.curry(function (inserter, value) {
  144. return [inserter, setOp(value)];
  145. });
  146. //
  147. var toGetter = function toGetter(getter) {
  148. if (typeof getter === 'function' && getter[LENGTH] < 4) return getter;
  149. getter = toFunction(getter);
  150. return function (x, i) {
  151. return getter(x, i, Select, id);
  152. };
  153. };
  154. //
  155. var tryCatch = function tryCatch(fn$$1) {
  156. return copyName(function (x) {
  157. try {
  158. return fn$$1(x);
  159. } catch (e) {
  160. return e;
  161. }
  162. }, fn$$1);
  163. };
  164. //
  165. var toStringPartial = function toStringPartial(x) {
  166. return void 0 !== x ? String(x) : '';
  167. };
  168. var sliceIndex = function sliceIndex(m, l, d, i) {
  169. return void 0 !== i ? Math.min(Math.max(m, i < 0 ? l + i : i), l) : d;
  170. };
  171. var cpair = function cpair(xs) {
  172. return function (x) {
  173. return [x, xs];
  174. };
  175. };
  176. var pairPartial = function pairPartial(k) {
  177. return function (v) {
  178. return void 0 !== k && void 0 !== v ? [k, v] : void 0;
  179. };
  180. };
  181. var unto = function unto(c) {
  182. return function (x) {
  183. return void 0 !== x ? x : c;
  184. };
  185. };
  186. var unto0 = /*#__PURE__*/unto(0);
  187. var toTrue = /*#__PURE__*/I.always(true);
  188. var notPartial = function complement(x) {
  189. return void 0 !== x ? !x : x;
  190. };
  191. var expect = function expect(p, f) {
  192. return copyName(function (x) {
  193. return p(x) ? f(x) : void 0;
  194. }, f);
  195. };
  196. var freezeInDev = I.freeze;
  197. var freezeResultInDev = res(I.freeze);
  198. var deepFreezeInDev = function deepFreezeInDev(x) {
  199. if (I.isArray(x)) {
  200. x.forEach(deepFreezeInDev);
  201. I.freeze(x);
  202. } else if (I.isObject(x)) {
  203. for (var k in x) {
  204. deepFreezeInDev(x[k]);
  205. }I.freeze(x);
  206. }
  207. return x;
  208. };
  209. function freezeObjectOfObjects(xs) {
  210. if (xs) for (var k in xs) {
  211. I.freeze(xs[k]);
  212. }return I.freeze(xs);
  213. }
  214. var isArrayOrPrimitive = function isArrayOrPrimitive(x) {
  215. return !(x instanceof Object) || I.isArray(x);
  216. };
  217. var rev = /*#__PURE__*/(res(I.freeze))(function reverse(xs) {
  218. if (seemsArrayLike(xs)) {
  219. var n = xs[LENGTH];
  220. var ys = Array(n);
  221. var i = 0;
  222. while (n) {
  223. ys[i++] = xs[--n];
  224. }return ys;
  225. }
  226. });
  227. //
  228. var mapPartialIndexU = /*#__PURE__*/(function (fn$$1) {
  229. return function (xi2y, xs, skip) {
  230. var ys = fn$$1(xi2y, xs, skip);
  231. if (xs !== ys) I.freeze(ys);
  232. return ys;
  233. };
  234. })(function (xi2y, xs, skip) {
  235. var n = xs[LENGTH];
  236. var ys = Array(n);
  237. var j = 0;
  238. var same = true;
  239. for (var i = 0; i < n; ++i) {
  240. var x = xs[i];
  241. var y = xi2y(x, i);
  242. if (skip !== y) {
  243. ys[j++] = y;
  244. if (same) same = x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
  245. }
  246. }
  247. if (j !== n) {
  248. ys[LENGTH] = j;
  249. return ys;
  250. } else if (same) {
  251. return xs;
  252. } else {
  253. return ys;
  254. }
  255. });
  256. var mapIfArrayLike = function mapIfArrayLike(xi2y, xs) {
  257. return seemsArrayLike(xs) ? mapPartialIndexU(xi2y, xs, void 0) : void 0;
  258. };
  259. var mapsIfArray = /*#__PURE__*/(res(I.freeze))(function (x2y, xs) {
  260. if (I.isArray(xs)) {
  261. var n = xs[LENGTH];
  262. var ys = Array();
  263. for (var i = 0; i < n; ++i) {
  264. if (void 0 === (ys[i] = x2y(xs[i]))) {
  265. return void 0;
  266. }
  267. }
  268. return ys;
  269. }
  270. });
  271. var copyToFrom = /*#__PURE__*/(function (fn$$1) {
  272. return function (ys, k, xs, i, j) {
  273. return ys[LENGTH] === k + j - i ? I.freeze(fn$$1(ys, k, xs, i, j)) : fn$$1(ys, k, xs, i, j);
  274. };
  275. })(function (ys, k, xs, i, j) {
  276. while (i < j) {
  277. ys[k++] = xs[i++];
  278. }return ys;
  279. });
  280. //
  281. function selectInArrayLike(xi2v, xs) {
  282. for (var i = 0, n = xs[LENGTH]; i < n; ++i) {
  283. var v = xi2v(xs[i], i);
  284. if (void 0 !== v) return v;
  285. }
  286. }
  287. //
  288. var ConstantWith = function ConstantWith(ap, empty) {
  289. return I.Applicative(I.sndU, I.always(empty), ap);
  290. };
  291. var ConstantOf = function ConstantOf(_ref) {
  292. var concat = _ref.concat,
  293. empty = _ref.empty;
  294. return ConstantWith(concat, empty());
  295. };
  296. var Sum = /*#__PURE__*/ConstantWith(addU, 0);
  297. var mumBy = function mumBy(ord) {
  298. return I.curry(function mumBy(xi2y, t, s) {
  299. xi2y = toGetter(xi2y);
  300. var minX = void 0;
  301. var minY = void 0;
  302. getAsU(function (x, i) {
  303. var y = xi2y(x, i);
  304. if (void 0 !== y && (void 0 === minY || ord(y, minY))) {
  305. minX = x;
  306. minY = y;
  307. }
  308. }, t, s);
  309. return minX;
  310. });
  311. };
  312. //
  313. var traverseU = function traverse(C, xi2yC, t, s) {
  314. return toFunction(t)(s, void 0, C, xi2yC);
  315. };
  316. //
  317. var expectedOptic = 'Expecting an optic';
  318. var opticIsEither = 'An optic can be either\n- a string,\n- a non-negative integer,\n- a quaternary optic function,\n- an ordinary unary or binary function, or\n- an array of optics.\nSee documentation of `toFunction` and `compose` for details.';
  319. var header = 'partial.lenses: ';
  320. function warn(f, m) {
  321. if (!f.warned) {
  322. f.warned = 1;
  323. console.warn(header + m);
  324. }
  325. }
  326. function errorGiven(m, o, e) {
  327. m = header + m + '.';
  328. e = e ? '\n' + e : '';
  329. console.error(m, 'Given:', o, e);
  330. throw Error(m + e);
  331. }
  332. var reqIndex = function index(x) {
  333. if (!Number.isInteger(x) || x < 0) errorGiven('`index` expects a non-negative integer', x);
  334. };
  335. function reqFunction(o) {
  336. if (!(I.isFunction(o) && (o[LENGTH] === 4 || o[LENGTH] <= 2))) errorGiven(expectedOptic, o, opticIsEither);
  337. }
  338. function reqFn(x) {
  339. if (!I.isFunction(x)) errorGiven('Expected a function', x);
  340. }
  341. function reqArray(o) {
  342. if (!I.isArray(o)) errorGiven(expectedOptic, o, opticIsEither);
  343. }
  344. function reqOptic(o) {
  345. switch (typeof o) {
  346. case 'string':
  347. break;
  348. case 'number':
  349. reqIndex(o);
  350. break;
  351. case 'object':
  352. reqArray(o);
  353. for (var i = 0, n = o[LENGTH]; i < n; ++i) {
  354. reqOptic(o[i]);
  355. }break;
  356. default:
  357. reqFunction(o);
  358. break;
  359. }
  360. }
  361. //
  362. var reqString = function reqString(msg) {
  363. return function (x) {
  364. if (!I.isString(x)) errorGiven(msg, x);
  365. };
  366. };
  367. var reqMaybeArray = function reqMaybeArray(msg) {
  368. return function (zs) {
  369. if (!(void 0 === zs || seemsArrayLike(zs))) errorGiven(msg, zs);
  370. };
  371. };
  372. //
  373. var reqMonad = function reqMonad(name) {
  374. return function (C) {
  375. if (!C.chain) errorGiven('`' + name + '` requires a monad', C, 'Note that you can only `modify`, `remove`, `set`, and `traverse` a transform.');
  376. };
  377. };
  378. //
  379. var mkTraverse = function mkTraverse(after, toC) {
  380. return I.curryN(4, copyName(function (xi2yC, m) {
  381. return m = toC(m), function (t, s) {
  382. return after(traverseU(m, xi2yC, t, s));
  383. };
  384. }, toC));
  385. };
  386. //
  387. var consExcept = function consExcept(skip) {
  388. return function (t) {
  389. return function (h) {
  390. return skip !== h ? [h, t] : t;
  391. };
  392. };
  393. };
  394. var pushTo = function pushTo(n, xs) {
  395. while (consExcept !== n) {
  396. xs.push(n[0]);
  397. n = n[1];
  398. }
  399. return xs;
  400. };
  401. var consTo = /*#__PURE__*/(res(I.freeze))(function (n) {
  402. return pushTo(n, []).reverse();
  403. });
  404. function traversePartialIndex(A, xi2yA, xs, skip) {
  405. var map = A.map,
  406. ap = A.ap;
  407. var xsA = A.of(consExcept);
  408. var n = xs[LENGTH];
  409. if (map === I.sndU) {
  410. for (var i = 0; i < n; ++i) {
  411. xsA = ap(xsA, xi2yA(xs[i], i));
  412. }return xsA;
  413. } else {
  414. var cons = consExcept(skip);
  415. for (var _i2 = 0; _i2 < n; ++_i2) {
  416. xsA = ap(map(cons, xsA), xi2yA(xs[_i2], _i2));
  417. }return map(consTo, xsA);
  418. }
  419. }
  420. //
  421. var SelectLog = /*#__PURE__*/I.Applicative(function (f, _ref2) {
  422. var p = _ref2.p,
  423. x = _ref2.x,
  424. c = _ref2.c;
  425. x = f(x);
  426. if (!I.isFunction(x)) p = [x, p];
  427. return { p: p, x: x, c: c };
  428. }, function (x) {
  429. return { p: [], x: x, c: undefined };
  430. }, function (l, r) {
  431. var v = undefined !== l.c ? l : r;
  432. return { p: v.p, x: l.x(r.x), c: v.c };
  433. });
  434. //
  435. var lensFrom = function lensFrom(get, set) {
  436. return function (i) {
  437. return function (x, _i, F, xi2yF) {
  438. return F.map(function (v) {
  439. return set(i, v, x);
  440. }, xi2yF(get(i, x), i));
  441. };
  442. };
  443. };
  444. //
  445. var getProp = function getProp(k, o) {
  446. return o instanceof Object ? o[k] : void 0;
  447. };
  448. var setProp = /*#__PURE__*/(res(I.freeze))(function (k, v, o) {
  449. return void 0 !== v ? I.assocPartialU(k, v, o) : I.dissocPartialU(k, o) || I.object0;
  450. });
  451. var funProp = /*#__PURE__*/lensFrom(getProp, setProp);
  452. //
  453. var getIndex = function getIndex(i, xs) {
  454. return seemsArrayLike(xs) ? xs[i] : void 0;
  455. };
  456. var setIndex = /*#__PURE__*/(fn(nth(0, ef(reqIndex)), I.freeze))(function (i, x, xs) {
  457. if (!seemsArrayLike(xs)) xs = '';
  458. var n = xs[LENGTH];
  459. if (void 0 !== x) {
  460. var m = Math.max(i + 1, n);
  461. var ys = Array(m);
  462. for (var j = 0; j < m; ++j) {
  463. ys[j] = xs[j];
  464. }ys[i] = x;
  465. return ys;
  466. } else {
  467. if (n <= i) return copyToFrom(Array(n), 0, xs, 0, n);
  468. var _ys = Array(n - 1);
  469. for (var _j = 0; _j < i; ++_j) {
  470. _ys[_j] = xs[_j];
  471. }for (var _j2 = i + 1; _j2 < n; ++_j2) {
  472. _ys[_j2 - 1] = xs[_j2];
  473. }return _ys;
  474. }
  475. });
  476. var funIndex = /*#__PURE__*/lensFrom(getIndex, setIndex);
  477. //
  478. var composedMiddle = function composedMiddle(o, r) {
  479. return function (F, xi2yF) {
  480. return xi2yF = r(F, xi2yF), function (x, i) {
  481. return o(x, i, F, xi2yF);
  482. };
  483. };
  484. };
  485. function composed(oi0, os) {
  486. var n = os[LENGTH] - oi0;
  487. if (n < 2) {
  488. return n ? toFunction(os[oi0]) : identity;
  489. } else {
  490. var _last = toFunction(os[oi0 + --n]);
  491. var r = function r(F, xi2yF) {
  492. return function (x, i) {
  493. return _last(x, i, F, xi2yF);
  494. };
  495. };
  496. while (--n) {
  497. r = composedMiddle(toFunction(os[oi0 + n]), r);
  498. }var _first = toFunction(os[oi0]);
  499. return function (x, i, F, xi2yF) {
  500. return _first(x, i, F, r(F, xi2yF));
  501. };
  502. }
  503. }
  504. var disperseU = function disperse(traversal, values, data) {
  505. if (!seemsArrayLike(values)) values = '';
  506. var i = 0;
  507. return modifyU(traversal, function () {
  508. return values[i++];
  509. }, data);
  510. };
  511. var setU = /*#__PURE__*/(par(0, ef(reqOptic)))(function set(o, x, s) {
  512. switch (typeof o) {
  513. case 'string':
  514. return setProp(o, x, s);
  515. case 'number':
  516. return setIndex(o, x, s);
  517. case 'object':
  518. return modifyComposed(o, 0, s, x);
  519. default:
  520. return o[LENGTH] === 4 ? o(s, void 0, I.Identity, I.always(x)) : s;
  521. }
  522. });
  523. var getInverseU = function getInverse(o, x) {
  524. return setU(o, x, void 0);
  525. };
  526. var modifyU = /*#__PURE__*/(par(0, ef(reqOptic)))(function modify(o, xi2x, s) {
  527. switch (typeof o) {
  528. case 'string':
  529. return setProp(o, xi2x(getProp(o, s), o), s);
  530. case 'number':
  531. return setIndex(o, xi2x(getIndex(o, s), o), s);
  532. case 'object':
  533. return modifyComposed(o, xi2x, s);
  534. default:
  535. return o[LENGTH] === 4 ? o(s, void 0, I.Identity, xi2x) : (xi2x(o(s, void 0), void 0), s);
  536. }
  537. });
  538. var modifyAsyncU = function modifyAsyncU(o, f, s) {
  539. return I.resolve(toFunction(o)(s, void 0, I.IdentityAsync, f));
  540. };
  541. var getAsU = /*#__PURE__*/(par(1, ef(reqOptic)))(function getAs(xi2y, l, s) {
  542. switch (typeof l) {
  543. case 'string':
  544. return xi2y(getProp(l, s), l);
  545. case 'number':
  546. return xi2y(getIndex(l, s), l);
  547. case 'object':
  548. {
  549. var n = l[LENGTH];
  550. for (var i = 0, o; i < n; ++i) {
  551. switch (typeof (o = l[i])) {
  552. case 'string':
  553. s = getProp(o, s);
  554. break;
  555. case 'number':
  556. s = getIndex(o, s);
  557. break;
  558. default:
  559. return composed(i, l)(s, l[i - 1], Select, xi2y);
  560. }
  561. }return xi2y(s, l[n - 1]);
  562. }
  563. default:
  564. return xi2y !== id && l[LENGTH] !== 4 ? xi2y(l(s, void 0), void 0) : l(s, void 0, Select, xi2y);
  565. }
  566. });
  567. var getU = function getU(l, s) {
  568. return getAsU(id, l, s);
  569. };
  570. function modifyComposed(os, xi2y, x, y) {
  571. var n = os[LENGTH];
  572. var xs = Array(n);
  573. for (var i = 0, o; i < n; ++i) {
  574. xs[i] = x;
  575. switch (typeof (o = os[i])) {
  576. case 'string':
  577. x = getProp(o, x);
  578. break;
  579. case 'number':
  580. x = getIndex(o, x);
  581. break;
  582. default:
  583. x = composed(i, os)(x, os[i - 1], I.Identity, xi2y || I.always(y));
  584. n = i;
  585. break;
  586. }
  587. }
  588. if (n === os[LENGTH]) x = xi2y ? xi2y(x, os[n - 1]) : y;
  589. for (var _o; 0 <= --n;) {
  590. x = I.isString(_o = os[n]) ? setProp(_o, x, xs[n]) : setIndex(_o, x, xs[n]);
  591. }return x;
  592. }
  593. //
  594. var lensU = function lens(get, set) {
  595. return copyName(function (x, i, F, xi2yF) {
  596. return F.map(function (y) {
  597. return set(y, x, i);
  598. }, xi2yF(get(x, i), i));
  599. }, get);
  600. };
  601. var isoU = function iso(bwd, fwd) {
  602. return copyName(function (x, i, F, xi2yF) {
  603. return F.map(fwd, xi2yF(bwd(x), i));
  604. }, bwd);
  605. };
  606. var stringIsoU = function stringIsoU(bwd, fwd) {
  607. return isoU(expect(I.isString, bwd), expect(I.isString, fwd));
  608. };
  609. var numberIsoU = function numberIsoU(bwd, fwd) {
  610. return isoU(expect(I.isNumber, bwd), expect(I.isNumber, fwd));
  611. };
  612. //
  613. var getPick = /*#__PURE__*/(res(I.freeze))(function (template, x) {
  614. var r = void 0;
  615. for (var k in template) {
  616. var t = template[k];
  617. var v = I.isObject(t) ? getPick(t, x) : getAsU(id, t, x);
  618. if (void 0 !== v) {
  619. if (!r) r = {};
  620. r[k] = v;
  621. }
  622. }
  623. return r;
  624. });
  625. var reqTemplate = function reqTemplate(name) {
  626. return function (template) {
  627. if (!I.isObject(template)) errorGiven('`' + name + '` expects a plain Object template', template);
  628. };
  629. };
  630. var reqObject = function reqObject(msg) {
  631. return function (value) {
  632. if (!(void 0 === value || value instanceof Object)) errorGiven(msg, value);
  633. };
  634. };
  635. var setPick = /*#__PURE__*/(par(1, ef(reqObject('`pick` must be set with undefined or an object'))))(function (template, value, x) {
  636. for (var k in template) {
  637. var v = value && value[k];
  638. var t = template[k];
  639. x = I.isObject(t) ? setPick(t, v, x) : setU(t, v, x);
  640. }
  641. return x;
  642. });
  643. //
  644. var toObject = function toObject(x) {
  645. return I.constructorOf(x) !== Object ? I.toObject(x) : x;
  646. };
  647. //
  648. var identity = function identity(x, i, _F, xi2yF) {
  649. return xi2yF(x, i);
  650. };
  651. //
  652. var branchAssemble = /*#__PURE__*/(res(res(I.freeze)))(function (ks) {
  653. return function (xs) {
  654. var r = {};
  655. var i = ks[LENGTH];
  656. while (i--) {
  657. var v = xs[0];
  658. if (void 0 !== v) {
  659. r[ks[i]] = v;
  660. }
  661. xs = xs[1];
  662. }
  663. return r;
  664. };
  665. });
  666. var branchOr1LevelIdentity = /*#__PURE__*/(function (fn$$1) {
  667. return function (otherwise, k2o, xO, x, A, xi2yA) {
  668. var y = fn$$1(otherwise, k2o, xO, x, A, xi2yA);
  669. if (x !== y) I.freeze(y);
  670. return y;
  671. };
  672. })(function (otherwise, k2o, xO, x, A, xi2yA) {
  673. var written = void 0;
  674. var same = true;
  675. var r = {};
  676. for (var k in k2o) {
  677. written = 1;
  678. var _x2 = xO[k];
  679. var y = k2o[k](_x2, k, A, xi2yA);
  680. if (void 0 !== y) {
  681. r[k] = y;
  682. if (same) same = _x2 === y && (_x2 !== 0 || 1 / _x2 === 1 / y) || _x2 !== _x2 && y !== y;
  683. } else {
  684. same = false;
  685. }
  686. }
  687. var t = written;
  688. for (var _k in xO) {
  689. if (void 0 === (t && k2o[_k])) {
  690. written = 1;
  691. var _x3 = xO[_k];
  692. var _y = otherwise(_x3, _k, A, xi2yA);
  693. if (void 0 !== _y) {
  694. r[_k] = _y;
  695. if (same) same = _x3 === _y && (_x3 !== 0 || 1 / _x3 === 1 / _y) || _x3 !== _x3 && _y !== _y;
  696. } else {
  697. same = false;
  698. }
  699. }
  700. }
  701. return written ? same && xO === x ? x : r : x;
  702. });
  703. var branchOr1Level = function branchOr1Level(otherwise, k2o) {
  704. return function (x, _i, A, xi2yA) {
  705. var xO = x instanceof Object ? toObject(x) : I.object0;
  706. if (I.Identity === A) {
  707. return branchOr1LevelIdentity(otherwise, k2o, xO, x, A, xi2yA);
  708. } else if (Select === A) {
  709. for (var k in k2o) {
  710. var y = k2o[k](xO[k], k, A, xi2yA);
  711. if (void 0 !== y) return y;
  712. }
  713. for (var _k2 in xO) {
  714. if (void 0 === k2o[_k2]) {
  715. var _y2 = otherwise(xO[_k2], _k2, A, xi2yA);
  716. if (void 0 !== _y2) return _y2;
  717. }
  718. }
  719. } else {
  720. var map = A.map,
  721. ap = A.ap,
  722. of = A.of;
  723. var xsA = of(cpair);
  724. var ks = [];
  725. for (var _k3 in k2o) {
  726. ks.push(_k3);
  727. xsA = ap(map(cpair, xsA), k2o[_k3](xO[_k3], _k3, A, xi2yA));
  728. }
  729. var t = ks[LENGTH] ? true : void 0;
  730. for (var _k4 in xO) {
  731. if (void 0 === (t && k2o[_k4])) {
  732. ks.push(_k4);
  733. xsA = ap(map(cpair, xsA), otherwise(xO[_k4], _k4, A, xi2yA));
  734. }
  735. }
  736. return ks[LENGTH] ? map(branchAssemble(ks), xsA) : of(x);
  737. }
  738. };
  739. };
  740. function branchOrU(otherwise, template) {
  741. var k2o = I.create(null);
  742. for (var k in template) {
  743. var v = template[k];
  744. k2o[k] = I.isObject(v) ? branchOrU(otherwise, v) : toFunction(v);
  745. }
  746. return branchOr1Level(otherwise, k2o);
  747. }
  748. var replaced = function replaced(inn, out, x) {
  749. return I.acyclicEqualsU(x, inn) ? out : x;
  750. };
  751. function findIndexHint(hint, xi2b, xs) {
  752. var u = hint.hint;
  753. var n = xs[LENGTH];
  754. if (n <= u) u = n - 1;
  755. if (u < 0) u = 0;
  756. var d = u - 1;
  757. for (; 0 <= d && u < n; ++u, --d) {
  758. if (xi2b(xs[u], u, hint)) return u;
  759. if (xi2b(xs[d], d, hint)) return d;
  760. }
  761. for (; u < n; ++u) {
  762. if (xi2b(xs[u], u, hint)) return u;
  763. }for (; 0 <= d; --d) {
  764. if (xi2b(xs[d], d, hint)) return d;
  765. }return n;
  766. }
  767. var partitionIntoIndex = /*#__PURE__*/(dep(function (_xi2b, _xs, ts, fs) {
  768. return res(ef(function () {
  769. I.freeze(ts);
  770. I.freeze(fs);
  771. }));
  772. }))(function (xi2b, xs, ts, fs) {
  773. for (var i = 0, n = xs[LENGTH], x; i < n; ++i) {
  774. (xi2b(x = xs[i], i) ? ts : fs).push(x);
  775. }
  776. });
  777. var fromReader = function fromReader(wi2x) {
  778. return copyName(function (w, i, F, xi2yF) {
  779. return F.map(I.always(w), xi2yF(wi2x(w, i), i));
  780. }, wi2x);
  781. };
  782. //
  783. var LAST_INDEX = 'lastIndex';
  784. var INDEX = 'index';
  785. var RE_VALUE = 0;
  786. var reLastIndex = function reLastIndex(m) {
  787. return m[INDEX] + m[0][LENGTH];
  788. };
  789. var reNext = /*#__PURE__*/(function (fn$$1) {
  790. return function (m, re) {
  791. var res$$1 = fn$$1(m, re);
  792. if ('' === res$$1) warn(reNext, '`matches(' + re + ')` traversal terminated due to empty match. `matches` traversal shouldn\'t be used with regular expressions that can produce empty matches.');
  793. return res$$1;
  794. };
  795. })(function (m, re) {
  796. var lastIndex = re[LAST_INDEX];
  797. re[LAST_INDEX] = reLastIndex(m);
  798. var n = re.exec(m.input);
  799. re[LAST_INDEX] = lastIndex;
  800. return n && n[0] && n;
  801. });
  802. //
  803. var iterCollect = function iterCollect(s) {
  804. return function (xs) {
  805. return function (x) {
  806. return [s, x, xs];
  807. };
  808. };
  809. };
  810. var iterToArray = function iterToArray(xs) {
  811. var ys = [];
  812. while (iterCollect !== xs) {
  813. ys.push(xs[0], xs[1]);
  814. xs = xs[2];
  815. }
  816. return ys;
  817. };
  818. function iterSelect(xi2y, t, s) {
  819. while (s = reNext(s, t)) {
  820. var y = xi2y(s[RE_VALUE], s[INDEX]);
  821. if (void 0 !== y) return y;
  822. }
  823. }
  824. function iterEager(map, ap, of, xi2yA, t, s) {
  825. var r = of(iterCollect);
  826. while (s = reNext(s, t)) {
  827. r = ap(ap(map(iterCollect, of(s)), r), xi2yA(s[RE_VALUE], s[INDEX]));
  828. }return r;
  829. }
  830. //
  831. var keyed = /*#__PURE__*/isoU( /*#__PURE__*/expect( /*#__PURE__*/isInstanceOf(Object), /*#__PURE__*/(res(freezeObjectOfObjects))(function keyed(x) {
  832. x = toObject(x);
  833. var es = [];
  834. for (var key in x) {
  835. es.push([key, x[key]]);
  836. }return es;
  837. })), /*#__PURE__*/expect(I.isArray, /*#__PURE__*/(res(I.freeze))(function (es) {
  838. var o = {};
  839. for (var i = 0, n = es[LENGTH]; i < n; ++i) {
  840. var entry = es[i];
  841. if (entry[LENGTH] === 2) o[entry[0]] = entry[1];
  842. }
  843. return o;
  844. })));
  845. //
  846. var matchesJoin = function matchesJoin(input) {
  847. return function (matchesIn) {
  848. var result = '';
  849. var lastIndex = 0;
  850. var matches = iterToArray(matchesIn);
  851. var n = matches[LENGTH];
  852. for (var j = n - 2; j !== -2; j += -2) {
  853. var m = matches[j];
  854. result += input.slice(lastIndex, m[INDEX]);
  855. var s = matches[j + 1];
  856. if (void 0 !== s) result += s;
  857. lastIndex = reLastIndex(m);
  858. }
  859. result += input.slice(lastIndex);
  860. return result;
  861. };
  862. };
  863. //
  864. var disjointBwd = /*#__PURE__*/(res(freezeObjectOfObjects))(function (groupOf, x) {
  865. if (x instanceof Object) {
  866. var y = {};
  867. x = toObject(x);
  868. for (var key in x) {
  869. var group = groupOf(key);
  870. var g = y[group];
  871. if (undefined === g) y[group] = g = {};
  872. g[key] = x[key];
  873. }
  874. return y;
  875. }
  876. });
  877. var disjointFwd = /*#__PURE__*/(res(res(I.freeze)))(function (groupOf) {
  878. return function (y) {
  879. if (y instanceof Object) {
  880. var x = {};
  881. y = toObject(y);
  882. for (var group in y) {
  883. var g = y[group];
  884. if (g instanceof Object) {
  885. g = toObject(g);
  886. for (var key in g) {
  887. if (groupOf(key) === group) {
  888. x[key] = g[key];
  889. }
  890. }
  891. }
  892. }
  893. return x;
  894. }
  895. };
  896. });
  897. //
  898. var subseqU = function subseq(begin, end, t) {
  899. t = toFunction(t);
  900. return copyName(function (x, i, F, xi2yF) {
  901. var n = -1;
  902. return t(x, i, F, function (x, i) {
  903. return begin <= ++n && !(end <= n) ? xi2yF(x, i) : F.of(x);
  904. });
  905. }, t);
  906. };
  907. //
  908. var attemptU = function attemptU(fn$$1, x) {
  909. if (void 0 !== x) {
  910. var y = fn$$1(x);
  911. if (void 0 !== y) return y;
  912. }
  913. return x;
  914. };
  915. var rewriteAttempt = function rewriteAttempt(fn$$1) {
  916. return function (x, i, F, xi2yF) {
  917. return F.map(function (x) {
  918. return attemptU(fn$$1, x);
  919. }, xi2yF(x, i));
  920. };
  921. };
  922. var rereadAttempt = function rereadAttempt(fn$$1) {
  923. return function (x, i, F, xi2yF) {
  924. return xi2yF(attemptU(fn$$1, x), i);
  925. };
  926. };
  927. //
  928. var transformEvery = function transformEvery(optic) {
  929. return transform(lazy(function (rec) {
  930. return [optic, children, rec];
  931. }));
  932. };
  933. var transformSome = function transformSome(fn$$1) {
  934. return transform(lazy(function (rec) {
  935. return choices(getter(fn$$1), [children, rec]);
  936. }));
  937. };
  938. //
  939. var isDefinedAtU = function isDefinedAtU(o, x, i) {
  940. return void 0 !== o(x, i, Select, id);
  941. };
  942. var isDefinedAt = function isDefinedAt(o) {
  943. return function (x, i) {
  944. return isDefinedAtU(o, x, i);
  945. };
  946. };
  947. var eitherU = function eitherU(t, e) {
  948. return function either(c) {
  949. return function either(x, i, C, xi2yC) {
  950. return (c(x, i) ? t : e)(x, i, C, xi2yC);
  951. };
  952. };
  953. };
  954. var orElseU = function orElse(back, prim) {
  955. prim = toFunction(prim);
  956. back = toFunction(back);
  957. return function orElse(x, i, C, xi2yC) {
  958. return (isDefinedAtU(prim, x, i) ? prim : back)(x, i, C, xi2yC);
  959. };
  960. };
  961. var orAlternativelyU = function orAlternatively(back, prim) {
  962. prim = toFunction(prim);
  963. back = toFunction(back);
  964. var fwd = function fwd(y) {
  965. y = I.always(y);
  966. var yP = prim(void 0, void 0, I.Identity, y);
  967. return void 0 === yP ? back(void 0, void 0, I.Identity, y) : yP;
  968. };
  969. return function orAlternatively(x, i, F, xi2yF) {
  970. var xP = prim(x, i, Select, id);
  971. return F.map(fwd, xi2yF(void 0 === xP ? back(x, i, Select, id) : xP, i));
  972. };
  973. };
  974. var makeSemi = function makeSemi(op) {
  975. return copyName(function (_) {
  976. var n = arguments[LENGTH];
  977. var r = arguments[--n];
  978. while (n) {
  979. r = op(r, arguments[--n]);
  980. }
  981. return r;
  982. }, op);
  983. };
  984. var zero = function zero(x, _i, C, _xi2yC) {
  985. return C.of(x);
  986. };
  987. //
  988. var elemsI = function elemsI(xs, _i, A, xi2yA) {
  989. return A === I.Identity ? mapPartialIndexU(xi2yA, xs, void 0) : A === Select ? selectInArrayLike(xi2yA, xs) : traversePartialIndex(A, xi2yA, xs, void 0);
  990. };
  991. //
  992. var seq2U = function seq2U(l, r) {
  993. return function (x, i, M, xi2yM) {
  994. return M.chain(function (x) {
  995. return r(x, i, M, xi2yM);
  996. }, l(x, i, M, xi2yM));
  997. };
  998. };
  999. //
  1000. var pickInAux = function pickInAux(t, k) {
  1001. return [k, pickIn(t)];
  1002. };
  1003. //
  1004. var iteratePartial = function iteratePartial(aa) {
  1005. return function iterate(a) {
  1006. var r = a;
  1007. while (a !== undefined) {
  1008. r = a;
  1009. a = aa(a);
  1010. }
  1011. return r;
  1012. };
  1013. };
  1014. //
  1015. var crossPartial = function crossPartial(op, ls, or$$1) {
  1016. return function (xs, ss) {
  1017. var n = ls[LENGTH];
  1018. if (!seemsArrayLike(xs)) return;
  1019. if (!seemsArrayLike(ss)) ss = '';
  1020. var m = Math.max(n, xs[LENGTH], ss[LENGTH]);
  1021. var ys = Array(m);
  1022. for (var i = 0; i < m; ++i) {
  1023. if (void 0 === (ys[i] = op(i < n ? ls[i] : or$$1, xs[i], ss[i]))) return;
  1024. }return ys;
  1025. };
  1026. };
  1027. var crossOr = /*#__PURE__*/(function (fn$$1) {
  1028. return I.curry(function crossOr(or$$1, ls) {
  1029. return toFunction([isoU(id, I.freeze), fn$$1(or$$1, ls), isoU(I.freeze, id)]);
  1030. });
  1031. })(function crossOr(or$$1, ls) {
  1032. return lensU(crossPartial(getU, ls, or$$1), crossPartial(setU, ls, or$$1));
  1033. });
  1034. var subsetPartial = function subsetPartial(p) {
  1035. return function subset(x) {
  1036. return void 0 !== x && p(x) ? x : void 0;
  1037. };
  1038. };
  1039. //
  1040. var unfoldPartial = /*#__PURE__*/(res(res(function (r) {
  1041. I.freeze(r);
  1042. I.freeze(r[1]);
  1043. return r;
  1044. })))(function (s2sa) {
  1045. return function unfold(s) {
  1046. var xs = [];
  1047. for (;;) {
  1048. var sa = s2sa(s);
  1049. if (!isPair(sa)) return [s, xs];
  1050. s = sa[0];
  1051. xs.push(sa[1]);
  1052. }
  1053. };
  1054. });
  1055. var foldPartial = function foldPartial(sa2s) {
  1056. return function (sxs) {
  1057. if (isPair(sxs)) {
  1058. var xs = sxs[1];
  1059. if (I.isArray(xs)) {
  1060. var s = sxs[0];
  1061. var n = xs[LENGTH];
  1062. while (n--) {
  1063. s = sa2s(freezeInDev([s, xs[n]]));
  1064. }return s;
  1065. }
  1066. }
  1067. };
  1068. };
  1069. //
  1070. var PAYLOAD = '珳襱댎纚䤤鬖罺좴';
  1071. var isPayload = function isPayload(k) {
  1072. return I.isString(k) && k.indexOf(PAYLOAD) === 0;
  1073. };
  1074. function Spread(i) {
  1075. this[PAYLOAD] = i;
  1076. I.freeze(this);
  1077. }
  1078. var isSpread = /*#__PURE__*/isInstanceOf(Spread);
  1079. var Variable = /*#__PURE__*/I.inherit(function Variable(i) {
  1080. this[PAYLOAD + i] = this[PAYLOAD] = I.freeze([new Spread(i)]);
  1081. I.freeze(this);
  1082. }, Object, /*#__PURE__*/I.assocPartialU(iterator, function () {
  1083. return this[PAYLOAD][iterator]();
  1084. }));
  1085. var isVariable = /*#__PURE__*/isInstanceOf(Variable);
  1086. var vars = [];
  1087. function nVars(n) {
  1088. while (vars[LENGTH] < n) {
  1089. vars.push(new Variable(vars[LENGTH]));
  1090. }return vars;
  1091. }
  1092. var isPrimitive = function isPrimitive(x) {
  1093. return x == null || typeof x !== 'object';
  1094. };
  1095. function match1(kinds, i, e, x) {
  1096. if (void 0 !== x) {
  1097. if (i in e) return I.acyclicEqualsU(e[i], x);
  1098. e[i] = x;
  1099. var k = kinds[i];
  1100. return !k || k(x);
  1101. }
  1102. }
  1103. function checkKind(kinds, i, kind) {
  1104. if (0 <= i) {
  1105. if (kinds[i]) {
  1106. if (kinds[i] !== kind) throw Error('Spread patterns must be used consistently either as arrays or as objects.');
  1107. } else {
  1108. kinds[i] = kind;
  1109. }
  1110. }
  1111. }
  1112. var arrayKind = function arrayKind(x) {
  1113. return void 0 === x || I.isArray(x);
  1114. };
  1115. var objectKind = function objectKind(x) {
  1116. return void 0 === x || isInstanceOf(Object);
  1117. };
  1118. function checkPattern(kinds, p) {
  1119. if (isSpread(p)) {
  1120. throw Error('Spread patterns must be inside objects or arrays.');
  1121. } else if (I.isArray(p)) {
  1122. var nSpread = 0;
  1123. for (var i = 0, n = p[LENGTH]; i < n; ++i) {
  1124. var pi = p[i];
  1125. if (isSpread(pi)) {
  1126. if (nSpread++) throw Error('At most one spread is allowed in an array or object.');
  1127. checkKind(kinds, pi[PAYLOAD], arrayKind);
  1128. } else {
  1129. checkPattern(kinds, pi);
  1130. }
  1131. }
  1132. } else if (I.isObject(p)) {
  1133. var spread = p[PAYLOAD];
  1134. if (spread) {
  1135. spread = spread[0][PAYLOAD];
  1136. checkKind(kinds, spread, objectKind);
  1137. }
  1138. var _n = 0;
  1139. for (var k in p) {
  1140. if (isPayload(k)) {
  1141. if (2 < ++_n) throw Error('At most one spread is allowed in an array or object.');
  1142. } else {
  1143. checkPattern(kinds, p[k]);
  1144. }
  1145. }
  1146. } else if (!isPrimitive(p) && !isVariable(p)) {
  1147. throw Error('Only plain arrays and objects are allowed in patterns.');
  1148. }
  1149. }
  1150. var checkPatternInDev = function (p) {
  1151. var kinds = [];
  1152. checkPattern(kinds, p);
  1153. return deepFreezeInDev(p);
  1154. };
  1155. var checkPatternPairInDev = function (ps) {
  1156. var kinds = [];
  1157. checkPattern(kinds, ps[0]);
  1158. checkPattern(kinds, ps[1]);
  1159. return deepFreezeInDev(ps);
  1160. };
  1161. var setDefined = function setDefined(o, k, x) {
  1162. if (void 0 !== x) o[k] = x;
  1163. };
  1164. var pushDefined = function pushDefined(xs, x) {
  1165. if (void 0 !== x) xs.push(x);
  1166. };
  1167. function toMatch(kinds, p) {
  1168. if (void 0 === p || all1(isPrimitive, leafs, p)) {
  1169. return function (e, x) {
  1170. return I.acyclicEqualsU(p, x);
  1171. };
  1172. } else if (isVariable(p)) {
  1173. var i = p[PAYLOAD][0][PAYLOAD];
  1174. return i < 0 ? id : function (e, x) {
  1175. return match1(kinds, i, e, x);
  1176. };
  1177. } else if (I.isArray(p)) {
  1178. var init = [];
  1179. var rest = [];
  1180. var spread = void 0;
  1181. var n = p[LENGTH];
  1182. for (var _i3 = 0; _i3 < n; ++_i3) {
  1183. var x = p[_i3];
  1184. if (isSpread(x)) {
  1185. spread = x[PAYLOAD];
  1186. kinds[spread] = arrayKind;
  1187. } else {
  1188. var side = void 0 !== spread ? rest : init;
  1189. side.push(toMatch(kinds, x));
  1190. }
  1191. }
  1192. return function (e, x) {
  1193. if (!seemsArrayLike(x)) return;
  1194. var l = x[LENGTH];
  1195. if (void 0 !== spread ? l < n - 1 : l !== n) return;
  1196. var j = init[LENGTH];
  1197. for (var _i4 = 0; _i4 < j; ++_i4) {
  1198. if (!init[_i4](e, x[_i4])) return;
  1199. }var k = rest[LENGTH];
  1200. l -= k;
  1201. for (var _i5 = 0; _i5 < k; ++_i5) {
  1202. if (!rest[_i5](e, x[l + _i5])) return;
  1203. }return !(0 <= spread) || match1(kinds, spread, e, copyToFrom(Array(l - j), 0, x, j, l));
  1204. };
  1205. } else {
  1206. var _spread = p[PAYLOAD];
  1207. if (_spread) {
  1208. _spread = _spread[0][PAYLOAD];
  1209. kinds[_spread] = objectKind;
  1210. }
  1211. p = modify(values, function (p, k) {
  1212. return isPayload(k) ? void 0 : toMatch(kinds, p);
  1213. }, p);
  1214. var _n2 = count(values, p);
  1215. return function (e, x) {
  1216. if (isPrimitive(x) || I.isArray(x)) return;
  1217. x = toObject(x);
  1218. var rest = 0 <= _spread && {};
  1219. var i = 0;
  1220. for (var k in x) {
  1221. var m = p[k];
  1222. if (m) {
  1223. if (!m(e, x[k])) return;
  1224. i++;
  1225. } else if (void 0 !== _spread) {
  1226. if (rest) rest[k] = x[k];
  1227. } else {
  1228. return;
  1229. }
  1230. }
  1231. return i === _n2 && (!rest || match1(kinds, _spread, e, freezeInDev(rest)));
  1232. };
  1233. }
  1234. }
  1235. function toSubst(p, k) {
  1236. if (isPayload(k)) {
  1237. return void 0;
  1238. } else if (void 0 === p || all1(isPrimitive, leafs, p)) {
  1239. return I.always(p);
  1240. } else if (isVariable(p)) {
  1241. var i = p[PAYLOAD][0][PAYLOAD];
  1242. return function (e) {
  1243. return e[i];
  1244. };
  1245. } else if (I.isArray(p)) {
  1246. var init = [];
  1247. var rest = [];
  1248. var spread = void 0;
  1249. var n = p[LENGTH];
  1250. for (var _i6 = 0; _i6 < n; ++_i6) {
  1251. var x = p[_i6];
  1252. if (isSpread(x)) {
  1253. spread = x[PAYLOAD];
  1254. } else {
  1255. var side = void 0 !== spread ? rest : init;
  1256. side.push(toSubst(x));
  1257. }
  1258. }
  1259. return freezeResultInDev(function (e) {
  1260. var r = [];
  1261. for (var _i7 = 0, _n3 = init[LENGTH]; _i7 < _n3; ++_i7) {
  1262. pushDefined(r, init[_i7](e));
  1263. }if (0 <= spread) {
  1264. var xs = e[spread];
  1265. if (xs) for (var _i8 = 0, _n4 = xs[LENGTH]; _i8 < _n4; ++_i8) {
  1266. pushDefined(r, xs[_i8]);
  1267. }
  1268. }
  1269. for (var _i9 = 0, _n5 = rest[LENGTH]; _i9 < _n5; ++_i9) {
  1270. pushDefined(r, rest[_i9](e));
  1271. }return r;
  1272. });
  1273. } else {
  1274. var _spread2 = p[PAYLOAD];
  1275. if (_spread2) _spread2 = _spread2[0][PAYLOAD];
  1276. p = modify(values, toSubst, p);
  1277. return freezeResultInDev(function (e) {
  1278. var r = {};
  1279. for (var _k5 in p) {
  1280. setDefined(r, _k5, p[_k5](e));
  1281. }if (0 <= _spread2) {
  1282. var _x4 = e[_spread2];
  1283. if (_x4) for (var _k6 in _x4) {
  1284. setDefined(r, _k6, _x4[_k6]);
  1285. }
  1286. }
  1287. return r;
  1288. });
  1289. }
  1290. }
  1291. var oneway = function oneway(n, m, s) {
  1292. return function (x) {
  1293. var e = Array(n);
  1294. if (m(e, x)) return s(e);
  1295. };
  1296. };
  1297. //
  1298. var ungroupByFn = /*#__PURE__*/(res(res(I.freeze)))(function (keyOf) {
  1299. return function ungroupBy(xxs) {
  1300. if (I.isArray(xxs)) {
  1301. var ys = [];
  1302. for (var i = 0, n = xxs.length; i < n; ++i) {
  1303. var xs = xxs[i];
  1304. if (!I.isArray(xs)) return;
  1305. var m = xs.length;
  1306. if (!m) return;
  1307. var k = keyOf(xs[0]);
  1308. if (void 0 === k) return;
  1309. for (var j = 0, _m = xs.length; j < _m; ++j) {
  1310. var x = xs[j];
  1311. if (!I.identicalU(k, keyOf(x))) return;
  1312. ys.push(x);
  1313. }
  1314. }
  1315. return ys;
  1316. }
  1317. };
  1318. });
  1319. var groupByFn = /*#__PURE__*/(res(res(freezeObjectOfObjects)))(function (keyOf) {
  1320. return function groupBy(ys) {
  1321. if (I.isArray(ys)) {
  1322. var groups = new Map();
  1323. for (var i = 0, n = ys.length; i < n; ++i) {
  1324. var y = ys[i];
  1325. var k = keyOf(y);
  1326. if (void 0 === k) return;
  1327. var xs = groups.get(k);
  1328. if (void 0 !== xs) {
  1329. xs.push(y);
  1330. } else {
  1331. groups.set(k, [y]);
  1332. }
  1333. }
  1334. var xxs = [];
  1335. groups.forEach(function (xs) {
  1336. return xxs.push(xs);
  1337. });
  1338. return xxs;
  1339. }
  1340. };
  1341. });
  1342. //
  1343. var zW1Fn = /*#__PURE__*/(res(res(I.freeze)))(function (fn$$1) {
  1344. return function zipWith1(xys) {
  1345. if (isPair(xys)) {
  1346. var ys = xys[1];
  1347. var n = ys[LENGTH];
  1348. if (n) {
  1349. var x = xys[0];
  1350. var zs = Array(n);
  1351. for (var i = 0; i < n; ++i) {
  1352. if (void 0 === (zs[i] = fn$$1([x, ys[i]]))) return;
  1353. }return zs;
  1354. }
  1355. }
  1356. };
  1357. });
  1358. var unzW1Fn = /*#__PURE__*/(res(res(freezeObjectOfObjects)))(function (fn$$1) {
  1359. return function unzipWith1(zs) {
  1360. if (I.isArray(zs)) {
  1361. var n = zs[LENGTH];
  1362. if (n) {
  1363. var xy0 = fn$$1(zs[0]);
  1364. if (isPair(xy0)) {
  1365. var ys = Array(n);
  1366. var x = xy0[0];
  1367. ys[0] = xy0[1];
  1368. for (var i = 1; i < n; ++i) {
  1369. var xy = fn$$1(zs[i]);
  1370. if (!isPair(xy) || !I.acyclicEqualsU(x, xy[0])) return;
  1371. ys[i] = xy[1];
  1372. }
  1373. return [x, ys];
  1374. }
  1375. }
  1376. }
  1377. };
  1378. });
  1379. // Auxiliary
  1380. var seemsArrayLike = function seemsArrayLike(x) {
  1381. return x instanceof Object && (x = x[LENGTH], x === x >> 0 && 0 <= x) || I.isString(x);
  1382. };
  1383. var Select = /*#__PURE__*/ConstantWith(function (l, r) {
  1384. return void 0 !== l ? l : r;
  1385. });
  1386. var toFunction = /*#__PURE__*/(par(0, ef(reqOptic)))(function toFunction(o) {
  1387. switch (typeof o) {
  1388. case 'string':
  1389. return funProp(o);
  1390. case 'number':
  1391. return funIndex(o);
  1392. case 'object':
  1393. return composed(0, o);
  1394. default:
  1395. return o[LENGTH] === 4 ? o : fromReader(o);
  1396. }
  1397. });
  1398. // Operations on optics
  1399. var assign = /*#__PURE__*/I.curry(function assign(o, x, s) {
  1400. return setU([o, assignTo], x, s);
  1401. });
  1402. var disperse = /*#__PURE__*/I.curry(disperseU);
  1403. var modify = /*#__PURE__*/I.curry(modifyU);
  1404. var modifyAsync = /*#__PURE__*/I.curry(modifyAsyncU);
  1405. var remove = /*#__PURE__*/I.curry(function remove(o, s) {
  1406. return setU(o, void 0, s);
  1407. });
  1408. var set = /*#__PURE__*/I.curry(setU);
  1409. var traverse = /*#__PURE__*/I.curry(traverseU);
  1410. // Nesting
  1411. function compose() {
  1412. var n = arguments[LENGTH];
  1413. if (n < 2) {
  1414. return n ? arguments[0] : identity;
  1415. } else {
  1416. var os = Array(n);
  1417. while (n--) {
  1418. os[n] = arguments[n];
  1419. }return os;
  1420. }
  1421. }
  1422. function flat() {
  1423. var r = [flatten];
  1424. for (var i = 0, n = arguments[LENGTH]; i < n; ++i) {
  1425. r.push(arguments[i], flatten);
  1426. }return r;
  1427. }
  1428. // Recursing
  1429. function lazy(o2o) {
  1430. var _memo = function memo(x, i, C, xi2yC) {
  1431. return (_memo = toFunction(o2o(rec)))(x, i, C, xi2yC);
  1432. };
  1433. function rec(x, i, C, xi2yC) {
  1434. return _memo(x, i, C, xi2yC);
  1435. }
  1436. return rec;
  1437. }
  1438. // Adapting
  1439. var choices = /*#__PURE__*/makeSemi(orElseU);
  1440. var choose = function choose(xiM2o) {
  1441. return copyName(function (x, i, C, xi2yC) {
  1442. return toFunction(xiM2o(x, i))(x, i, C, xi2yC);
  1443. }, xiM2o);
  1444. };
  1445. var cond = /*#__PURE__*/(function (fn$$1) {
  1446. return function cond() {
  1447. var pair = tup(ef(reqFn), ef(reqOptic));
  1448. for (var _len = arguments.length, cs = Array(_len), _key = 0; _key < _len; _key++) {
  1449. cs[_key] = arguments[_key];
  1450. }
  1451. arr(pair)(cs.slice(0, -1));
  1452. arr(or(tup(ef(reqOptic)), pair))(cs.slice(-1));
  1453. return fn$$1.apply(undefined, cs);
  1454. };
  1455. })(function cond() {
  1456. var n = arguments[LENGTH];
  1457. var r = zero;
  1458. while (n--) {
  1459. var c = arguments[n];
  1460. r = c[LENGTH] < 2 ? toFunction(c[0]) : eitherU(toFunction(c[1]), r)(c[0]);
  1461. }
  1462. return r;
  1463. });
  1464. var condOf = /*#__PURE__*/(function (fn$$1) {
  1465. return function condOf(of) {
  1466. var pair = tup(ef(reqFn), ef(reqOptic));
  1467. for (var _len2 = arguments.length, cs = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  1468. cs[_key2 - 1] = arguments[_key2];
  1469. }
  1470. arr(pair)(cs.slice(0, -1));
  1471. arr(or(tup(ef(reqOptic)), pair))(cs.slice(-1));
  1472. return fn$$1.apply(undefined, [of].concat(cs));
  1473. };
  1474. })(function condOf(of) {
  1475. of = toFunction(of);
  1476. var n = arguments[LENGTH] - 1;
  1477. if (!n) return zero;
  1478. var def = arguments[n];
  1479. if (def[LENGTH] === 1) {
  1480. --n;
  1481. def = toFunction(def[0]);
  1482. } else {
  1483. def = zero;
  1484. }
  1485. var ps = Array(n);
  1486. var os = Array(n + 1);
  1487. for (var i = 0; i < n; ++i) {
  1488. var c = arguments[i + 1];
  1489. ps[i] = c[0];
  1490. os[i] = toFunction(c[1]);
  1491. }
  1492. os[n] = def;
  1493. return function condOf(x, i, F, xi2yF) {
  1494. var min = n;
  1495. of(x, i, Select, function (y, j) {
  1496. for (var _i10 = 0; _i10 < min; ++_i10) {
  1497. if (ps[_i10](y, j)) {
  1498. min = _i10;
  1499. if (_i10 === 0) return 0;else break;
  1500. }
  1501. }
  1502. });
  1503. return os[min](x, i, F, xi2yF);
  1504. };
  1505. });
  1506. var ifElse = /*#__PURE__*/I.curry(function ifElse(c, t, e) {
  1507. return eitherU(toFunction(t), toFunction(e))(c);
  1508. });
  1509. var orElse = /*#__PURE__*/I.curry(orElseU);
  1510. // Querying
  1511. var chain = /*#__PURE__*/I.curry(function chain(xi2yO, xO) {
  1512. return [xO, choose(function (xM, i) {
  1513. return void 0 !== xM ? xi2yO(xM, i) : zero;
  1514. })];
  1515. });
  1516. var choice = function choice() {
  1517. for (var _len3 = arguments.length, os = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  1518. os[_key3] = arguments[_key3];
  1519. }
  1520. return os.reduceRight(orElseU, zero);
  1521. };
  1522. var unless = /*#__PURE__*/eitherU(zero, identity);
  1523. var when = /*#__PURE__*/eitherU(identity, zero);
  1524. var optional = /*#__PURE__*/when(I.isDefined);
  1525. // Indices
  1526. var mapIx = function mapIx(ix2j) {
  1527. return function mapIx(x, i, F, xj2yF) {
  1528. return xj2yF(x, ix2j(i, x));
  1529. };
  1530. };
  1531. var setIx = function setIx(j) {
  1532. return function setIx(x, _i, _F, xj2yF) {
  1533. return xj2yF(x, j);
  1534. };
  1535. };
  1536. var tieIx = /*#__PURE__*/I.curry(function tieIx(ij2k, o) {
  1537. o = toFunction(o);
  1538. return copyName(function (x, i, F, yk2zF) {
  1539. return o(x, i, F, function (y, j) {
  1540. return yk2zF(y, ij2k(j, i));
  1541. });
  1542. }, o);
  1543. });
  1544. var joinIx = /*#__PURE__*/setName( /*#__PURE__*/tieIx(function (j, i) {
  1545. return void 0 !== i ? void 0 !== j ? [i, j] : i : j;
  1546. }), 'joinIx');
  1547. var reIx = function reIx(o) {
  1548. o = toFunction(o);
  1549. return copyName(function (x, i, F, xi2yF) {
  1550. var j = 0;
  1551. return o(x, i, F, function (x) {
  1552. return xi2yF(x, j++);
  1553. });
  1554. }, o);
  1555. };
  1556. var skipIx = /*#__PURE__*/setName( /*#__PURE__*/tieIx(I.sndU), 'skipIx');
  1557. // Debugging
  1558. function getLog(l, s) {
  1559. var _traverseU = traverseU(SelectLog, function (x) {
  1560. return { p: [x, consExcept], x: x, c: x };
  1561. }, l, s),
  1562. p = _traverseU.p,
  1563. c = _traverseU.c;
  1564. p = pushTo(p, ['%O']);
  1565. for (var i = 2; i < p[LENGTH]; ++i) {
  1566. p[0] += ' <= %O';
  1567. }console.log.apply(console, p);
  1568. return c;
  1569. }
  1570. function log() {
  1571. var show = I.curry(function log(dir, x) {
  1572. console.log.apply(console, copyToFrom([], 0, arguments, 0, arguments[LENGTH]).concat([dir, x]));
  1573. return x;
  1574. });
  1575. return isoU(show('get'), show('set'));
  1576. }
  1577. // Operations on transforms
  1578. var transform = /*#__PURE__*/I.curry(function transform(o, s) {
  1579. return modifyU(o, id, s);
  1580. });
  1581. var transformAsync = /*#__PURE__*/I.curry(function transformAsync(o, s) {
  1582. return modifyAsyncU(o, id, s);
  1583. });
  1584. // Sequencing
  1585. var seq = /*#__PURE__*/(function (fn$$1) {
  1586. return function seq() {
  1587. return par(2, ef(reqMonad('seq')))(fn$$1.apply(undefined, arguments));
  1588. };
  1589. })(function seq() {
  1590. var n = arguments[LENGTH];
  1591. var r = zero;
  1592. if (n) {
  1593. r = toFunction(arguments[--n]);
  1594. while (n) {
  1595. r = seq2U(toFunction(arguments[--n]), r);
  1596. }
  1597. }
  1598. return r;
  1599. });
  1600. // Creating new traversals
  1601. var branchOr = /*#__PURE__*/(par(1, ef(reqTemplate('branchOr'))))( /*#__PURE__*/I.curryN(2, function branchOr(otherwise) {
  1602. otherwise = toFunction(otherwise);
  1603. return function branchOr(template) {
  1604. return branchOrU(otherwise, template);
  1605. };
  1606. }));
  1607. var branch = /*#__PURE__*/branchOr(zero);
  1608. function branches() {
  1609. var n = arguments[LENGTH];
  1610. var template = {};
  1611. for (var i = 0; i < n; ++i) {
  1612. template[arguments[i]] = identity;
  1613. }return branch(template);
  1614. }
  1615. // Traversals and combinators
  1616. function elems(xs, i, A, xi2yA) {
  1617. return seemsArrayLike(xs) ? elemsI(xs, i, A, xi2yA) : A.of(xs);
  1618. }
  1619. var elemsTotal = function elemsTotal(xs, i, A, xi2yA) {
  1620. return seemsArrayLike(xs) ? A === I.Identity ? mapPartialIndexU(xi2yA, xs, mapPartialIndexU) : A === Select ? selectInArrayLike(xi2yA, xs) : traversePartialIndex(A, xi2yA, xs, traversePartialIndex) : A.of(xs);
  1621. };
  1622. var entries = /*#__PURE__*/setName( /*#__PURE__*/toFunction([keyed, elems]), 'entries');
  1623. var keys = /*#__PURE__*/setName( /*#__PURE__*/toFunction([keyed, elems, 0]), 'keys');
  1624. var keysEverywhere = function keysEverywhere(x, i, A, xi2yA) {
  1625. var recEntry = function recEntry(kv, i) {
  1626. return A.ap(A.map(pairPartial, xi2yA(kv[0], i)), recAny(kv[1], i));
  1627. };
  1628. var recAny = function recAny(x, i) {
  1629. return I.isArray(x) ? elemsI(x, i, A, recAny) : I.isObject(x) ? entries(x, i, A, recEntry) : A.of(x);
  1630. };
  1631. return recAny(x, i);
  1632. };
  1633. var subseq = /*#__PURE__*/I.curry(subseqU);
  1634. var limit = /*#__PURE__*/subseq(0);
  1635. var offset = /*#__PURE__*/I.curry(function offset(begin, t) {
  1636. return subseqU(begin, void 0, t);
  1637. });
  1638. function matches(re) {
  1639. return function matches(x, _i, C, xi2yC) {
  1640. if (I.isString(x)) {
  1641. var map = C.map;
  1642. if (re.global) {
  1643. var m0 = [''];
  1644. m0.input = x;
  1645. m0[INDEX] = 0;
  1646. if (Select === C) {
  1647. return iterSelect(xi2yC, re, m0);
  1648. } else {
  1649. var ap = C.ap,
  1650. of = C.of;
  1651. return map(matchesJoin(x), iterEager(map, ap, of, xi2yC, re, m0));
  1652. }
  1653. } else {
  1654. var m = x.match(re);
  1655. if (m) return map(function (y) {
  1656. return x.replace(re, void 0 !== y ? y : '');
  1657. }, xi2yC(m[0], m[INDEX]));
  1658. }
  1659. }
  1660. return C.of(x);
  1661. };
  1662. }
  1663. var values = /*#__PURE__*/setName( /*#__PURE__*/branchOr1Level(identity, protoless0), 'values');
  1664. function children(x, i, C, xi2yC) {
  1665. return I.isArray(x) ? elemsI(x, i, C, xi2yC) : I.isObject(x) ? values(x, i, C, xi2yC) : C.of(x);
  1666. }
  1667. function flatten(x, i, C, xi2yC) {
  1668. var rec = function rec(x, i) {
  1669. return I.isArray(x) ? elemsI(x, i, C, rec) : void 0 !== x ? xi2yC(x, i) : C.of(x);
  1670. };
  1671. return rec(x, i);
  1672. }
  1673. function query() {
  1674. var r = [];
  1675. for (var i = 0, n = arguments[LENGTH]; i < n; ++i) {
  1676. var o = toFunction(arguments[i]);
  1677. r.push(satisfying(isDefinedAt(o)), o);
  1678. }
  1679. return r;
  1680. }
  1681. var satisfying = function satisfying(p) {
  1682. return function satisfying(x, i, C, xi2yC) {
  1683. var rec = function rec(x, i) {
  1684. return p(x, i) ? xi2yC(x, i) : children(x, i, C, rec);
  1685. };
  1686. return rec(x, i);
  1687. };
  1688. };
  1689. var leafs = /*#__PURE__*/satisfying(function (x) {
  1690. return void 0 !== x && !I.isArray(x) && !I.isObject(x);
  1691. });
  1692. var whereEq = function whereEq(template) {
  1693. return satisfying(and$1(branch(modify(leafs, is, template))));
  1694. };
  1695. // Folds over traversals
  1696. var all = /*#__PURE__*/I.curry(function all(xi2b, t, s) {
  1697. return !getAsU(function (x, i) {
  1698. if (!xi2b(x, i)) return true;
  1699. }, t, s);
  1700. });
  1701. var and$1 = /*#__PURE__*/all(id);
  1702. var all1 = /*#__PURE__*/I.curry(function all1(xi2b, t, s) {
  1703. var result = false;
  1704. getAsU(function (x, i) {
  1705. if (xi2b(x, i)) result = true;else return result = false;
  1706. }, t, s);
  1707. return result;
  1708. });
  1709. var and1 = /*#__PURE__*/all1(id);
  1710. var any = /*#__PURE__*/I.curry(function any(xi2b, t, s) {
  1711. return !!getAsU(function (x, i) {
  1712. if (xi2b(x, i)) return true;
  1713. }, t, s);
  1714. });
  1715. var collectAs = /*#__PURE__*/(res(I.freeze))(function collectAs(xi2y, t, s) {
  1716. var results = [];
  1717. getAsU(function (x, i) {
  1718. var y = xi2y(x, i);
  1719. if (void 0 !== y) results.push(y);
  1720. }, t, s);
  1721. return results;
  1722. });
  1723. var collect = /*#__PURE__*/collectAs(id);
  1724. var collectTotalAs = /*#__PURE__*/(res(I.freeze))(function collectTotalAs(xi2y, t, s) {
  1725. var results = [];
  1726. getAsU(function (x, i) {
  1727. results.push(xi2y(x, i));
  1728. }, t, s);
  1729. return results;
  1730. });
  1731. var collectTotal = /*#__PURE__*/collectTotalAs(id);
  1732. var concatAs = /*#__PURE__*/mkTraverse(id, ConstantOf);
  1733. var concat = /*#__PURE__*/concatAs(id);
  1734. var countIf = /*#__PURE__*/I.curry(function countIf(p, t, s) {
  1735. return traverseU(Sum, function (x, i) {
  1736. return p(x, i) ? 1 : 0;
  1737. }, t, s);
  1738. });
  1739. var count = /*#__PURE__*/countIf(I.isDefined);
  1740. var countsAs = /*#__PURE__*/I.curry(function countsAs(xi2k, t, s) {
  1741. var counts = new Map();
  1742. getAsU(function (x, i) {
  1743. var k = xi2k(x, i);
  1744. var n = counts.get(k);
  1745. counts.set(k, void 0 !== n ? n + 1 : 1);
  1746. }, t, s);
  1747. return counts;
  1748. });
  1749. var counts = /*#__PURE__*/countsAs(id);
  1750. var foldl = /*#__PURE__*/I.curry(function foldl(f, r, t, s) {
  1751. getAsU(function (x, i) {
  1752. r = f(r, x, i);
  1753. }, t, s);
  1754. return r;
  1755. });
  1756. var foldr = /*#__PURE__*/I.curry(function foldr(f, r, t, s) {
  1757. var is = [];
  1758. var xs = [];
  1759. getAsU(function (x, i) {
  1760. xs.push(x);
  1761. is.push(i);
  1762. }, t, s);
  1763. for (var i = xs[LENGTH] - 1; 0 <= i; --i) {
  1764. r = f(r, xs[i], is[i]);
  1765. }return r;
  1766. });
  1767. var forEach = /*#__PURE__*/I.curry(function forEach(f, t, s) {
  1768. return getAsU(function (x, i) {
  1769. f(x, i);
  1770. }, t, s);
  1771. });
  1772. var forEachWith = /*#__PURE__*/I.curry(function forEachWith(newC, ef$$1, t, s) {
  1773. var c = newC();
  1774. getAsU(function (x, i) {
  1775. ef$$1(c, x, i);
  1776. }, t, s);
  1777. return c;
  1778. });
  1779. function get(l, s) {
  1780. return 1 < arguments[LENGTH] ? getAsU(id, l, s) : function (s) {
  1781. return getAsU(id, l, s);
  1782. };
  1783. }
  1784. var getAs = /*#__PURE__*/I.curry(getAsU);
  1785. var isDefined = /*#__PURE__*/I.curry(function isDefined(t, s) {
  1786. return void 0 !== getAsU(id, t, s);
  1787. });
  1788. var isEmpty = /*#__PURE__*/I.curry(function isEmpty(t, s) {
  1789. return !getAsU(toTrue, t, s);
  1790. });
  1791. var joinAs = /*#__PURE__*/mkTraverse(toStringPartial, /*#__PURE__*/(par(0, ef(reqString('`join` and `joinAs` expect a string delimiter'))))(function joinAs(d) {
  1792. return ConstantWith(function (x, y) {
  1793. return void 0 !== x ? void 0 !== y ? x + d + y : x : y;
  1794. });
  1795. }));
  1796. var join = /*#__PURE__*/joinAs(id);
  1797. var maximumBy = /*#__PURE__*/mumBy(gtU);
  1798. var maximum = /*#__PURE__*/maximumBy(id);
  1799. var meanAs = /*#__PURE__*/I.curry(function meanAs(xi2y, t, s) {
  1800. var sum = 0;
  1801. var num = 0;
  1802. getAsU(function (x, i) {
  1803. var y = xi2y(x, i);
  1804. if (void 0 !== y) {
  1805. num += 1;
  1806. sum += y;
  1807. }
  1808. }, t, s);
  1809. return sum / num;
  1810. });
  1811. var mean = /*#__PURE__*/meanAs(id);
  1812. var minimumBy = /*#__PURE__*/mumBy(ltU);
  1813. var minimum = /*#__PURE__*/minimumBy(id);
  1814. var none = /*#__PURE__*/I.curry(function none(xi2b, t, s) {
  1815. return !getAsU(function (x, i) {
  1816. if (xi2b(x, i)) return true;
  1817. }, t, s);
  1818. });
  1819. var or$1 = /*#__PURE__*/any(id);
  1820. var productAs = /*#__PURE__*/traverse( /*#__PURE__*/ConstantWith(multiplyU, 1));
  1821. var product = /*#__PURE__*/productAs( /*#__PURE__*/unto(1));
  1822. var select = I.curry(function select(l, s) {
  1823. warn(select, '`select` has been obsoleted. Just use `get`. See CHANGELOG for details.');
  1824. return get(l, s);
  1825. });
  1826. var selectAs = I.curry(function selectAs(f, l, s) {
  1827. warn(selectAs, '`selectAs` has been obsoleted. Just use `getAs`. See CHANGELOG for details.');
  1828. return getAs(f, l, s);
  1829. });
  1830. var sumAs = /*#__PURE__*/traverse(Sum);
  1831. var sum = /*#__PURE__*/sumAs(unto0);
  1832. // Creating new lenses
  1833. var foldTraversalLens = /*#__PURE__*/I.curry(function foldTraversalLens(fold, traversal) {
  1834. return lensU(fold(traversal), set(traversal));
  1835. });
  1836. var getter = function getter(get) {
  1837. return function (x, i, F, xi2yF) {
  1838. return xi2yF(get(x, i), i);
  1839. };
  1840. };
  1841. var lens = /*#__PURE__*/I.curry(lensU);
  1842. function partsOf(t) {
  1843. if (arguments[LENGTH] !== 1) t = toFunction(compose.apply(null, arguments));
  1844. return function partsOf(x, i, F, xi2yF) {
  1845. return F.map(function (y) {
  1846. return disperseU(t, y, x);
  1847. }, xi2yF(collectTotal(t, x), i));
  1848. };
  1849. }
  1850. var setter = /*#__PURE__*/lens(id);
  1851. // Enforcing invariants
  1852. function defaults(out) {
  1853. function o2u(x) {
  1854. return replaced(out, void 0, x);
  1855. }
  1856. return function defaults(x, i, F, xi2yF) {
  1857. return F.map(o2u, xi2yF(void 0 !== x ? x : out, i));
  1858. };
  1859. }
  1860. function define(v) {
  1861. var untoV = unto(v);
  1862. return function define(x, i, F, xi2yF) {
  1863. return F.map(untoV, xi2yF(void 0 !== x ? x : v, i));
  1864. };
  1865. }
  1866. var normalize = function normalize(xi2x) {
  1867. return [reread(xi2x), rewrite(xi2x)];
  1868. };
  1869. function required(inn) {
  1870. return replace$1(inn, void 0);
  1871. }
  1872. var reread = function reread(xi2x) {
  1873. return function (x, i, _F, xi2yF) {
  1874. return xi2yF(void 0 !== x ? xi2x(x, i) : x, i);
  1875. };
  1876. };
  1877. var rewrite = function rewrite(yi2y) {
  1878. return function (x, i, F, xi2yF) {
  1879. return F.map(function (y) {
  1880. return void 0 !== y ? yi2y(y, i) : y;
  1881. }, xi2yF(x, i));
  1882. };
  1883. };
  1884. // Lensing arrays
  1885. var filter = /*#__PURE__*/(res(function (lens) {
  1886. return toFunction([lens, isoU(id, ef(reqMaybeArray('`filter` must be set with undefined or an array-like object')))]);
  1887. }))(function filter(xi2b) {
  1888. return function filter(xs, i, F, xi2yF) {
  1889. var ts = void 0;
  1890. var fs = I.array0;
  1891. if (seemsArrayLike(xs)) partitionIntoIndex(xi2b, xs, ts = [], fs = []);
  1892. return F.map(function (ts) {
  1893. var tsN = ts ? ts[LENGTH] : 0;
  1894. var fsN = fs[LENGTH];
  1895. var n = tsN + fsN;
  1896. return n === fsN ? fs : copyToFrom(copyToFrom(Array(n), 0, ts, 0, tsN), tsN, fs, 0, fsN);
  1897. }, xi2yF(ts, i));
  1898. };
  1899. });
  1900. function find(xih2b) {
  1901. var hint = arguments[LENGTH] > 1 ? arguments[1] : { hint: 0 };
  1902. return function find(xs, _i, F, xi2yF) {
  1903. var ys = seemsArrayLike(xs) ? xs : '';
  1904. var i = hint.hint = findIndexHint(hint, xih2b, ys);
  1905. return F.map(function (v) {
  1906. return setIndex(i, v, ys);
  1907. }, xi2yF(ys[i], i));
  1908. };
  1909. }
  1910. function findWith(o) {
  1911. var oo = toFunction(o);
  1912. var p = isDefinedAt(oo);
  1913. return [arguments[LENGTH] > 1 ? find(p, arguments[1]) : find(p), oo];
  1914. }
  1915. var first = 0;
  1916. var index = ef(reqIndex);
  1917. var last = /*#__PURE__*/choose(function last(maybeArray) {
  1918. return seemsArrayLike(maybeArray) && maybeArray[LENGTH] ? maybeArray[LENGTH] - 1 : 0;
  1919. });
  1920. var prefix = function prefix(n) {
  1921. return slice(0, n);
  1922. };
  1923. var slice = /*#__PURE__*/(res(function (lens) {
  1924. return toFunction([lens, isoU(id, ef(reqMaybeArray('`slice` must be set with undefined or an array-like object')))]);
  1925. }))(function slice(begin, end) {
  1926. return function slice(xs, i, F, xsi2yF) {
  1927. var seems = seemsArrayLike(xs);
  1928. var xsN = seems && xs[LENGTH];
  1929. var b = sliceIndex(0, xsN, 0, begin);
  1930. var e = sliceIndex(b, xsN, xsN, end);
  1931. return F.map(function (zs) {
  1932. var zsN = zs ? zs[LENGTH] : 0;
  1933. var bPzsN = b + zsN;
  1934. var n = xsN - e + bPzsN;
  1935. return copyToFrom(copyToFrom(copyToFrom(Array(n), 0, xs, 0, b), b, zs, 0, zsN), bPzsN, xs, e, xsN);
  1936. }, xsi2yF(seems ? copyToFrom(Array(Math.max(0, e - b)), 0, xs, b, e) : void 0, i));
  1937. };
  1938. });
  1939. var suffix = function suffix(n) {
  1940. return slice(0 === n ? Infinity : !n ? 0 : -n, void 0);
  1941. };
  1942. // Lensing objects
  1943. var pickIn = function pickIn(t) {
  1944. return I.isObject(t) ? pick(modify(values, pickInAux, t)) : t;
  1945. };
  1946. var prop = function (x) {
  1947. if (!I.isString(x)) errorGiven('`prop` expects a string', x);
  1948. return x;
  1949. };
  1950. function props() {
  1951. var n = arguments[LENGTH];
  1952. var template = {};
  1953. for (var i = 0, k; i < n; ++i) {
  1954. template[k = arguments[i]] = k;
  1955. }return pick(template);
  1956. }
  1957. function propsExcept() {
  1958. var setish = I.create(null);
  1959. for (var i = 0, n = arguments[LENGTH]; i < n; ++i) {
  1960. setish[arguments[i]] = 'd';
  1961. }return [disjoint(function (k) {
  1962. return setish[k] || 't';
  1963. }), 't'];
  1964. }
  1965. var propsOf = function propsOf(o) {
  1966. warn(propsOf, '`propsOf` has been deprecated and there is no replacement. See CHANGELOG for details.');
  1967. return props.apply(null, I.keys(o));
  1968. };
  1969. function removable() {
  1970. for (var _len4 = arguments.length, ps = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  1971. ps[_key4] = arguments[_key4];
  1972. }
  1973. function drop(y) {
  1974. if (!(y instanceof Object)) return y;
  1975. for (var i = 0, n = ps[LENGTH]; i < n; ++i) {
  1976. if (I.hasU(ps[i], y)) return y;
  1977. }
  1978. }
  1979. return function (x, i, F, xi2yF) {
  1980. return F.map(drop, xi2yF(x, i));
  1981. };
  1982. }
  1983. // Providing defaults
  1984. var valueOr = function valueOr(v) {
  1985. return function (x, i, _F, xi2yF) {
  1986. return xi2yF(x != null ? x : v, i);
  1987. };
  1988. };
  1989. // Transforming data
  1990. var pick = /*#__PURE__*/(par(0, ef(reqTemplate('pick'))))(function pick(template) {
  1991. return function (x, i, F, xi2yF) {
  1992. return F.map(function (v) {
  1993. return setPick(template, v, x);
  1994. }, xi2yF(getPick(template, x), i));
  1995. };
  1996. });
  1997. var replace$1 = /*#__PURE__*/I.curry(function replace$$1(inn, out) {
  1998. function o2i(x) {
  1999. return replaced(out, inn, x);
  2000. }
  2001. return function replace$$1(x, i, F, xi2yF) {
  2002. return F.map(o2i, xi2yF(replaced(inn, out, x), i));
  2003. };
  2004. });
  2005. // Inserters
  2006. function appendTo(xs, _, F, xi2yF) {
  2007. var i = seemsArrayLike(xs) ? xs[LENGTH] : 0;
  2008. return F.map(function (x) {
  2009. return setIndex(i, x, xs);
  2010. }, xi2yF(void 0, i));
  2011. }
  2012. var append = function append(x, i, F, xi2yF) {
  2013. warn(append, '`append` has been renamed to `appendTo`. See CHANGELOG for details.');
  2014. return appendTo(x, i, F, xi2yF);
  2015. };
  2016. var assignTo = /*#__PURE__*/(function (iso) {
  2017. return copyName(toFunction([isoU(id, I.freeze), iso]), iso);
  2018. })(function assignTo(x, i, F, xi2yF) {
  2019. return F.map(function (y) {
  2020. return I.assign({}, x instanceof Object ? x : null, y);
  2021. }, xi2yF(void 0, i));
  2022. });
  2023. var prependTo = /*#__PURE__*/setName( /*#__PURE__*/toFunction([/*#__PURE__*/prefix(0), 0]), 'prependTo');
  2024. // Transforming
  2025. var appendOp = /*#__PURE__*/setName( /*#__PURE__*/inserterOp(appendTo), 'appendOp');
  2026. var assignOp = /*#__PURE__*/setName( /*#__PURE__*/inserterOp(assignTo), 'assignOp');
  2027. var modifyOp = function modifyOp(xi2y) {
  2028. return function modifyOp(x, i, C, _xi2yC) {
  2029. return C.of(xi2y(x, i));
  2030. };
  2031. };
  2032. var prependOp = /*#__PURE__*/setName( /*#__PURE__*/inserterOp(prependTo), 'prependOp');
  2033. var setOp = function setOp(y) {
  2034. return function setOp(_x, _i, C, _xi2yC) {
  2035. return C.of(y);
  2036. };
  2037. };
  2038. var removeOp = /*#__PURE__*/setOp();
  2039. var cross = /*#__PURE__*/setName( /*#__PURE__*/crossOr(removeOp), 'cross');
  2040. // Operations on isomorphisms
  2041. function getInverse(o, s) {
  2042. return 1 < arguments[LENGTH] ? getInverseU(o, s) : function (s) {
  2043. return getInverseU(o, s);
  2044. };
  2045. }
  2046. // Creating new isomorphisms
  2047. var iso = /*#__PURE__*/I.curry(isoU);
  2048. var _ = /*#__PURE__*/new Variable(-1);
  2049. function mapping(ps) {
  2050. var n = 0;
  2051. if (I.isFunction(ps)) ps = ps.apply(null, nVars(n = ps[LENGTH]));
  2052. checkPatternPairInDev(ps);
  2053. var kinds = Array(n);
  2054. var ms = ps.map(function (p) {
  2055. return toMatch(kinds, p);
  2056. });
  2057. var ss = ps.map(toSubst);
  2058. return isoU(oneway(n, ms[0], ss[1]), oneway(n, ms[1], ss[0]));
  2059. }
  2060. function mappings(ps) {
  2061. if (I.isFunction(ps)) ps = ps.apply(null, nVars(ps[LENGTH]));
  2062. return alternatives.apply(null, ps.map(mapping));
  2063. }
  2064. function pattern(p) {
  2065. var n = 0;
  2066. if (I.isFunction(p)) p = p.apply(null, nVars(n = p[LENGTH]));
  2067. checkPatternInDev(p);
  2068. var kinds = Array(n);
  2069. var m = toMatch(kinds, p);
  2070. return subset(function (x) {
  2071. return m(Array(n), x);
  2072. });
  2073. }
  2074. function patterns(ps) {
  2075. if (I.isFunction(ps)) ps = ps.apply(null, nVars(ps[LENGTH]));
  2076. return alternatives.apply(null, ps.map(pattern));
  2077. }
  2078. // Isomorphism combinators
  2079. var alternatives = /*#__PURE__*/makeSemi(orAlternativelyU);
  2080. var applyAt = /*#__PURE__*/I.curry(function applyAt(elements, transform) {
  2081. return isoU(modify(elements, get(transform)), modify(elements, getInverse(transform)));
  2082. });
  2083. var attemptEveryDown = function attemptEveryDown(iso) {
  2084. return isoU(transformEvery(rereadAttempt(get(iso))), transformEvery(rewriteAttempt(getInverse(iso))));
  2085. };
  2086. var attemptEveryUp = function attemptEveryUp(iso) {
  2087. return isoU(transformEvery(rewriteAttempt(get(iso))), transformEvery(rereadAttempt(getInverse(iso))));
  2088. };
  2089. var attemptSomeDown = function attemptSomeDown(iso) {
  2090. return isoU(transformSome(get(iso)), transformSome(getInverse(iso)));
  2091. };
  2092. var conjugate = /*#__PURE__*/I.curry(function conjugate(outer, inner) {
  2093. return [outer, inner, inverse(outer)];
  2094. });
  2095. var inverse = function inverse(iso) {
  2096. return function (x, i, F, xi2yF) {
  2097. return F.map(function (x) {
  2098. return getAsU(id, iso, x);
  2099. }, xi2yF(setU(iso, x, void 0), i));
  2100. };
  2101. };
  2102. var iterate = function iterate(aIa) {
  2103. return isoU(iteratePartial(get(aIa)), iteratePartial(getInverse(aIa)));
  2104. };
  2105. var orAlternatively = /*#__PURE__*/I.curry(orAlternativelyU);
  2106. var fold = function fold(saIs) {
  2107. return isoU(foldPartial(get(saIs)), unfoldPartial(getInverse(saIs)));
  2108. };
  2109. var unfold = function unfold(sIsa) {
  2110. return isoU(unfoldPartial(get(sIsa)), foldPartial(getInverse(sIsa)));
  2111. };
  2112. // Basic isomorphisms
  2113. var complement = /*#__PURE__*/isoU(notPartial, notPartial);
  2114. var is = function is(v) {
  2115. return isoU(function is(x) {
  2116. return I.acyclicEqualsU(v, x);
  2117. }, function (b) {
  2118. return true === b ? v : void 0;
  2119. });
  2120. };
  2121. function subset(predicate) {
  2122. var subsetFn = subsetPartial(predicate);
  2123. return isoU(subsetFn, subsetFn);
  2124. }
  2125. // Array isomorphisms
  2126. var array = function array(elem) {
  2127. var fwd = getInverse(elem);
  2128. var bwd = get(elem);
  2129. var mapFwd = function mapFwd(x) {
  2130. return mapIfArrayLike(fwd, x);
  2131. };
  2132. return function (x, i, F, xi2yF) {
  2133. return F.map(mapFwd, xi2yF(mapIfArrayLike(bwd, x), i));
  2134. };
  2135. };
  2136. var arrays = function arrays(elem) {
  2137. var fwd = getInverse(elem);
  2138. var bwd = get(elem);
  2139. var mapFwd = function mapFwd(x) {
  2140. return mapsIfArray(fwd, x);
  2141. };
  2142. return function (x, i, F, xi2yF) {
  2143. return F.map(mapFwd, xi2yF(mapsIfArray(bwd, x), i));
  2144. };
  2145. };
  2146. var indexed = /*#__PURE__*/isoU( /*#__PURE__*/expect(seemsArrayLike, /*#__PURE__*/(res(freezeObjectOfObjects))(function indexed(xs) {
  2147. var n = xs[LENGTH];
  2148. var xis = Array(n);
  2149. for (var i = 0; i < n; ++i) {
  2150. xis[i] = [i, xs[i]];
  2151. }return xis;
  2152. })), /*#__PURE__*/expect(I.isArray, /*#__PURE__*/(res(I.freeze))(function (xis) {
  2153. var n = xis[LENGTH];
  2154. var xs = Array(n);
  2155. for (var i = 0; i < n; ++i) {
  2156. var xi = xis[i];
  2157. if (xi[LENGTH] === 2) xs[xi[0]] = xi[1];
  2158. }
  2159. n = xs[LENGTH];
  2160. var j = 0;
  2161. for (var _i11 = 0; _i11 < n; ++_i11) {
  2162. var x = xs[_i11];
  2163. if (void 0 !== x) {
  2164. if (_i11 !== j) xs[j] = x;
  2165. ++j;
  2166. }
  2167. }
  2168. xs[LENGTH] = j;
  2169. return xs;
  2170. })));
  2171. var reverse = /*#__PURE__*/isoU(rev, rev);
  2172. var singleton = /*#__PURE__*/setName( /*#__PURE__*/mapping(function (x) {
  2173. return [[x], x];
  2174. }), 'singleton');
  2175. var groupBy = function groupBy(keyOf) {
  2176. keyOf = toGetter(keyOf);
  2177. return isoU(groupByFn(keyOf), ungroupByFn(keyOf));
  2178. };
  2179. var ungroupBy = function ungroupBy(keyOf) {
  2180. keyOf = toGetter(keyOf);
  2181. return isoU(ungroupByFn(keyOf), groupByFn(keyOf));
  2182. };
  2183. var zipWith1 = function zipWith1(iso) {
  2184. return isoU(zW1Fn(get(iso)), unzW1Fn(getInverse(iso)));
  2185. };
  2186. var unzipWith1 = function unzipWith1(iso) {
  2187. return isoU(unzW1Fn(get(iso)), zW1Fn(getInverse(iso)));
  2188. };
  2189. // Object isomorphisms
  2190. var disjoint = function disjoint(groupOf) {
  2191. return function disjoint(x, i, F, xi2yF) {
  2192. var fwd = disjointFwd(groupOf);
  2193. return F.map(fwd, xi2yF(disjointBwd(groupOf, x), i));
  2194. };
  2195. };
  2196. var multikeyed = /*#__PURE__*/isoU( /*#__PURE__*/expect( /*#__PURE__*/isInstanceOf(Object), /*#__PURE__*/(res(freezeObjectOfObjects))(function multikeyed(o) {
  2197. o = toObject(o);
  2198. var ps = [];
  2199. for (var k in o) {
  2200. var v = o[k];
  2201. if (I.isArray(v)) for (var i = 0, n = v[LENGTH]; i < n; ++i) {
  2202. ps.push([k, v[i]]);
  2203. } else ps.push([k, v]);
  2204. }
  2205. return ps;
  2206. })), /*#__PURE__*/expect(I.isArray, /*#__PURE__*/(res(freezeObjectOfObjects))(function (ps) {
  2207. var o = I.create(null);
  2208. for (var i = 0, n = ps[LENGTH]; i < n; ++i) {
  2209. var entry = ps[i];
  2210. if (entry[LENGTH] === 2) {
  2211. var k = entry[0];
  2212. var v = entry[1];
  2213. var was = o[k];
  2214. if (was === void 0) o[k] = v;else if (I.isArray(was)) was.push(v);else o[k] = [was, v];
  2215. }
  2216. }
  2217. return I.assign({}, o);
  2218. })));
  2219. // Standard isomorphisms
  2220. var json = /*#__PURE__*/(res(function (iso) {
  2221. return toFunction([iso, isoU(deepFreezeInDev, id)]);
  2222. }))(function json(options) {
  2223. var _ref3 = options || I.object0,
  2224. reviver = _ref3.reviver,
  2225. replacer = _ref3.replacer,
  2226. space = _ref3.space;
  2227. return isoU(expect(I.isString, tryCatch(function json(text) {
  2228. return JSON.parse(text, reviver);
  2229. })), expect(I.isDefined, function (value) {
  2230. return JSON.stringify(value, replacer, space);
  2231. }));
  2232. });
  2233. var uri = /*#__PURE__*/stringIsoU( /*#__PURE__*/tryCatch(decodeURI), encodeURI);
  2234. var uriComponent = /*#__PURE__*/isoU( /*#__PURE__*/expect(I.isString, /*#__PURE__*/tryCatch(decodeURIComponent)), /*#__PURE__*/expect(isPrimitiveData, encodeURIComponent));
  2235. // String isomorphisms
  2236. var dropPrefix = function dropPrefix(pfx) {
  2237. return stringIsoU(function dropPrefix(x) {
  2238. return x.startsWith(pfx) ? x.slice(pfx[LENGTH]) : undefined;
  2239. }, function (x) {
  2240. return pfx + x;
  2241. });
  2242. };
  2243. var dropSuffix = function dropSuffix(sfx) {
  2244. return stringIsoU(function dropSuffix(x) {
  2245. return x.endsWith(sfx) ? x.slice(0, x[LENGTH] - sfx[LENGTH]) : undefined;
  2246. }, function (x) {
  2247. return x + sfx;
  2248. });
  2249. };
  2250. var replaces = /*#__PURE__*/I.curry(function replaces(i, o) {
  2251. return stringIsoU(replace(toRegExpU(i, 'g'), o), replace(toRegExpU(o, 'g'), i));
  2252. });
  2253. var split = /*#__PURE__*/(function (fn$$1) {
  2254. return function split(_sep) {
  2255. return toFunction([fn$$1.apply(null, arguments), isoU(I.freeze, id)]);
  2256. };
  2257. })(function split(sep) {
  2258. var re = arguments[LENGTH] > 1 ? arguments[1] : sep;
  2259. return isoU(expect(I.isString, function (x) {
  2260. return x.split(re);
  2261. }), expect(I.isArray, function (xs) {
  2262. return xs.join(sep);
  2263. }));
  2264. });
  2265. var uncouple = /*#__PURE__*/(function (fn$$1) {
  2266. return function uncouple(_sep) {
  2267. return toFunction([fn$$1.apply(null, arguments), isoU(I.freeze, id)]);
  2268. };
  2269. })(function uncouple(sep) {
  2270. var re = toRegExpU(arguments[LENGTH] > 1 ? arguments[1] : sep, '');
  2271. return isoU(expect(I.isString, function (x) {
  2272. var m = re.exec(x);
  2273. return m ? [x.slice(0, m[INDEX]), x.slice(reLastIndex(m))] : [x, ''];
  2274. }), function (kv) {
  2275. if (isPair(kv)) {
  2276. var k = kv[0];
  2277. var v = kv[1];
  2278. return v ? k + sep + v : k;
  2279. }
  2280. });
  2281. });
  2282. // Standardish isomorphisms
  2283. var querystring = /*#__PURE__*/setName( /*#__PURE__*/toFunction([/*#__PURE__*/reread(function (s) {
  2284. return I.isString(s) ? s.replace(/\+/g, '%20') : s;
  2285. }), /*#__PURE__*/split('&'), /*#__PURE__*/array([/*#__PURE__*/uncouple('='), /*#__PURE__*/array(uriComponent)]), /*#__PURE__*/inverse(multikeyed)]), 'querystring');
  2286. // Arithmetic isomorphisms
  2287. var add$1 = function add$$1(c) {
  2288. return numberIsoU(add(c), add(-c));
  2289. };
  2290. var divide = function divide(c) {
  2291. return numberIsoU(divideBy(c), multiply(c));
  2292. };
  2293. var multiply$1 = function multiply$$1(c) {
  2294. return numberIsoU(multiply(c), divideBy(c));
  2295. };
  2296. var negate$1 = /*#__PURE__*/numberIsoU(negate, negate);
  2297. var subtract = function subtract(c) {
  2298. return numberIsoU(add(-c), add(c));
  2299. };
  2300. var pointer = function pointer(s) {
  2301. if (s[0] === '#') s = decodeURIComponent(s);
  2302. var ts = s.split('/');
  2303. var n = ts[LENGTH];
  2304. for (var i = 1; i < n; ++i) {
  2305. var t = ts[i];
  2306. ts[i - 1] = /^(0|[1-9]\d*)$/.test(t) ? ifElse(isArrayOrPrimitive, Number(t), t) : '-' === t ? ifElse(isArrayOrPrimitive, append, t) : t.replace('~1', '/').replace('~0', '~');
  2307. }
  2308. ts[LENGTH] = n - 1;
  2309. return ts;
  2310. };
  2311. exports.Identity = I.Identity;
  2312. exports.IdentityAsync = I.IdentityAsync;
  2313. exports.FantasyFunctor = I.FantasyFunctor;
  2314. exports.fromFantasy = I.fromFantasy;
  2315. exports.fromFantasyApplicative = I.fromFantasyApplicative;
  2316. exports.fromFantasyMonad = I.fromFantasyMonad;
  2317. exports.seemsArrayLike = seemsArrayLike;
  2318. exports.Select = Select;
  2319. exports.toFunction = toFunction;
  2320. exports.assign = assign;
  2321. exports.disperse = disperse;
  2322. exports.modify = modify;
  2323. exports.modifyAsync = modifyAsync;
  2324. exports.remove = remove;
  2325. exports.set = set;
  2326. exports.traverse = traverse;
  2327. exports.compose = compose;
  2328. exports.flat = flat;
  2329. exports.lazy = lazy;
  2330. exports.choices = choices;
  2331. exports.choose = choose;
  2332. exports.cond = cond;
  2333. exports.condOf = condOf;
  2334. exports.ifElse = ifElse;
  2335. exports.orElse = orElse;
  2336. exports.chain = chain;
  2337. exports.choice = choice;
  2338. exports.unless = unless;
  2339. exports.when = when;
  2340. exports.optional = optional;
  2341. exports.zero = zero;
  2342. exports.mapIx = mapIx;
  2343. exports.setIx = setIx;
  2344. exports.tieIx = tieIx;
  2345. exports.joinIx = joinIx;
  2346. exports.reIx = reIx;
  2347. exports.skipIx = skipIx;
  2348. exports.getLog = getLog;
  2349. exports.log = log;
  2350. exports.transform = transform;
  2351. exports.transformAsync = transformAsync;
  2352. exports.seq = seq;
  2353. exports.branchOr = branchOr;
  2354. exports.branch = branch;
  2355. exports.branches = branches;
  2356. exports.elems = elems;
  2357. exports.elemsTotal = elemsTotal;
  2358. exports.entries = entries;
  2359. exports.keys = keys;
  2360. exports.keysEverywhere = keysEverywhere;
  2361. exports.subseq = subseq;
  2362. exports.limit = limit;
  2363. exports.offset = offset;
  2364. exports.matches = matches;
  2365. exports.values = values;
  2366. exports.children = children;
  2367. exports.flatten = flatten;
  2368. exports.query = query;
  2369. exports.satisfying = satisfying;
  2370. exports.leafs = leafs;
  2371. exports.whereEq = whereEq;
  2372. exports.all = all;
  2373. exports.and = and$1;
  2374. exports.all1 = all1;
  2375. exports.and1 = and1;
  2376. exports.any = any;
  2377. exports.collectAs = collectAs;
  2378. exports.collect = collect;
  2379. exports.collectTotalAs = collectTotalAs;
  2380. exports.collectTotal = collectTotal;
  2381. exports.concatAs = concatAs;
  2382. exports.concat = concat;
  2383. exports.countIf = countIf;
  2384. exports.count = count;
  2385. exports.countsAs = countsAs;
  2386. exports.counts = counts;
  2387. exports.foldl = foldl;
  2388. exports.foldr = foldr;
  2389. exports.forEach = forEach;
  2390. exports.forEachWith = forEachWith;
  2391. exports.get = get;
  2392. exports.getAs = getAs;
  2393. exports.isDefined = isDefined;
  2394. exports.isEmpty = isEmpty;
  2395. exports.joinAs = joinAs;
  2396. exports.join = join;
  2397. exports.maximumBy = maximumBy;
  2398. exports.maximum = maximum;
  2399. exports.meanAs = meanAs;
  2400. exports.mean = mean;
  2401. exports.minimumBy = minimumBy;
  2402. exports.minimum = minimum;
  2403. exports.none = none;
  2404. exports.or = or$1;
  2405. exports.productAs = productAs;
  2406. exports.product = product;
  2407. exports.select = select;
  2408. exports.selectAs = selectAs;
  2409. exports.sumAs = sumAs;
  2410. exports.sum = sum;
  2411. exports.foldTraversalLens = foldTraversalLens;
  2412. exports.getter = getter;
  2413. exports.lens = lens;
  2414. exports.partsOf = partsOf;
  2415. exports.setter = setter;
  2416. exports.defaults = defaults;
  2417. exports.define = define;
  2418. exports.normalize = normalize;
  2419. exports.required = required;
  2420. exports.reread = reread;
  2421. exports.rewrite = rewrite;
  2422. exports.filter = filter;
  2423. exports.find = find;
  2424. exports.findWith = findWith;
  2425. exports.first = first;
  2426. exports.index = index;
  2427. exports.last = last;
  2428. exports.prefix = prefix;
  2429. exports.slice = slice;
  2430. exports.suffix = suffix;
  2431. exports.pickIn = pickIn;
  2432. exports.prop = prop;
  2433. exports.props = props;
  2434. exports.propsExcept = propsExcept;
  2435. exports.propsOf = propsOf;
  2436. exports.removable = removable;
  2437. exports.valueOr = valueOr;
  2438. exports.pick = pick;
  2439. exports.replace = replace$1;
  2440. exports.appendTo = appendTo;
  2441. exports.append = append;
  2442. exports.assignTo = assignTo;
  2443. exports.prependTo = prependTo;
  2444. exports.appendOp = appendOp;
  2445. exports.assignOp = assignOp;
  2446. exports.modifyOp = modifyOp;
  2447. exports.prependOp = prependOp;
  2448. exports.setOp = setOp;
  2449. exports.removeOp = removeOp;
  2450. exports.cross = cross;
  2451. exports.getInverse = getInverse;
  2452. exports.iso = iso;
  2453. exports._ = _;
  2454. exports.mapping = mapping;
  2455. exports.mappings = mappings;
  2456. exports.pattern = pattern;
  2457. exports.patterns = patterns;
  2458. exports.alternatives = alternatives;
  2459. exports.applyAt = applyAt;
  2460. exports.attemptEveryDown = attemptEveryDown;
  2461. exports.attemptEveryUp = attemptEveryUp;
  2462. exports.attemptSomeDown = attemptSomeDown;
  2463. exports.conjugate = conjugate;
  2464. exports.inverse = inverse;
  2465. exports.iterate = iterate;
  2466. exports.orAlternatively = orAlternatively;
  2467. exports.fold = fold;
  2468. exports.unfold = unfold;
  2469. exports.complement = complement;
  2470. exports.identity = identity;
  2471. exports.is = is;
  2472. exports.subset = subset;
  2473. exports.array = array;
  2474. exports.arrays = arrays;
  2475. exports.indexed = indexed;
  2476. exports.reverse = reverse;
  2477. exports.singleton = singleton;
  2478. exports.groupBy = groupBy;
  2479. exports.ungroupBy = ungroupBy;
  2480. exports.zipWith1 = zipWith1;
  2481. exports.unzipWith1 = unzipWith1;
  2482. exports.disjoint = disjoint;
  2483. exports.keyed = keyed;
  2484. exports.multikeyed = multikeyed;
  2485. exports.json = json;
  2486. exports.uri = uri;
  2487. exports.uriComponent = uriComponent;
  2488. exports.dropPrefix = dropPrefix;
  2489. exports.dropSuffix = dropSuffix;
  2490. exports.replaces = replaces;
  2491. exports.split = split;
  2492. exports.uncouple = uncouple;
  2493. exports.querystring = querystring;
  2494. exports.add = add$1;
  2495. exports.divide = divide;
  2496. exports.multiply = multiply$1;
  2497. exports.negate = negate$1;
  2498. exports.subtract = subtract;
  2499. exports.pointer = pointer;
  2500. Object.defineProperty(exports, '__esModule', { value: true });
  2501. })));