版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ReadonlyNonEmptyArray.js 36 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  26. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  27. if (ar || !(i in from)) {
  28. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  29. ar[i] = from[i];
  30. }
  31. }
  32. return to.concat(ar || Array.prototype.slice.call(from));
  33. };
  34. Object.defineProperty(exports, "__esModule", { value: true });
  35. exports.reduceRight = exports.foldMap = exports.reduce = exports.mapWithIndex = exports.map = exports.flatten = exports.duplicate = exports.extend = exports.chain = exports.ap = exports.alt = exports.altW = exports.of = exports.chunksOf = exports.splitAt = exports.chop = exports.chainWithIndex = exports.intersperse = exports.prependAll = exports.unzip = exports.zip = exports.zipWith = exports.modifyAt = exports.updateAt = exports.sort = exports.groupBy = exports.group = exports.reverse = exports.concat = exports.concatW = exports.fromArray = exports.unappend = exports.unprepend = exports.range = exports.replicate = exports.makeBy = exports.fromReadonlyArray = exports.rotate = exports.union = exports.sortBy = exports.uniq = exports.unsafeUpdateAt = exports.unsafeInsertAt = exports.append = exports.appendW = exports.prepend = exports.prependW = exports.isOutOfBound = exports.isNonEmpty = exports.empty = void 0;
  36. exports.filter = exports.groupSort = exports.intercalate = exports.updateLast = exports.modifyLast = exports.updateHead = exports.modifyHead = exports.matchRight = exports.matchLeft = exports.concatAll = exports.max = exports.min = exports.init = exports.last = exports.tail = exports.head = exports.apS = exports.bind = exports.let = exports.bindTo = exports.Do = exports.Comonad = exports.Alt = exports.TraversableWithIndex = exports.Traversable = exports.FoldableWithIndex = exports.Foldable = exports.Monad = exports.chainFirst = exports.Chain = exports.Applicative = exports.apSecond = exports.apFirst = exports.Apply = exports.FunctorWithIndex = exports.Pointed = exports.flap = exports.Functor = exports.getUnionSemigroup = exports.getEq = exports.getSemigroup = exports.getShow = exports.URI = exports.extract = exports.traverseWithIndex = exports.sequence = exports.traverse = exports.reduceRightWithIndex = exports.foldMapWithIndex = exports.reduceWithIndex = void 0;
  37. exports.readonlyNonEmptyArray = exports.fold = exports.prependToAll = exports.insertAt = exports.snoc = exports.cons = exports.unsnoc = exports.uncons = exports.filterWithIndex = void 0;
  38. var Apply_1 = require("./Apply");
  39. var Chain_1 = require("./Chain");
  40. var Eq_1 = require("./Eq");
  41. var function_1 = require("./function");
  42. var Functor_1 = require("./Functor");
  43. var _ = __importStar(require("./internal"));
  44. var Ord_1 = require("./Ord");
  45. var Se = __importStar(require("./Semigroup"));
  46. // -------------------------------------------------------------------------------------
  47. // internal
  48. // -------------------------------------------------------------------------------------
  49. /**
  50. * @internal
  51. */
  52. exports.empty = _.emptyReadonlyArray;
  53. /**
  54. * @internal
  55. */
  56. exports.isNonEmpty = _.isNonEmpty;
  57. /**
  58. * @internal
  59. */
  60. var isOutOfBound = function (i, as) { return i < 0 || i >= as.length; };
  61. exports.isOutOfBound = isOutOfBound;
  62. /**
  63. * @internal
  64. */
  65. var prependW = function (head) {
  66. return function (tail) {
  67. return __spreadArray([head], tail, true);
  68. };
  69. };
  70. exports.prependW = prependW;
  71. /**
  72. * @internal
  73. */
  74. exports.prepend = exports.prependW;
  75. /**
  76. * @internal
  77. */
  78. var appendW = function (end) {
  79. return function (init) {
  80. return __spreadArray(__spreadArray([], init, true), [end], false);
  81. };
  82. };
  83. exports.appendW = appendW;
  84. /**
  85. * @internal
  86. */
  87. exports.append = exports.appendW;
  88. /**
  89. * @internal
  90. */
  91. var unsafeInsertAt = function (i, a, as) {
  92. if ((0, exports.isNonEmpty)(as)) {
  93. var xs = _.fromReadonlyNonEmptyArray(as);
  94. xs.splice(i, 0, a);
  95. return xs;
  96. }
  97. return [a];
  98. };
  99. exports.unsafeInsertAt = unsafeInsertAt;
  100. /**
  101. * @internal
  102. */
  103. var unsafeUpdateAt = function (i, a, as) {
  104. if (as[i] === a) {
  105. return as;
  106. }
  107. else {
  108. var xs = _.fromReadonlyNonEmptyArray(as);
  109. xs[i] = a;
  110. return xs;
  111. }
  112. };
  113. exports.unsafeUpdateAt = unsafeUpdateAt;
  114. /**
  115. * Remove duplicates from a `ReadonlyNonEmptyArray`, keeping the first occurrence of an element.
  116. *
  117. * @example
  118. * import { uniq } from 'fp-ts/ReadonlyNonEmptyArray'
  119. * import * as N from 'fp-ts/number'
  120. *
  121. * assert.deepStrictEqual(uniq(N.Eq)([1, 2, 1]), [1, 2])
  122. *
  123. * @since 2.11.0
  124. */
  125. var uniq = function (E) {
  126. return function (as) {
  127. if (as.length === 1) {
  128. return as;
  129. }
  130. var out = [(0, exports.head)(as)];
  131. var rest = (0, exports.tail)(as);
  132. var _loop_1 = function (a) {
  133. if (out.every(function (o) { return !E.equals(o, a); })) {
  134. out.push(a);
  135. }
  136. };
  137. for (var _i = 0, rest_1 = rest; _i < rest_1.length; _i++) {
  138. var a = rest_1[_i];
  139. _loop_1(a);
  140. }
  141. return out;
  142. };
  143. };
  144. exports.uniq = uniq;
  145. /**
  146. * Sort the elements of a `ReadonlyNonEmptyArray` in increasing order, where elements are compared using first `ords[0]`, then `ords[1]`,
  147. * etc...
  148. *
  149. * @example
  150. * import * as RNEA from 'fp-ts/ReadonlyNonEmptyArray'
  151. * import { contramap } from 'fp-ts/Ord'
  152. * import * as S from 'fp-ts/string'
  153. * import * as N from 'fp-ts/number'
  154. * import { pipe } from 'fp-ts/function'
  155. *
  156. * interface Person {
  157. * name: string
  158. * age: number
  159. * }
  160. *
  161. * const byName = pipe(S.Ord, contramap((p: Person) => p.name))
  162. *
  163. * const byAge = pipe(N.Ord, contramap((p: Person) => p.age))
  164. *
  165. * const sortByNameByAge = RNEA.sortBy([byName, byAge])
  166. *
  167. * const persons: RNEA.ReadonlyNonEmptyArray<Person> = [
  168. * { name: 'a', age: 1 },
  169. * { name: 'b', age: 3 },
  170. * { name: 'c', age: 2 },
  171. * { name: 'b', age: 2 }
  172. * ]
  173. *
  174. * assert.deepStrictEqual(sortByNameByAge(persons), [
  175. * { name: 'a', age: 1 },
  176. * { name: 'b', age: 2 },
  177. * { name: 'b', age: 3 },
  178. * { name: 'c', age: 2 }
  179. * ])
  180. *
  181. * @since 2.11.0
  182. */
  183. var sortBy = function (ords) {
  184. if ((0, exports.isNonEmpty)(ords)) {
  185. var M = (0, Ord_1.getMonoid)();
  186. return (0, exports.sort)(ords.reduce(M.concat, M.empty));
  187. }
  188. return function_1.identity;
  189. };
  190. exports.sortBy = sortBy;
  191. /**
  192. * @since 2.11.0
  193. */
  194. var union = function (E) {
  195. var uniqE = (0, exports.uniq)(E);
  196. return function (second) { return function (first) { return uniqE((0, function_1.pipe)(first, concat(second))); }; };
  197. };
  198. exports.union = union;
  199. /**
  200. * Rotate a `ReadonlyNonEmptyArray` by `n` steps.
  201. *
  202. * @example
  203. * import { rotate } from 'fp-ts/ReadonlyNonEmptyArray'
  204. *
  205. * assert.deepStrictEqual(rotate(2)([1, 2, 3, 4, 5]), [4, 5, 1, 2, 3])
  206. * assert.deepStrictEqual(rotate(-2)([1, 2, 3, 4, 5]), [3, 4, 5, 1, 2])
  207. *
  208. * @since 2.11.0
  209. */
  210. var rotate = function (n) {
  211. return function (as) {
  212. var len = as.length;
  213. var m = Math.round(n) % len;
  214. if ((0, exports.isOutOfBound)(Math.abs(m), as) || m === 0) {
  215. return as;
  216. }
  217. if (m < 0) {
  218. var _a = (0, exports.splitAt)(-m)(as), f = _a[0], s = _a[1];
  219. return (0, function_1.pipe)(s, concat(f));
  220. }
  221. else {
  222. return (0, exports.rotate)(m - len)(as);
  223. }
  224. };
  225. };
  226. exports.rotate = rotate;
  227. // -------------------------------------------------------------------------------------
  228. // constructors
  229. // -------------------------------------------------------------------------------------
  230. /**
  231. * Return a `ReadonlyNonEmptyArray` from a `ReadonlyArray` returning `none` if the input is empty.
  232. *
  233. * @category conversions
  234. * @since 2.5.0
  235. */
  236. var fromReadonlyArray = function (as) {
  237. return (0, exports.isNonEmpty)(as) ? _.some(as) : _.none;
  238. };
  239. exports.fromReadonlyArray = fromReadonlyArray;
  240. /**
  241. * Return a `ReadonlyNonEmptyArray` of length `n` with element `i` initialized with `f(i)`.
  242. *
  243. * **Note**. `n` is normalized to a natural number.
  244. *
  245. * @example
  246. * import { makeBy } from 'fp-ts/ReadonlyNonEmptyArray'
  247. * import { pipe } from 'fp-ts/function'
  248. *
  249. * const double = (n: number): number => n * 2
  250. * assert.deepStrictEqual(pipe(5, makeBy(double)), [0, 2, 4, 6, 8])
  251. *
  252. * @category constructors
  253. * @since 2.11.0
  254. */
  255. var makeBy = function (f) {
  256. return function (n) {
  257. var j = Math.max(0, Math.floor(n));
  258. var out = [f(0)];
  259. for (var i = 1; i < j; i++) {
  260. out.push(f(i));
  261. }
  262. return out;
  263. };
  264. };
  265. exports.makeBy = makeBy;
  266. /**
  267. * Create a `ReadonlyNonEmptyArray` containing a value repeated the specified number of times.
  268. *
  269. * **Note**. `n` is normalized to a natural number.
  270. *
  271. * @example
  272. * import { replicate } from 'fp-ts/ReadonlyNonEmptyArray'
  273. * import { pipe } from 'fp-ts/function'
  274. *
  275. * assert.deepStrictEqual(pipe(3, replicate('a')), ['a', 'a', 'a'])
  276. *
  277. * @category constructors
  278. * @since 2.11.0
  279. */
  280. var replicate = function (a) { return (0, exports.makeBy)(function () { return a; }); };
  281. exports.replicate = replicate;
  282. /**
  283. * Create a `ReadonlyNonEmptyArray` containing a range of integers, including both endpoints.
  284. *
  285. * @example
  286. * import { range } from 'fp-ts/ReadonlyNonEmptyArray'
  287. *
  288. * assert.deepStrictEqual(range(1, 5), [1, 2, 3, 4, 5])
  289. *
  290. * @category constructors
  291. * @since 2.11.0
  292. */
  293. var range = function (start, end) {
  294. return start <= end ? (0, exports.makeBy)(function (i) { return start + i; })(end - start + 1) : [start];
  295. };
  296. exports.range = range;
  297. /**
  298. * Return the tuple of the `head` and the `tail`.
  299. *
  300. * @example
  301. * import { unprepend } from 'fp-ts/ReadonlyNonEmptyArray'
  302. *
  303. * assert.deepStrictEqual(unprepend([1, 2, 3, 4]), [1, [2, 3, 4]])
  304. *
  305. * @since 2.9.0
  306. */
  307. var unprepend = function (as) { return [(0, exports.head)(as), (0, exports.tail)(as)]; };
  308. exports.unprepend = unprepend;
  309. /**
  310. * Return the tuple of the `init` and the `last`.
  311. *
  312. * @example
  313. * import { unappend } from 'fp-ts/ReadonlyNonEmptyArray'
  314. *
  315. * assert.deepStrictEqual(unappend([1, 2, 3, 4]), [[1, 2, 3], 4])
  316. *
  317. * @since 2.9.0
  318. */
  319. var unappend = function (as) { return [(0, exports.init)(as), (0, exports.last)(as)]; };
  320. exports.unappend = unappend;
  321. /**
  322. * @category conversions
  323. * @since 2.5.0
  324. */
  325. var fromArray = function (as) { return (0, exports.fromReadonlyArray)(as.slice()); };
  326. exports.fromArray = fromArray;
  327. function concatW(second) {
  328. return function (first) { return first.concat(second); };
  329. }
  330. exports.concatW = concatW;
  331. function concat(x, y) {
  332. return y ? x.concat(y) : function (y) { return y.concat(x); };
  333. }
  334. exports.concat = concat;
  335. /**
  336. * @since 2.5.0
  337. */
  338. var reverse = function (as) {
  339. return as.length === 1 ? as : __spreadArray([(0, exports.last)(as)], as.slice(0, -1).reverse(), true);
  340. };
  341. exports.reverse = reverse;
  342. function group(E) {
  343. return function (as) {
  344. var len = as.length;
  345. if (len === 0) {
  346. return exports.empty;
  347. }
  348. var out = [];
  349. var head = as[0];
  350. var nea = [head];
  351. for (var i = 1; i < len; i++) {
  352. var a = as[i];
  353. if (E.equals(a, head)) {
  354. nea.push(a);
  355. }
  356. else {
  357. out.push(nea);
  358. head = a;
  359. nea = [head];
  360. }
  361. }
  362. out.push(nea);
  363. return out;
  364. };
  365. }
  366. exports.group = group;
  367. /**
  368. * Splits an array into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning
  369. * function on each element, and grouping the results according to values returned
  370. *
  371. * @example
  372. * import { groupBy } from 'fp-ts/ReadonlyNonEmptyArray'
  373. *
  374. * assert.deepStrictEqual(groupBy((s: string) => String(s.length))(['a', 'b', 'ab']), {
  375. * '1': ['a', 'b'],
  376. * '2': ['ab']
  377. * })
  378. *
  379. * @since 2.5.0
  380. */
  381. var groupBy = function (f) {
  382. return function (as) {
  383. var out = {};
  384. for (var _i = 0, as_1 = as; _i < as_1.length; _i++) {
  385. var a = as_1[_i];
  386. var k = f(a);
  387. if (_.has.call(out, k)) {
  388. out[k].push(a);
  389. }
  390. else {
  391. out[k] = [a];
  392. }
  393. }
  394. return out;
  395. };
  396. };
  397. exports.groupBy = groupBy;
  398. /**
  399. * @since 2.5.0
  400. */
  401. var sort = function (O) {
  402. return function (as) {
  403. return as.length === 1 ? as : as.slice().sort(O.compare);
  404. };
  405. };
  406. exports.sort = sort;
  407. /**
  408. * @since 2.5.0
  409. */
  410. var updateAt = function (i, a) {
  411. return (0, exports.modifyAt)(i, function () { return a; });
  412. };
  413. exports.updateAt = updateAt;
  414. /**
  415. * @since 2.5.0
  416. */
  417. var modifyAt = function (i, f) {
  418. return function (as) {
  419. return (0, exports.isOutOfBound)(i, as) ? _.none : _.some((0, exports.unsafeUpdateAt)(i, f(as[i]), as));
  420. };
  421. };
  422. exports.modifyAt = modifyAt;
  423. /**
  424. * @since 2.5.1
  425. */
  426. var zipWith = function (as, bs, f) {
  427. var cs = [f(as[0], bs[0])];
  428. var len = Math.min(as.length, bs.length);
  429. for (var i = 1; i < len; i++) {
  430. cs[i] = f(as[i], bs[i]);
  431. }
  432. return cs;
  433. };
  434. exports.zipWith = zipWith;
  435. function zip(as, bs) {
  436. if (bs === undefined) {
  437. return function (bs) { return zip(bs, as); };
  438. }
  439. return (0, exports.zipWith)(as, bs, function (a, b) { return [a, b]; });
  440. }
  441. exports.zip = zip;
  442. /**
  443. * @since 2.5.1
  444. */
  445. var unzip = function (abs) {
  446. var fa = [abs[0][0]];
  447. var fb = [abs[0][1]];
  448. for (var i = 1; i < abs.length; i++) {
  449. fa[i] = abs[i][0];
  450. fb[i] = abs[i][1];
  451. }
  452. return [fa, fb];
  453. };
  454. exports.unzip = unzip;
  455. /**
  456. * Prepend an element to every member of a `ReadonlyNonEmptyArray`.
  457. *
  458. * @example
  459. * import { prependAll } from 'fp-ts/ReadonlyNonEmptyArray'
  460. *
  461. * assert.deepStrictEqual(prependAll(9)([1, 2, 3, 4]), [9, 1, 9, 2, 9, 3, 9, 4])
  462. *
  463. * @since 2.10.0
  464. */
  465. var prependAll = function (middle) {
  466. return function (as) {
  467. var out = [middle, as[0]];
  468. for (var i = 1; i < as.length; i++) {
  469. out.push(middle, as[i]);
  470. }
  471. return out;
  472. };
  473. };
  474. exports.prependAll = prependAll;
  475. /**
  476. * Places an element in between members of a `ReadonlyNonEmptyArray`.
  477. *
  478. * @example
  479. * import { intersperse } from 'fp-ts/ReadonlyNonEmptyArray'
  480. *
  481. * assert.deepStrictEqual(intersperse(9)([1, 2, 3, 4]), [1, 9, 2, 9, 3, 9, 4])
  482. *
  483. * @since 2.9.0
  484. */
  485. var intersperse = function (middle) {
  486. return function (as) {
  487. var rest = (0, exports.tail)(as);
  488. return (0, exports.isNonEmpty)(rest) ? (0, function_1.pipe)(rest, (0, exports.prependAll)(middle), (0, exports.prepend)((0, exports.head)(as))) : as;
  489. };
  490. };
  491. exports.intersperse = intersperse;
  492. /**
  493. * @category sequencing
  494. * @since 2.10.0
  495. */
  496. var chainWithIndex = function (f) {
  497. return function (as) {
  498. var out = _.fromReadonlyNonEmptyArray(f(0, (0, exports.head)(as)));
  499. for (var i = 1; i < as.length; i++) {
  500. out.push.apply(out, f(i, as[i]));
  501. }
  502. return out;
  503. };
  504. };
  505. exports.chainWithIndex = chainWithIndex;
  506. /**
  507. * A useful recursion pattern for processing a `ReadonlyNonEmptyArray` to produce a new `ReadonlyNonEmptyArray`, often used for "chopping" up the input
  508. * `ReadonlyNonEmptyArray`. Typically `chop` is called with some function that will consume an initial prefix of the `ReadonlyNonEmptyArray` and produce a
  509. * value and the tail of the `ReadonlyNonEmptyArray`.
  510. *
  511. * @since 2.10.0
  512. */
  513. var chop = function (f) {
  514. return function (as) {
  515. var _a = f(as), b = _a[0], rest = _a[1];
  516. var out = [b];
  517. var next = rest;
  518. while ((0, exports.isNonEmpty)(next)) {
  519. var _b = f(next), b_1 = _b[0], rest_2 = _b[1];
  520. out.push(b_1);
  521. next = rest_2;
  522. }
  523. return out;
  524. };
  525. };
  526. exports.chop = chop;
  527. /**
  528. * Splits a `ReadonlyNonEmptyArray` into two pieces, the first piece has max `n` elements.
  529. *
  530. * @since 2.10.0
  531. */
  532. var splitAt = function (n) {
  533. return function (as) {
  534. var m = Math.max(1, n);
  535. return m >= as.length ? [as, exports.empty] : [(0, function_1.pipe)(as.slice(1, m), (0, exports.prepend)((0, exports.head)(as))), as.slice(m)];
  536. };
  537. };
  538. exports.splitAt = splitAt;
  539. /**
  540. * Splits a `ReadonlyNonEmptyArray` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
  541. * the `ReadonlyNonEmptyArray`.
  542. *
  543. * @since 2.10.0
  544. */
  545. var chunksOf = function (n) { return (0, exports.chop)((0, exports.splitAt)(n)); };
  546. exports.chunksOf = chunksOf;
  547. var _map = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.map)(f)); };
  548. /* istanbul ignore next */
  549. var _mapWithIndex = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.mapWithIndex)(f)); };
  550. var _ap = function (fab, fa) { return (0, function_1.pipe)(fab, (0, exports.ap)(fa)); };
  551. var _chain = function (ma, f) { return (0, function_1.pipe)(ma, (0, exports.chain)(f)); };
  552. /* istanbul ignore next */
  553. var _extend = function (wa, f) { return (0, function_1.pipe)(wa, (0, exports.extend)(f)); };
  554. /* istanbul ignore next */
  555. var _reduce = function (fa, b, f) { return (0, function_1.pipe)(fa, (0, exports.reduce)(b, f)); };
  556. /* istanbul ignore next */
  557. var _foldMap = function (M) {
  558. var foldMapM = (0, exports.foldMap)(M);
  559. return function (fa, f) { return (0, function_1.pipe)(fa, foldMapM(f)); };
  560. };
  561. /* istanbul ignore next */
  562. var _reduceRight = function (fa, b, f) { return (0, function_1.pipe)(fa, (0, exports.reduceRight)(b, f)); };
  563. /* istanbul ignore next */
  564. var _traverse = function (F) {
  565. var traverseF = (0, exports.traverse)(F);
  566. return function (ta, f) { return (0, function_1.pipe)(ta, traverseF(f)); };
  567. };
  568. /* istanbul ignore next */
  569. var _alt = function (fa, that) { return (0, function_1.pipe)(fa, (0, exports.alt)(that)); };
  570. /* istanbul ignore next */
  571. var _reduceWithIndex = function (fa, b, f) {
  572. return (0, function_1.pipe)(fa, (0, exports.reduceWithIndex)(b, f));
  573. };
  574. /* istanbul ignore next */
  575. var _foldMapWithIndex = function (M) {
  576. var foldMapWithIndexM = (0, exports.foldMapWithIndex)(M);
  577. return function (fa, f) { return (0, function_1.pipe)(fa, foldMapWithIndexM(f)); };
  578. };
  579. /* istanbul ignore next */
  580. var _reduceRightWithIndex = function (fa, b, f) {
  581. return (0, function_1.pipe)(fa, (0, exports.reduceRightWithIndex)(b, f));
  582. };
  583. /* istanbul ignore next */
  584. var _traverseWithIndex = function (F) {
  585. var traverseWithIndexF = (0, exports.traverseWithIndex)(F);
  586. return function (ta, f) { return (0, function_1.pipe)(ta, traverseWithIndexF(f)); };
  587. };
  588. /**
  589. * @category constructors
  590. * @since 2.5.0
  591. */
  592. exports.of = _.singleton;
  593. /**
  594. * Less strict version of [`alt`](#alt).
  595. *
  596. * The `W` suffix (short for **W**idening) means that the return types will be merged.
  597. *
  598. * @example
  599. * import * as RNEA from 'fp-ts/ReadonlyNonEmptyArray'
  600. * import { pipe } from 'fp-ts/function'
  601. *
  602. * assert.deepStrictEqual(
  603. * pipe(
  604. * [1, 2, 3] as RNEA.ReadonlyNonEmptyArray<number>,
  605. * RNEA.altW(() => ['a', 'b'])
  606. * ),
  607. * [1, 2, 3, 'a', 'b']
  608. * )
  609. *
  610. * @category error handling
  611. * @since 2.9.0
  612. */
  613. var altW = function (that) {
  614. return function (as) {
  615. return (0, function_1.pipe)(as, concatW(that()));
  616. };
  617. };
  618. exports.altW = altW;
  619. /**
  620. * Identifies an associative operation on a type constructor. It is similar to `Semigroup`, except that it applies to
  621. * types of kind `* -> *`.
  622. *
  623. * In case of `ReadonlyNonEmptyArray` concatenates the inputs into a single array.
  624. *
  625. * @example
  626. * import * as RNEA from 'fp-ts/ReadonlyNonEmptyArray'
  627. * import { pipe } from 'fp-ts/function'
  628. *
  629. * assert.deepStrictEqual(
  630. * pipe(
  631. * [1, 2, 3],
  632. * RNEA.alt(() => [4, 5])
  633. * ),
  634. * [1, 2, 3, 4, 5]
  635. * )
  636. *
  637. * @category error handling
  638. * @since 2.6.2
  639. */
  640. exports.alt = exports.altW;
  641. /**
  642. * @since 2.5.0
  643. */
  644. var ap = function (as) { return (0, exports.chain)(function (f) { return (0, function_1.pipe)(as, (0, exports.map)(f)); }); };
  645. exports.ap = ap;
  646. /**
  647. * Composes computations in sequence, using the return value of one computation to determine the next computation.
  648. *
  649. * @example
  650. * import * as RNEA from 'fp-ts/ReadonlyNonEmptyArray'
  651. * import { pipe } from 'fp-ts/function'
  652. *
  653. * assert.deepStrictEqual(
  654. * pipe(
  655. * [1, 2, 3],
  656. * RNEA.chain((n) => [`a${n}`, `b${n}`])
  657. * ),
  658. * ['a1', 'b1', 'a2', 'b2', 'a3', 'b3']
  659. * )
  660. *
  661. * @category sequencing
  662. * @since 2.5.0
  663. */
  664. var chain = function (f) { return (0, exports.chainWithIndex)(function (_, a) { return f(a); }); };
  665. exports.chain = chain;
  666. /**
  667. * @since 2.5.0
  668. */
  669. var extend = function (f) {
  670. return function (as) {
  671. var next = (0, exports.tail)(as);
  672. var out = [f(as)];
  673. while ((0, exports.isNonEmpty)(next)) {
  674. out.push(f(next));
  675. next = (0, exports.tail)(next);
  676. }
  677. return out;
  678. };
  679. };
  680. exports.extend = extend;
  681. /**
  682. * @since 2.5.0
  683. */
  684. exports.duplicate =
  685. /*#__PURE__*/ (0, exports.extend)(function_1.identity);
  686. /**
  687. * @category sequencing
  688. * @since 2.5.0
  689. */
  690. exports.flatten =
  691. /*#__PURE__*/ (0, exports.chain)(function_1.identity);
  692. /**
  693. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  694. * use the type constructor `F` to represent some computational context.
  695. *
  696. * @category mapping
  697. * @since 2.5.0
  698. */
  699. var map = function (f) {
  700. return (0, exports.mapWithIndex)(function (_, a) { return f(a); });
  701. };
  702. exports.map = map;
  703. /**
  704. * @category mapping
  705. * @since 2.5.0
  706. */
  707. var mapWithIndex = function (f) {
  708. return function (as) {
  709. var out = [f(0, (0, exports.head)(as))];
  710. for (var i = 1; i < as.length; i++) {
  711. out.push(f(i, as[i]));
  712. }
  713. return out;
  714. };
  715. };
  716. exports.mapWithIndex = mapWithIndex;
  717. /**
  718. * @category folding
  719. * @since 2.5.0
  720. */
  721. var reduce = function (b, f) {
  722. return (0, exports.reduceWithIndex)(b, function (_, b, a) { return f(b, a); });
  723. };
  724. exports.reduce = reduce;
  725. /**
  726. * **Note**. The constraint is relaxed: a `Semigroup` instead of a `Monoid`.
  727. *
  728. * @category folding
  729. * @since 2.5.0
  730. */
  731. var foldMap = function (S) {
  732. return function (f) {
  733. return function (as) {
  734. return as.slice(1).reduce(function (s, a) { return S.concat(s, f(a)); }, f(as[0]));
  735. };
  736. };
  737. };
  738. exports.foldMap = foldMap;
  739. /**
  740. * @category folding
  741. * @since 2.5.0
  742. */
  743. var reduceRight = function (b, f) {
  744. return (0, exports.reduceRightWithIndex)(b, function (_, b, a) { return f(b, a); });
  745. };
  746. exports.reduceRight = reduceRight;
  747. /**
  748. * @category folding
  749. * @since 2.5.0
  750. */
  751. var reduceWithIndex = function (b, f) {
  752. return function (as) {
  753. return as.reduce(function (b, a, i) { return f(i, b, a); }, b);
  754. };
  755. };
  756. exports.reduceWithIndex = reduceWithIndex;
  757. /**
  758. * **Note**. The constraint is relaxed: a `Semigroup` instead of a `Monoid`.
  759. *
  760. * @category folding
  761. * @since 2.5.0
  762. */
  763. var foldMapWithIndex = function (S) {
  764. return function (f) {
  765. return function (as) {
  766. return as.slice(1).reduce(function (s, a, i) { return S.concat(s, f(i + 1, a)); }, f(0, as[0]));
  767. };
  768. };
  769. };
  770. exports.foldMapWithIndex = foldMapWithIndex;
  771. /**
  772. * @category folding
  773. * @since 2.5.0
  774. */
  775. var reduceRightWithIndex = function (b, f) {
  776. return function (as) {
  777. return as.reduceRight(function (b, a, i) { return f(i, a, b); }, b);
  778. };
  779. };
  780. exports.reduceRightWithIndex = reduceRightWithIndex;
  781. /**
  782. * @category traversing
  783. * @since 2.6.3
  784. */
  785. var traverse = function (F) {
  786. var traverseWithIndexF = (0, exports.traverseWithIndex)(F);
  787. return function (f) { return traverseWithIndexF(function (_, a) { return f(a); }); };
  788. };
  789. exports.traverse = traverse;
  790. /**
  791. * @category traversing
  792. * @since 2.6.3
  793. */
  794. var sequence = function (F) { return (0, exports.traverseWithIndex)(F)(function_1.SK); };
  795. exports.sequence = sequence;
  796. /**
  797. * @category sequencing
  798. * @since 2.6.3
  799. */
  800. var traverseWithIndex = function (F) {
  801. return function (f) {
  802. return function (as) {
  803. var out = F.map(f(0, (0, exports.head)(as)), exports.of);
  804. for (var i = 1; i < as.length; i++) {
  805. out = F.ap(F.map(out, function (bs) { return function (b) { return (0, function_1.pipe)(bs, (0, exports.append)(b)); }; }), f(i, as[i]));
  806. }
  807. return out;
  808. };
  809. };
  810. };
  811. exports.traverseWithIndex = traverseWithIndex;
  812. /**
  813. * @category Comonad
  814. * @since 2.6.3
  815. */
  816. exports.extract = _.head;
  817. /**
  818. * @category type lambdas
  819. * @since 2.5.0
  820. */
  821. exports.URI = 'ReadonlyNonEmptyArray';
  822. /**
  823. * @category instances
  824. * @since 2.5.0
  825. */
  826. var getShow = function (S) { return ({
  827. show: function (as) { return "[".concat(as.map(S.show).join(', '), "]"); }
  828. }); };
  829. exports.getShow = getShow;
  830. /**
  831. * Builds a `Semigroup` instance for `ReadonlyNonEmptyArray`
  832. *
  833. * @category instances
  834. * @since 2.5.0
  835. */
  836. var getSemigroup = function () { return ({
  837. concat: concat
  838. }); };
  839. exports.getSemigroup = getSemigroup;
  840. /**
  841. * @example
  842. * import { getEq } from 'fp-ts/ReadonlyNonEmptyArray'
  843. * import * as N from 'fp-ts/number'
  844. *
  845. * const E = getEq(N.Eq)
  846. * assert.strictEqual(E.equals([1, 2], [1, 2]), true)
  847. * assert.strictEqual(E.equals([1, 2], [1, 3]), false)
  848. *
  849. * @category instances
  850. * @since 2.5.0
  851. */
  852. var getEq = function (E) {
  853. return (0, Eq_1.fromEquals)(function (xs, ys) { return xs.length === ys.length && xs.every(function (x, i) { return E.equals(x, ys[i]); }); });
  854. };
  855. exports.getEq = getEq;
  856. /**
  857. * @since 2.11.0
  858. */
  859. var getUnionSemigroup = function (E) {
  860. var unionE = (0, exports.union)(E);
  861. return {
  862. concat: function (first, second) { return unionE(second)(first); }
  863. };
  864. };
  865. exports.getUnionSemigroup = getUnionSemigroup;
  866. /**
  867. * @category instances
  868. * @since 2.7.0
  869. */
  870. exports.Functor = {
  871. URI: exports.URI,
  872. map: _map
  873. };
  874. /**
  875. * @category mapping
  876. * @since 2.10.0
  877. */
  878. exports.flap = (0, Functor_1.flap)(exports.Functor);
  879. /**
  880. * @category instances
  881. * @since 2.10.0
  882. */
  883. exports.Pointed = {
  884. URI: exports.URI,
  885. of: exports.of
  886. };
  887. /**
  888. * @category instances
  889. * @since 2.7.0
  890. */
  891. exports.FunctorWithIndex = {
  892. URI: exports.URI,
  893. map: _map,
  894. mapWithIndex: _mapWithIndex
  895. };
  896. /**
  897. * @category instances
  898. * @since 2.10.0
  899. */
  900. exports.Apply = {
  901. URI: exports.URI,
  902. map: _map,
  903. ap: _ap
  904. };
  905. /**
  906. * Combine two effectful actions, keeping only the result of the first.
  907. *
  908. * @since 2.5.0
  909. */
  910. exports.apFirst = (0, Apply_1.apFirst)(exports.Apply);
  911. /**
  912. * Combine two effectful actions, keeping only the result of the second.
  913. *
  914. * @since 2.5.0
  915. */
  916. exports.apSecond = (0, Apply_1.apSecond)(exports.Apply);
  917. /**
  918. * @category instances
  919. * @since 2.7.0
  920. */
  921. exports.Applicative = {
  922. URI: exports.URI,
  923. map: _map,
  924. ap: _ap,
  925. of: exports.of
  926. };
  927. /**
  928. * @category instances
  929. * @since 2.10.0
  930. */
  931. exports.Chain = {
  932. URI: exports.URI,
  933. map: _map,
  934. ap: _ap,
  935. chain: _chain
  936. };
  937. /**
  938. * Composes computations in sequence, using the return value of one computation to determine the next computation and
  939. * keeping only the result of the first.
  940. *
  941. * @example
  942. * import * as RA from 'fp-ts/ReadonlyArray'
  943. * import { pipe } from 'fp-ts/function'
  944. *
  945. * assert.deepStrictEqual(
  946. * pipe(
  947. * [1, 2, 3],
  948. * RA.chainFirst(() => ['a', 'b'])
  949. * ),
  950. * [1, 1, 2, 2, 3, 3]
  951. * )
  952. *
  953. * @category sequencing
  954. * @since 2.5.0
  955. */
  956. exports.chainFirst = (0, Chain_1.chainFirst)(exports.Chain);
  957. /**
  958. * @category instances
  959. * @since 2.7.0
  960. */
  961. exports.Monad = {
  962. URI: exports.URI,
  963. map: _map,
  964. ap: _ap,
  965. of: exports.of,
  966. chain: _chain
  967. };
  968. /**
  969. * @category instances
  970. * @since 2.7.0
  971. */
  972. exports.Foldable = {
  973. URI: exports.URI,
  974. reduce: _reduce,
  975. foldMap: _foldMap,
  976. reduceRight: _reduceRight
  977. };
  978. /**
  979. * @category instances
  980. * @since 2.7.0
  981. */
  982. exports.FoldableWithIndex = {
  983. URI: exports.URI,
  984. reduce: _reduce,
  985. foldMap: _foldMap,
  986. reduceRight: _reduceRight,
  987. reduceWithIndex: _reduceWithIndex,
  988. foldMapWithIndex: _foldMapWithIndex,
  989. reduceRightWithIndex: _reduceRightWithIndex
  990. };
  991. /**
  992. * @category instances
  993. * @since 2.7.0
  994. */
  995. exports.Traversable = {
  996. URI: exports.URI,
  997. map: _map,
  998. reduce: _reduce,
  999. foldMap: _foldMap,
  1000. reduceRight: _reduceRight,
  1001. traverse: _traverse,
  1002. sequence: exports.sequence
  1003. };
  1004. /**
  1005. * @category instances
  1006. * @since 2.7.0
  1007. */
  1008. exports.TraversableWithIndex = {
  1009. URI: exports.URI,
  1010. map: _map,
  1011. mapWithIndex: _mapWithIndex,
  1012. reduce: _reduce,
  1013. foldMap: _foldMap,
  1014. reduceRight: _reduceRight,
  1015. traverse: _traverse,
  1016. sequence: exports.sequence,
  1017. reduceWithIndex: _reduceWithIndex,
  1018. foldMapWithIndex: _foldMapWithIndex,
  1019. reduceRightWithIndex: _reduceRightWithIndex,
  1020. traverseWithIndex: _traverseWithIndex
  1021. };
  1022. /**
  1023. * @category instances
  1024. * @since 2.7.0
  1025. */
  1026. exports.Alt = {
  1027. URI: exports.URI,
  1028. map: _map,
  1029. alt: _alt
  1030. };
  1031. /**
  1032. * @category instances
  1033. * @since 2.7.0
  1034. */
  1035. exports.Comonad = {
  1036. URI: exports.URI,
  1037. map: _map,
  1038. extend: _extend,
  1039. extract: exports.extract
  1040. };
  1041. // -------------------------------------------------------------------------------------
  1042. // do notation
  1043. // -------------------------------------------------------------------------------------
  1044. /**
  1045. * @category do notation
  1046. * @since 2.9.0
  1047. */
  1048. exports.Do = (0, exports.of)(_.emptyRecord);
  1049. /**
  1050. * @category do notation
  1051. * @since 2.8.0
  1052. */
  1053. exports.bindTo = (0, Functor_1.bindTo)(exports.Functor);
  1054. var let_ = /*#__PURE__*/ (0, Functor_1.let)(exports.Functor);
  1055. exports.let = let_;
  1056. /**
  1057. * @category do notation
  1058. * @since 2.8.0
  1059. */
  1060. exports.bind = (0, Chain_1.bind)(exports.Chain);
  1061. /**
  1062. * @category do notation
  1063. * @since 2.8.0
  1064. */
  1065. exports.apS = (0, Apply_1.apS)(exports.Apply);
  1066. // -------------------------------------------------------------------------------------
  1067. // utils
  1068. // -------------------------------------------------------------------------------------
  1069. /**
  1070. * @since 2.5.0
  1071. */
  1072. exports.head = exports.extract;
  1073. /**
  1074. * @since 2.5.0
  1075. */
  1076. exports.tail = _.tail;
  1077. /**
  1078. * @since 2.5.0
  1079. */
  1080. var last = function (as) { return as[as.length - 1]; };
  1081. exports.last = last;
  1082. /**
  1083. * Get all but the last element of a non empty array, creating a new array.
  1084. *
  1085. * @example
  1086. * import { init } from 'fp-ts/ReadonlyNonEmptyArray'
  1087. *
  1088. * assert.deepStrictEqual(init([1, 2, 3]), [1, 2])
  1089. * assert.deepStrictEqual(init([1]), [])
  1090. *
  1091. * @since 2.5.0
  1092. */
  1093. var init = function (as) { return as.slice(0, -1); };
  1094. exports.init = init;
  1095. /**
  1096. * @since 2.5.0
  1097. */
  1098. var min = function (O) {
  1099. var S = Se.min(O);
  1100. return function (as) { return as.reduce(S.concat); };
  1101. };
  1102. exports.min = min;
  1103. /**
  1104. * @since 2.5.0
  1105. */
  1106. var max = function (O) {
  1107. var S = Se.max(O);
  1108. return function (as) { return as.reduce(S.concat); };
  1109. };
  1110. exports.max = max;
  1111. /**
  1112. * @since 2.10.0
  1113. */
  1114. var concatAll = function (S) {
  1115. return function (as) {
  1116. return as.reduce(S.concat);
  1117. };
  1118. };
  1119. exports.concatAll = concatAll;
  1120. /**
  1121. * Break a `ReadonlyArray` into its first element and remaining elements.
  1122. *
  1123. * @category pattern matching
  1124. * @since 2.11.0
  1125. */
  1126. var matchLeft = function (f) {
  1127. return function (as) {
  1128. return f((0, exports.head)(as), (0, exports.tail)(as));
  1129. };
  1130. };
  1131. exports.matchLeft = matchLeft;
  1132. /**
  1133. * Break a `ReadonlyArray` into its initial elements and the last element.
  1134. *
  1135. * @category pattern matching
  1136. * @since 2.11.0
  1137. */
  1138. var matchRight = function (f) {
  1139. return function (as) {
  1140. return f((0, exports.init)(as), (0, exports.last)(as));
  1141. };
  1142. };
  1143. exports.matchRight = matchRight;
  1144. /**
  1145. * Apply a function to the head, creating a new `ReadonlyNonEmptyArray`.
  1146. *
  1147. * @since 2.11.0
  1148. */
  1149. var modifyHead = function (f) {
  1150. return function (as) {
  1151. return __spreadArray([f((0, exports.head)(as))], (0, exports.tail)(as), true);
  1152. };
  1153. };
  1154. exports.modifyHead = modifyHead;
  1155. /**
  1156. * Change the head, creating a new `ReadonlyNonEmptyArray`.
  1157. *
  1158. * @since 2.11.0
  1159. */
  1160. var updateHead = function (a) { return (0, exports.modifyHead)(function () { return a; }); };
  1161. exports.updateHead = updateHead;
  1162. /**
  1163. * Apply a function to the last element, creating a new `ReadonlyNonEmptyArray`.
  1164. *
  1165. * @since 2.11.0
  1166. */
  1167. var modifyLast = function (f) {
  1168. return function (as) {
  1169. return (0, function_1.pipe)((0, exports.init)(as), (0, exports.append)(f((0, exports.last)(as))));
  1170. };
  1171. };
  1172. exports.modifyLast = modifyLast;
  1173. /**
  1174. * Change the last element, creating a new `ReadonlyNonEmptyArray`.
  1175. *
  1176. * @since 2.11.0
  1177. */
  1178. var updateLast = function (a) { return (0, exports.modifyLast)(function () { return a; }); };
  1179. exports.updateLast = updateLast;
  1180. /**
  1181. * Places an element in between members of a `ReadonlyNonEmptyArray`, then folds the results using the provided `Semigroup`.
  1182. *
  1183. * @example
  1184. * import * as S from 'fp-ts/string'
  1185. * import { intercalate } from 'fp-ts/ReadonlyNonEmptyArray'
  1186. *
  1187. * assert.deepStrictEqual(intercalate(S.Semigroup)('-')(['a', 'b', 'c']), 'a-b-c')
  1188. *
  1189. * @since 2.12.0
  1190. */
  1191. var intercalate = function (S) {
  1192. var concatAllS = (0, exports.concatAll)(S);
  1193. return function (middle) { return (0, function_1.flow)((0, exports.intersperse)(middle), concatAllS); };
  1194. };
  1195. exports.intercalate = intercalate;
  1196. function groupSort(O) {
  1197. var sortO = (0, exports.sort)(O);
  1198. var groupO = group(O);
  1199. return function (as) { return ((0, exports.isNonEmpty)(as) ? groupO(sortO(as)) : exports.empty); };
  1200. }
  1201. exports.groupSort = groupSort;
  1202. function filter(predicate) {
  1203. return (0, exports.filterWithIndex)(function (_, a) { return predicate(a); });
  1204. }
  1205. exports.filter = filter;
  1206. /**
  1207. * Use [`filterWithIndex`](./ReadonlyArray.ts.html#filterwithindex) instead.
  1208. *
  1209. * @category zone of death
  1210. * @since 2.5.0
  1211. * @deprecated
  1212. */
  1213. var filterWithIndex = function (predicate) {
  1214. return function (as) {
  1215. return (0, exports.fromReadonlyArray)(as.filter(function (a, i) { return predicate(i, a); }));
  1216. };
  1217. };
  1218. exports.filterWithIndex = filterWithIndex;
  1219. /**
  1220. * Use [`unprepend`](#unprepend) instead.
  1221. *
  1222. * @category zone of death
  1223. * @since 2.10.0
  1224. * @deprecated
  1225. */
  1226. exports.uncons = exports.unprepend;
  1227. /**
  1228. * Use [`unappend`](#unappend) instead.
  1229. *
  1230. * @category zone of death
  1231. * @since 2.10.0
  1232. * @deprecated
  1233. */
  1234. exports.unsnoc = exports.unappend;
  1235. function cons(head, tail) {
  1236. return tail === undefined ? (0, exports.prepend)(head) : (0, function_1.pipe)(tail, (0, exports.prepend)(head));
  1237. }
  1238. exports.cons = cons;
  1239. /**
  1240. * Use [`append`](./ReadonlyArray.ts.html#append) instead.
  1241. *
  1242. * @category zone of death
  1243. * @since 2.5.0
  1244. * @deprecated
  1245. */
  1246. var snoc = function (init, end) { return (0, function_1.pipe)(init, concat([end])); };
  1247. exports.snoc = snoc;
  1248. /**
  1249. * Use [`insertAt`](./ReadonlyArray.ts.html#insertat) instead.
  1250. *
  1251. * @category zone of death
  1252. * @since 2.5.0
  1253. * @deprecated
  1254. */
  1255. var insertAt = function (i, a) {
  1256. return function (as) {
  1257. return i < 0 || i > as.length ? _.none : _.some((0, exports.unsafeInsertAt)(i, a, as));
  1258. };
  1259. };
  1260. exports.insertAt = insertAt;
  1261. /**
  1262. * Use [`prependAll`](#prependall) instead.
  1263. *
  1264. * @category zone of death
  1265. * @since 2.9.0
  1266. * @deprecated
  1267. */
  1268. exports.prependToAll = exports.prependAll;
  1269. /**
  1270. * Use [`concatAll`](#concatall) instead.
  1271. *
  1272. * @category zone of death
  1273. * @since 2.5.0
  1274. * @deprecated
  1275. */
  1276. exports.fold = exports.concatAll;
  1277. /**
  1278. * This instance is deprecated, use small, specific instances instead.
  1279. * For example if a function needs a `Functor` instance, pass `RNEA.Functor` instead of `RNEA.readonlyNonEmptyArray`
  1280. * (where `RNEA` is from `import RNEA from 'fp-ts/ReadonlyNonEmptyArray'`)
  1281. *
  1282. * @category zone of death
  1283. * @since 2.5.0
  1284. * @deprecated
  1285. */
  1286. exports.readonlyNonEmptyArray = {
  1287. URI: exports.URI,
  1288. of: exports.of,
  1289. map: _map,
  1290. mapWithIndex: _mapWithIndex,
  1291. ap: _ap,
  1292. chain: _chain,
  1293. extend: _extend,
  1294. extract: exports.extract,
  1295. reduce: _reduce,
  1296. foldMap: _foldMap,
  1297. reduceRight: _reduceRight,
  1298. traverse: _traverse,
  1299. sequence: exports.sequence,
  1300. reduceWithIndex: _reduceWithIndex,
  1301. foldMapWithIndex: _foldMapWithIndex,
  1302. reduceRightWithIndex: _reduceRightWithIndex,
  1303. traverseWithIndex: _traverseWithIndex,
  1304. alt: _alt
  1305. };