版博士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.

NonEmptyArray.d.ts 23 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. /**
  2. * Data structure which represents non-empty arrays.
  3. *
  4. * ```ts
  5. * export type NonEmptyArray<A> = Array<A> & {
  6. * 0: A
  7. * }
  8. * ```
  9. *
  10. * Note that you don't need any conversion, a `NonEmptyArray` is an `Array`,
  11. * so all `Array`'s APIs can be used with a `NonEmptyArray` without further ado.
  12. *
  13. * @since 2.0.0
  14. */
  15. import { Alt1 } from './Alt'
  16. import { Applicative1 } from './Applicative'
  17. import { Apply1 } from './Apply'
  18. import { Chain1 } from './Chain'
  19. import { Comonad1 } from './Comonad'
  20. import { Endomorphism } from './Endomorphism'
  21. import { Eq } from './Eq'
  22. import { Foldable1 } from './Foldable'
  23. import { FoldableWithIndex1 } from './FoldableWithIndex'
  24. import { Lazy } from './function'
  25. import { Functor1 } from './Functor'
  26. import { FunctorWithIndex1 } from './FunctorWithIndex'
  27. import { Monad1 } from './Monad'
  28. import { Option } from './Option'
  29. import { Ord } from './Ord'
  30. import { Pointed1 } from './Pointed'
  31. import { Predicate } from './Predicate'
  32. import * as RNEA from './ReadonlyNonEmptyArray'
  33. import { Refinement } from './Refinement'
  34. import * as Se from './Semigroup'
  35. import { Show } from './Show'
  36. import { PipeableTraverse1, Traversable1 } from './Traversable'
  37. import { PipeableTraverseWithIndex1, TraversableWithIndex1 } from './TraversableWithIndex'
  38. import Semigroup = Se.Semigroup
  39. import ReadonlyNonEmptyArray = RNEA.ReadonlyNonEmptyArray
  40. /**
  41. * @category model
  42. * @since 2.0.0
  43. */
  44. export interface NonEmptyArray<A> extends Array<A> {
  45. 0: A
  46. }
  47. /**
  48. * Remove duplicates from a `NonEmptyArray`, keeping the first occurrence of an element.
  49. *
  50. * @example
  51. * import { uniq } from 'fp-ts/NonEmptyArray'
  52. * import * as N from 'fp-ts/number'
  53. *
  54. * assert.deepStrictEqual(uniq(N.Eq)([1, 2, 1]), [1, 2])
  55. *
  56. * @since 2.11.0
  57. */
  58. export declare const uniq: <A>(E: Eq<A>) => (as: NonEmptyArray<A>) => NonEmptyArray<A>
  59. /**
  60. * Sort the elements of a `NonEmptyArray` in increasing order, where elements are compared using first `ords[0]`, then `ords[1]`,
  61. * etc...
  62. *
  63. * @example
  64. * import * as NEA from 'fp-ts/NonEmptyArray'
  65. * import { contramap } from 'fp-ts/Ord'
  66. * import * as S from 'fp-ts/string'
  67. * import * as N from 'fp-ts/number'
  68. * import { pipe } from 'fp-ts/function'
  69. *
  70. * interface Person {
  71. * name: string
  72. * age: number
  73. * }
  74. *
  75. * const byName = pipe(S.Ord, contramap((p: Person) => p.name))
  76. *
  77. * const byAge = pipe(N.Ord, contramap((p: Person) => p.age))
  78. *
  79. * const sortByNameByAge = NEA.sortBy([byName, byAge])
  80. *
  81. * const persons: NEA.NonEmptyArray<Person> = [
  82. * { name: 'a', age: 1 },
  83. * { name: 'b', age: 3 },
  84. * { name: 'c', age: 2 },
  85. * { name: 'b', age: 2 }
  86. * ]
  87. *
  88. * assert.deepStrictEqual(sortByNameByAge(persons), [
  89. * { name: 'a', age: 1 },
  90. * { name: 'b', age: 2 },
  91. * { name: 'b', age: 3 },
  92. * { name: 'c', age: 2 }
  93. * ])
  94. *
  95. * @since 2.11.0
  96. */
  97. export declare const sortBy: <B>(ords: Ord<B>[]) => <A extends B>(as: NonEmptyArray<A>) => NonEmptyArray<A>
  98. /**
  99. * @since 2.11.0
  100. */
  101. export declare const union: <A>(E: Eq<A>) => (second: NonEmptyArray<A>) => (first: NonEmptyArray<A>) => NonEmptyArray<A>
  102. /**
  103. * Rotate a `NonEmptyArray` by `n` steps.
  104. *
  105. * @example
  106. * import { rotate } from 'fp-ts/NonEmptyArray'
  107. *
  108. * assert.deepStrictEqual(rotate(2)([1, 2, 3, 4, 5]), [4, 5, 1, 2, 3])
  109. * assert.deepStrictEqual(rotate(-2)([1, 2, 3, 4, 5]), [3, 4, 5, 1, 2])
  110. *
  111. * @since 2.11.0
  112. */
  113. export declare const rotate: (n: number) => <A>(as: NonEmptyArray<A>) => NonEmptyArray<A>
  114. /**
  115. * @category conversions
  116. * @since 2.10.0
  117. */
  118. export declare const fromReadonlyNonEmptyArray: <A>(as: ReadonlyNonEmptyArray<A>) => NonEmptyArray<A>
  119. /**
  120. * Builds a `NonEmptyArray` from an `Array` returning `none` if `as` is an empty array
  121. *
  122. * @category conversions
  123. * @since 2.0.0
  124. */
  125. export declare const fromArray: <A>(as: A[]) => Option<NonEmptyArray<A>>
  126. /**
  127. * Return a `NonEmptyArray` of length `n` with element `i` initialized with `f(i)`.
  128. *
  129. * **Note**. `n` is normalized to a natural number.
  130. *
  131. * @example
  132. * import { makeBy } from 'fp-ts/NonEmptyArray'
  133. * import { pipe } from 'fp-ts/function'
  134. *
  135. * const double = (n: number): number => n * 2
  136. * assert.deepStrictEqual(pipe(5, makeBy(double)), [0, 2, 4, 6, 8])
  137. *
  138. * @category constructors
  139. * @since 2.11.0
  140. */
  141. export declare const makeBy: <A>(f: (i: number) => A) => (n: number) => NonEmptyArray<A>
  142. /**
  143. * Create a `NonEmptyArray` containing a value repeated the specified number of times.
  144. *
  145. * **Note**. `n` is normalized to a natural number.
  146. *
  147. * @example
  148. * import { replicate } from 'fp-ts/NonEmptyArray'
  149. * import { pipe } from 'fp-ts/function'
  150. *
  151. * assert.deepStrictEqual(pipe(3, replicate('a')), ['a', 'a', 'a'])
  152. *
  153. * @category constructors
  154. * @since 2.11.0
  155. */
  156. export declare const replicate: <A>(a: A) => (n: number) => RNEA.ReadonlyNonEmptyArray<A>
  157. /**
  158. * Create a `NonEmptyArray` containing a range of integers, including both endpoints.
  159. *
  160. * @example
  161. * import { range } from 'fp-ts/NonEmptyArray'
  162. *
  163. * assert.deepStrictEqual(range(1, 5), [1, 2, 3, 4, 5])
  164. *
  165. * @category constructors
  166. * @since 2.11.0
  167. */
  168. export declare const range: (start: number, end: number) => NonEmptyArray<number>
  169. /**
  170. * Return the tuple of the `head` and the `tail`.
  171. *
  172. * @example
  173. * import { unprepend } from 'fp-ts/NonEmptyArray'
  174. *
  175. * assert.deepStrictEqual(unprepend([1, 2, 3]), [1, [2, 3]])
  176. *
  177. * @since 2.9.0
  178. */
  179. export declare const unprepend: <A>(as: NonEmptyArray<A>) => [A, A[]]
  180. /**
  181. * Return the tuple of the `init` and the `last`.
  182. *
  183. * @example
  184. * import { unappend } from 'fp-ts/NonEmptyArray'
  185. *
  186. * assert.deepStrictEqual(unappend([1, 2, 3, 4]), [[1, 2, 3], 4])
  187. *
  188. * @since 2.9.0
  189. */
  190. export declare const unappend: <A>(as: NonEmptyArray<A>) => [A[], A]
  191. /**
  192. * @since 2.11.0
  193. */
  194. export declare function concatW<B>(second: NonEmptyArray<B>): <A>(first: Array<A>) => NonEmptyArray<A | B>
  195. export declare function concatW<B>(second: Array<B>): <A>(first: NonEmptyArray<A>) => NonEmptyArray<A | B>
  196. /**
  197. * @since 2.2.0
  198. */
  199. export declare function concat<A>(second: NonEmptyArray<A>): (first: Array<A>) => NonEmptyArray<A>
  200. export declare function concat<A>(second: Array<A>): (first: NonEmptyArray<A>) => NonEmptyArray<A>
  201. /** @deprecated */
  202. export declare function concat<A>(first: Array<A>, second: NonEmptyArray<A>): NonEmptyArray<A>
  203. /** @deprecated */
  204. export declare function concat<A>(first: NonEmptyArray<A>, second: Array<A>): NonEmptyArray<A>
  205. /**
  206. * @since 2.0.0
  207. */
  208. export declare const reverse: <A>(as: NonEmptyArray<A>) => NonEmptyArray<A>
  209. /**
  210. * Group equal, consecutive elements of an array into non empty arrays.
  211. *
  212. * @example
  213. * import { group } from 'fp-ts/NonEmptyArray'
  214. * import * as N from 'fp-ts/number'
  215. *
  216. * assert.deepStrictEqual(group(N.Ord)([1, 2, 1, 1]), [
  217. * [1],
  218. * [2],
  219. * [1, 1]
  220. * ])
  221. *
  222. * @since 2.0.0
  223. */
  224. export declare function group<B>(E: Eq<B>): {
  225. <A extends B>(as: NonEmptyArray<A>): NonEmptyArray<NonEmptyArray<A>>
  226. <A extends B>(as: Array<A>): Array<NonEmptyArray<A>>
  227. }
  228. /**
  229. * Splits an array into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning
  230. * function on each element, and grouping the results according to values returned
  231. *
  232. * @example
  233. * import { groupBy } from 'fp-ts/NonEmptyArray'
  234. *
  235. * assert.deepStrictEqual(groupBy((s: string) => String(s.length))(['a', 'b', 'ab']), {
  236. * '1': ['a', 'b'],
  237. * '2': ['ab']
  238. * })
  239. *
  240. * @since 2.0.0
  241. */
  242. export declare const groupBy: <A>(f: (a: A) => string) => (as: A[]) => Record<string, NonEmptyArray<A>>
  243. /**
  244. * @since 2.0.0
  245. */
  246. export declare const sort: <B>(O: Ord<B>) => <A extends B>(as: NonEmptyArray<A>) => NonEmptyArray<A>
  247. /**
  248. * @since 2.0.0
  249. */
  250. export declare const insertAt: <A>(i: number, a: A) => (as: A[]) => Option<NonEmptyArray<A>>
  251. /**
  252. * @since 2.0.0
  253. */
  254. export declare const updateAt: <A>(i: number, a: A) => (as: NonEmptyArray<A>) => Option<NonEmptyArray<A>>
  255. /**
  256. * @since 2.0.0
  257. */
  258. export declare const modifyAt: <A>(i: number, f: (a: A) => A) => (as: NonEmptyArray<A>) => Option<NonEmptyArray<A>>
  259. /**
  260. * @since 2.0.0
  261. */
  262. export declare const copy: <A>(as: NonEmptyArray<A>) => NonEmptyArray<A>
  263. /**
  264. * @category constructors
  265. * @since 2.0.0
  266. */
  267. export declare const of: <A>(a: A) => NonEmptyArray<A>
  268. /**
  269. * @since 2.5.1
  270. */
  271. export declare const zipWith: <A, B, C>(
  272. as: NonEmptyArray<A>,
  273. bs: NonEmptyArray<B>,
  274. f: (a: A, b: B) => C
  275. ) => NonEmptyArray<C>
  276. /**
  277. * @since 2.5.1
  278. */
  279. export declare function zip<B>(bs: NonEmptyArray<B>): <A>(as: NonEmptyArray<A>) => NonEmptyArray<[A, B]>
  280. export declare function zip<A, B>(as: NonEmptyArray<A>, bs: NonEmptyArray<B>): NonEmptyArray<[A, B]>
  281. /**
  282. * @since 2.5.1
  283. */
  284. export declare const unzip: <A, B>(abs: NonEmptyArray<[A, B]>) => [NonEmptyArray<A>, NonEmptyArray<B>]
  285. /**
  286. * Prepend an element to every member of an array
  287. *
  288. * @example
  289. * import { prependAll } from 'fp-ts/NonEmptyArray'
  290. *
  291. * assert.deepStrictEqual(prependAll(9)([1, 2, 3, 4]), [9, 1, 9, 2, 9, 3, 9, 4])
  292. *
  293. * @since 2.10.0
  294. */
  295. export declare const prependAll: <A>(middle: A) => (as: NonEmptyArray<A>) => NonEmptyArray<A>
  296. /**
  297. * Places an element in between members of an array
  298. *
  299. * @example
  300. * import { intersperse } from 'fp-ts/NonEmptyArray'
  301. *
  302. * assert.deepStrictEqual(intersperse(9)([1, 2, 3, 4]), [1, 9, 2, 9, 3, 9, 4])
  303. *
  304. * @since 2.9.0
  305. */
  306. export declare const intersperse: <A>(middle: A) => (as: NonEmptyArray<A>) => NonEmptyArray<A>
  307. /**
  308. * @category folding
  309. * @since 2.0.0
  310. */
  311. export declare const foldMapWithIndex: <S>(
  312. S: Semigroup<S>
  313. ) => <A>(f: (i: number, a: A) => S) => (fa: NonEmptyArray<A>) => S
  314. /**
  315. * @category folding
  316. * @since 2.0.0
  317. */
  318. export declare const foldMap: <S>(S: Semigroup<S>) => <A>(f: (a: A) => S) => (fa: NonEmptyArray<A>) => S
  319. /**
  320. * @category sequencing
  321. * @since 2.10.0
  322. */
  323. export declare const chainWithIndex: <A, B>(
  324. f: (i: number, a: A) => NonEmptyArray<B>
  325. ) => (as: NonEmptyArray<A>) => NonEmptyArray<B>
  326. /**
  327. * @since 2.10.0
  328. */
  329. export declare const chop: <A, B>(f: (as: NonEmptyArray<A>) => [B, A[]]) => (as: NonEmptyArray<A>) => NonEmptyArray<B>
  330. /**
  331. * Splits a `NonEmptyArray` into two pieces, the first piece has max `n` elements.
  332. *
  333. * @since 2.10.0
  334. */
  335. export declare const splitAt: (n: number) => <A>(as: NonEmptyArray<A>) => [NonEmptyArray<A>, A[]]
  336. /**
  337. * @since 2.10.0
  338. */
  339. export declare const chunksOf: (n: number) => <A>(as: NonEmptyArray<A>) => NonEmptyArray<NonEmptyArray<A>>
  340. /**
  341. * Less strict version of [`alt`](#alt).
  342. *
  343. * The `W` suffix (short for **W**idening) means that the return types will be merged.
  344. *
  345. * @example
  346. * import * as NEA from 'fp-ts/NonEmptyArray'
  347. * import { pipe } from 'fp-ts/function'
  348. *
  349. * assert.deepStrictEqual(
  350. * pipe(
  351. * [1, 2, 3] as NEA.NonEmptyArray<number>,
  352. * NEA.altW(() => ['a', 'b'])
  353. * ),
  354. * [1, 2, 3, 'a', 'b']
  355. * )
  356. *
  357. * @category error handling
  358. * @since 2.9.0
  359. */
  360. export declare const altW: <B>(that: Lazy<NonEmptyArray<B>>) => <A>(as: NonEmptyArray<A>) => NonEmptyArray<B | A>
  361. /**
  362. * Identifies an associative operation on a type constructor. It is similar to `Semigroup`, except that it applies to
  363. * types of kind `* -> *`.
  364. *
  365. * In case of `NonEmptyArray` concatenates the inputs into a single array.
  366. *
  367. * @example
  368. * import * as NEA from 'fp-ts/NonEmptyArray'
  369. * import { pipe } from 'fp-ts/function'
  370. *
  371. * assert.deepStrictEqual(
  372. * pipe(
  373. * [1, 2, 3],
  374. * NEA.alt(() => [4, 5])
  375. * ),
  376. * [1, 2, 3, 4, 5]
  377. * )
  378. *
  379. * @category error handling
  380. * @since 2.6.2
  381. */
  382. export declare const alt: <A>(that: Lazy<NonEmptyArray<A>>) => (fa: NonEmptyArray<A>) => NonEmptyArray<A>
  383. /**
  384. * Apply a function to an argument under a type constructor.
  385. *
  386. * @since 2.0.0
  387. */
  388. export declare const ap: <A>(as: NonEmptyArray<A>) => <B>(fab: NonEmptyArray<(a: A) => B>) => NonEmptyArray<B>
  389. /**
  390. * Composes computations in sequence, using the return value of one computation to determine the next computation.
  391. *
  392. * @example
  393. * import * as NEA from 'fp-ts/NonEmptyArray'
  394. * import { pipe } from 'fp-ts/function'
  395. *
  396. * assert.deepStrictEqual(
  397. * pipe(
  398. * [1, 2, 3],
  399. * NEA.chain((n) => [`a${n}`, `b${n}`])
  400. * ),
  401. * ['a1', 'b1', 'a2', 'b2', 'a3', 'b3']
  402. * )
  403. *
  404. * @category sequencing
  405. * @since 2.0.0
  406. */
  407. export declare const chain: <A, B>(f: (a: A) => NonEmptyArray<B>) => (ma: NonEmptyArray<A>) => NonEmptyArray<B>
  408. /**
  409. * @since 2.0.0
  410. */
  411. export declare const extend: <A, B>(f: (as: NonEmptyArray<A>) => B) => (as: NonEmptyArray<A>) => NonEmptyArray<B>
  412. /**
  413. * @since 2.5.0
  414. */
  415. export declare const duplicate: <A>(ma: NonEmptyArray<A>) => NonEmptyArray<NonEmptyArray<A>>
  416. /**
  417. * @category sequencing
  418. * @since 2.5.0
  419. */
  420. export declare const flatten: <A>(mma: NonEmptyArray<NonEmptyArray<A>>) => NonEmptyArray<A>
  421. /**
  422. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  423. * use the type constructor `F` to represent some computational context.
  424. *
  425. * @category mapping
  426. * @since 2.0.0
  427. */
  428. export declare const map: <A, B>(f: (a: A) => B) => (as: NonEmptyArray<A>) => NonEmptyArray<B>
  429. /**
  430. * @category mapping
  431. * @since 2.0.0
  432. */
  433. export declare const mapWithIndex: <A, B>(f: (i: number, a: A) => B) => (as: NonEmptyArray<A>) => NonEmptyArray<B>
  434. /**
  435. * @category folding
  436. * @since 2.0.0
  437. */
  438. export declare const reduce: <A, B>(b: B, f: (b: B, a: A) => B) => (fa: NonEmptyArray<A>) => B
  439. /**
  440. * @category folding
  441. * @since 2.0.0
  442. */
  443. export declare const reduceWithIndex: <A, B>(b: B, f: (i: number, b: B, a: A) => B) => (fa: NonEmptyArray<A>) => B
  444. /**
  445. * @category folding
  446. * @since 2.0.0
  447. */
  448. export declare const reduceRight: <A, B>(b: B, f: (a: A, b: B) => B) => (fa: NonEmptyArray<A>) => B
  449. /**
  450. * @category folding
  451. * @since 2.0.0
  452. */
  453. export declare const reduceRightWithIndex: <A, B>(b: B, f: (i: number, a: A, b: B) => B) => (fa: NonEmptyArray<A>) => B
  454. /**
  455. * @category traversing
  456. * @since 2.6.3
  457. */
  458. export declare const traverse: PipeableTraverse1<URI>
  459. /**
  460. * @category traversing
  461. * @since 2.6.3
  462. */
  463. export declare const sequence: Traversable1<URI>['sequence']
  464. /**
  465. * @category sequencing
  466. * @since 2.6.3
  467. */
  468. export declare const traverseWithIndex: PipeableTraverseWithIndex1<URI, number>
  469. /**
  470. * @since 2.7.0
  471. */
  472. export declare const extract: Comonad1<URI>['extract']
  473. /**
  474. * @category type lambdas
  475. * @since 2.0.0
  476. */
  477. export declare const URI = 'NonEmptyArray'
  478. /**
  479. * @category type lambdas
  480. * @since 2.0.0
  481. */
  482. export declare type URI = typeof URI
  483. declare module './HKT' {
  484. interface URItoKind<A> {
  485. readonly [URI]: NonEmptyArray<A>
  486. }
  487. }
  488. /**
  489. * @category instances
  490. * @since 2.0.0
  491. */
  492. export declare const getShow: <A>(S: Show<A>) => Show<NonEmptyArray<A>>
  493. /**
  494. * Builds a `Semigroup` instance for `NonEmptyArray`
  495. *
  496. * @category instances
  497. * @since 2.0.0
  498. */
  499. export declare const getSemigroup: <A = never>() => Se.Semigroup<NonEmptyArray<A>>
  500. /**
  501. * @example
  502. * import { getEq } from 'fp-ts/NonEmptyArray'
  503. * import * as N from 'fp-ts/number'
  504. *
  505. * const E = getEq(N.Eq)
  506. * assert.strictEqual(E.equals([1, 2], [1, 2]), true)
  507. * assert.strictEqual(E.equals([1, 2], [1, 3]), false)
  508. *
  509. * @category instances
  510. * @since 2.0.0
  511. */
  512. export declare const getEq: <A>(E: Eq<A>) => Eq<NonEmptyArray<A>>
  513. /**
  514. * @since 2.11.0
  515. */
  516. export declare const getUnionSemigroup: <A>(E: Eq<A>) => Se.Semigroup<NonEmptyArray<A>>
  517. /**
  518. * @category instances
  519. * @since 2.7.0
  520. */
  521. export declare const Functor: Functor1<URI>
  522. /**
  523. * @category mapping
  524. * @since 2.10.0
  525. */
  526. export declare const flap: <A>(a: A) => <B>(fab: NonEmptyArray<(a: A) => B>) => NonEmptyArray<B>
  527. /**
  528. * @category instances
  529. * @since 2.10.0
  530. */
  531. export declare const Pointed: Pointed1<URI>
  532. /**
  533. * @category instances
  534. * @since 2.7.0
  535. */
  536. export declare const FunctorWithIndex: FunctorWithIndex1<URI, number>
  537. /**
  538. * @category instances
  539. * @since 2.10.0
  540. */
  541. export declare const Apply: Apply1<URI>
  542. /**
  543. * Combine two effectful actions, keeping only the result of the first.
  544. *
  545. * @since 2.5.0
  546. */
  547. export declare const apFirst: <B>(second: NonEmptyArray<B>) => <A>(first: NonEmptyArray<A>) => NonEmptyArray<A>
  548. /**
  549. * Combine two effectful actions, keeping only the result of the second.
  550. *
  551. * @since 2.5.0
  552. */
  553. export declare const apSecond: <B>(second: NonEmptyArray<B>) => <A>(first: NonEmptyArray<A>) => NonEmptyArray<B>
  554. /**
  555. * @category instances
  556. * @since 2.7.0
  557. */
  558. export declare const Applicative: Applicative1<URI>
  559. /**
  560. * @category instances
  561. * @since 2.10.0
  562. */
  563. export declare const Chain: Chain1<URI>
  564. /**
  565. * Composes computations in sequence, using the return value of one computation to determine the next computation and
  566. * keeping only the result of the first.
  567. *
  568. * @category sequencing
  569. * @since 2.5.0
  570. */
  571. export declare const chainFirst: <A, B>(f: (a: A) => NonEmptyArray<B>) => (first: NonEmptyArray<A>) => NonEmptyArray<A>
  572. /**
  573. * @category instances
  574. * @since 2.7.0
  575. */
  576. export declare const Monad: Monad1<URI>
  577. /**
  578. * @category instances
  579. * @since 2.7.0
  580. */
  581. export declare const Foldable: Foldable1<URI>
  582. /**
  583. * @category instances
  584. * @since 2.7.0
  585. */
  586. export declare const FoldableWithIndex: FoldableWithIndex1<URI, number>
  587. /**
  588. * @category instances
  589. * @since 2.7.0
  590. */
  591. export declare const Traversable: Traversable1<URI>
  592. /**
  593. * @category instances
  594. * @since 2.7.0
  595. */
  596. export declare const TraversableWithIndex: TraversableWithIndex1<URI, number>
  597. /**
  598. * @category instances
  599. * @since 2.7.0
  600. */
  601. export declare const Alt: Alt1<URI>
  602. /**
  603. * @category instances
  604. * @since 2.7.0
  605. */
  606. export declare const Comonad: Comonad1<URI>
  607. /**
  608. * @category do notation
  609. * @since 2.9.0
  610. */
  611. export declare const Do: NonEmptyArray<{}>
  612. /**
  613. * @category do notation
  614. * @since 2.8.0
  615. */
  616. export declare const bindTo: <N extends string>(
  617. name: N
  618. ) => <A>(fa: NonEmptyArray<A>) => NonEmptyArray<{ readonly [K in N]: A }>
  619. declare const let_: <N extends string, A, B>(
  620. name: Exclude<N, keyof A>,
  621. f: (a: A) => B
  622. ) => (fa: NonEmptyArray<A>) => NonEmptyArray<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
  623. export {
  624. /**
  625. * @category do notation
  626. * @since 2.13.0
  627. */
  628. let_ as let
  629. }
  630. /**
  631. * @category do notation
  632. * @since 2.8.0
  633. */
  634. export declare const bind: <N extends string, A, B>(
  635. name: Exclude<N, keyof A>,
  636. f: (a: A) => NonEmptyArray<B>
  637. ) => (ma: NonEmptyArray<A>) => NonEmptyArray<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
  638. /**
  639. * @category do notation
  640. * @since 2.8.0
  641. */
  642. export declare const apS: <N extends string, A, B>(
  643. name: Exclude<N, keyof A>,
  644. fb: NonEmptyArray<B>
  645. ) => (fa: NonEmptyArray<A>) => NonEmptyArray<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
  646. /**
  647. * @since 2.0.0
  648. */
  649. export declare const head: <A>(nea: NonEmptyArray<A>) => A
  650. /**
  651. * @since 2.0.0
  652. */
  653. export declare const tail: <A>(as: NonEmptyArray<A>) => A[]
  654. /**
  655. * @since 2.0.0
  656. */
  657. export declare const last: <A>(nea: NonEmptyArray<A>) => A
  658. /**
  659. * Get all but the last element of a non empty array, creating a new array.
  660. *
  661. * @example
  662. * import { init } from 'fp-ts/NonEmptyArray'
  663. *
  664. * assert.deepStrictEqual(init([1, 2, 3]), [1, 2])
  665. * assert.deepStrictEqual(init([1]), [])
  666. *
  667. * @since 2.2.0
  668. */
  669. export declare const init: <A>(as: NonEmptyArray<A>) => A[]
  670. /**
  671. * @since 2.0.0
  672. */
  673. export declare const min: <A>(ord: Ord<A>) => (nea: NonEmptyArray<A>) => A
  674. /**
  675. * @since 2.0.0
  676. */
  677. export declare const max: <A>(ord: Ord<A>) => (nea: NonEmptyArray<A>) => A
  678. /**
  679. * @since 2.10.0
  680. */
  681. export declare const concatAll: <A>(S: Se.Semigroup<A>) => (as: NonEmptyArray<A>) => A
  682. /**
  683. * Break an `Array` into its first element and remaining elements.
  684. *
  685. * @category pattern matching
  686. * @since 2.11.0
  687. */
  688. export declare const matchLeft: <A, B>(f: (head: A, tail: A[]) => B) => (as: NonEmptyArray<A>) => B
  689. /**
  690. * Break an `Array` into its initial elements and the last element.
  691. *
  692. * @category pattern matching
  693. * @since 2.11.0
  694. */
  695. export declare const matchRight: <A, B>(f: (init: A[], last: A) => B) => (as: NonEmptyArray<A>) => B
  696. /**
  697. * Apply a function to the head, creating a new `NonEmptyArray`.
  698. *
  699. * @since 2.11.0
  700. */
  701. export declare const modifyHead: <A>(f: Endomorphism<A>) => (as: NonEmptyArray<A>) => NonEmptyArray<A>
  702. /**
  703. * Change the head, creating a new `NonEmptyArray`.
  704. *
  705. * @since 2.11.0
  706. */
  707. export declare const updateHead: <A>(a: A) => (as: NonEmptyArray<A>) => NonEmptyArray<A>
  708. /**
  709. * Apply a function to the last element, creating a new `NonEmptyArray`.
  710. *
  711. * @since 2.11.0
  712. */
  713. export declare const modifyLast: <A>(f: Endomorphism<A>) => (as: NonEmptyArray<A>) => NonEmptyArray<A>
  714. /**
  715. * Change the last element, creating a new `NonEmptyArray`.
  716. *
  717. * @since 2.11.0
  718. */
  719. export declare const updateLast: <A>(a: A) => (as: NonEmptyArray<A>) => NonEmptyArray<A>
  720. /**
  721. * Places an element in between members of a `NonEmptyArray`, then folds the results using the provided `Semigroup`.
  722. *
  723. * @example
  724. * import * as S from 'fp-ts/string'
  725. * import { intercalate } from 'fp-ts/NonEmptyArray'
  726. *
  727. * assert.deepStrictEqual(intercalate(S.Semigroup)('-')(['a', 'b', 'c']), 'a-b-c')
  728. *
  729. * @since 2.12.0
  730. */
  731. export declare const intercalate: <A>(S: Semigroup<A>) => (middle: A) => (as: NonEmptyArray<A>) => A
  732. /**
  733. * This is just `sort` followed by `group`.
  734. *
  735. * @category zone of death
  736. * @since 2.0.0
  737. * @deprecated
  738. */
  739. export declare function groupSort<B>(O: Ord<B>): {
  740. <A extends B>(as: NonEmptyArray<A>): NonEmptyArray<NonEmptyArray<A>>
  741. <A extends B>(as: Array<A>): Array<NonEmptyArray<A>>
  742. }
  743. /**
  744. * Use [`filter`](./Array.ts.html#filter) instead.
  745. *
  746. * @category zone of death
  747. * @since 2.0.0
  748. * @deprecated
  749. */
  750. export declare function filter<A, B extends A>(
  751. refinement: Refinement<A, B>
  752. ): (as: NonEmptyArray<A>) => Option<NonEmptyArray<B>>
  753. export declare function filter<A>(
  754. predicate: Predicate<A>
  755. ): <B extends A>(bs: NonEmptyArray<B>) => Option<NonEmptyArray<B>>
  756. export declare function filter<A>(predicate: Predicate<A>): (as: NonEmptyArray<A>) => Option<NonEmptyArray<A>>
  757. /**
  758. * Use [`filterWithIndex`](./Array.ts.html#filterwithindex) instead.
  759. *
  760. * @category zone of death
  761. * @since 2.0.0
  762. * @deprecated
  763. */
  764. export declare const filterWithIndex: <A>(
  765. predicate: (i: number, a: A) => boolean
  766. ) => (as: NonEmptyArray<A>) => Option<NonEmptyArray<A>>
  767. /**
  768. * Use [`unprepend`](#unprepend) instead.
  769. *
  770. * @category zone of death
  771. * @since 2.9.0
  772. * @deprecated
  773. */
  774. export declare const uncons: <A>(as: NonEmptyArray<A>) => [A, Array<A>]
  775. /**
  776. * Use [`unappend`](#unappend) instead.
  777. *
  778. * @category zone of death
  779. * @since 2.9.0
  780. * @deprecated
  781. */
  782. export declare const unsnoc: <A>(as: NonEmptyArray<A>) => [Array<A>, A]
  783. /**
  784. * Use [`prepend`](./Array.ts.html#prepend) instead.
  785. *
  786. * @category zone of death
  787. * @since 2.0.0
  788. * @deprecated
  789. */
  790. export declare function cons<A>(head: A): (tail: Array<A>) => NonEmptyArray<A>
  791. /** @deprecated */
  792. export declare function cons<A>(head: A, tail: Array<A>): NonEmptyArray<A>
  793. /**
  794. * Use [`append`](./Array.ts.html#append) instead.
  795. *
  796. * @category zone of death
  797. * @since 2.0.0
  798. * @deprecated
  799. */
  800. export declare const snoc: <A>(init: A[], end: A) => NonEmptyArray<A>
  801. /**
  802. * Use [`prependAll`](#prependall) instead.
  803. *
  804. * @category zone of death
  805. * @since 2.9.0
  806. * @deprecated
  807. */
  808. export declare const prependToAll: <A>(middle: A) => (as: NonEmptyArray<A>) => NonEmptyArray<A>
  809. /**
  810. * Use [`concatAll`](#concatall) instead.
  811. *
  812. * @category zone of death
  813. * @since 2.5.0
  814. * @deprecated
  815. */
  816. export declare const fold: <A>(S: Semigroup<A>) => (fa: NonEmptyArray<A>) => A
  817. /**
  818. * This instance is deprecated, use small, specific instances instead.
  819. * For example if a function needs a `Functor` instance, pass `NEA.Functor` instead of `NEA.nonEmptyArray`
  820. * (where `NEA` is from `import NEA from 'fp-ts/NonEmptyArray'`)
  821. *
  822. * @category zone of death
  823. * @since 2.0.0
  824. * @deprecated
  825. */
  826. export declare const nonEmptyArray: Monad1<URI> &
  827. Comonad1<URI> &
  828. TraversableWithIndex1<URI, number> &
  829. FunctorWithIndex1<URI, number> &
  830. FoldableWithIndex1<URI, number> &
  831. Alt1<URI>