版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

918 строки
26 KiB

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