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

1682 строки
51 KiB

  1. /**
  2. * @since 2.5.0
  3. */
  4. import { Alt1 } from './Alt'
  5. import { Alternative1 } from './Alternative'
  6. import { Applicative1 } from './Applicative'
  7. import { Apply1 } from './Apply'
  8. import { Chain1 } from './Chain'
  9. import { ChainRec1 } from './ChainRec'
  10. import { Compactable1 } from './Compactable'
  11. import { Either } from './Either'
  12. import { Eq } from './Eq'
  13. import { Extend1 } from './Extend'
  14. import { Filterable1 } from './Filterable'
  15. import { FilterableWithIndex1, PredicateWithIndex, RefinementWithIndex } from './FilterableWithIndex'
  16. import { Foldable1 } from './Foldable'
  17. import { FoldableWithIndex1 } from './FoldableWithIndex'
  18. import { FromEither1 } from './FromEither'
  19. import { Lazy } from './function'
  20. import { Functor1 } from './Functor'
  21. import { FunctorWithIndex1 } from './FunctorWithIndex'
  22. import { Magma } from './Magma'
  23. import { Monad1 } from './Monad'
  24. import { Monoid } from './Monoid'
  25. import { Option } from './Option'
  26. import { Ord } from './Ord'
  27. import { Pointed1 } from './Pointed'
  28. import { Predicate } from './Predicate'
  29. import * as RNEA from './ReadonlyNonEmptyArray'
  30. import { Refinement } from './Refinement'
  31. import { Semigroup } from './Semigroup'
  32. import { Separated } from './Separated'
  33. import { Show } from './Show'
  34. import { PipeableTraverse1, Traversable1 } from './Traversable'
  35. import { PipeableTraverseWithIndex1, TraversableWithIndex1 } from './TraversableWithIndex'
  36. import { Unfoldable1 } from './Unfoldable'
  37. import { PipeableWilt1, PipeableWither1, Witherable1 } from './Witherable'
  38. import { Zero1 } from './Zero'
  39. import ReadonlyNonEmptyArray = RNEA.ReadonlyNonEmptyArray
  40. /**
  41. * Test whether a `ReadonlyArray` is empty.
  42. *
  43. * @example
  44. * import { isEmpty } from 'fp-ts/ReadonlyArray'
  45. *
  46. * assert.strictEqual(isEmpty([]), true)
  47. *
  48. * @category refinements
  49. * @since 2.5.0
  50. */
  51. export declare const isEmpty: <A>(as: readonly A[]) => as is readonly []
  52. /**
  53. * Test whether a `ReadonlyArray` is non empty.
  54. *
  55. * @category refinements
  56. * @since 2.5.0
  57. */
  58. export declare const isNonEmpty: <A>(as: ReadonlyArray<A>) => as is ReadonlyNonEmptyArray<A>
  59. /**
  60. * Prepend an element to the front of a `ReadonlyArray`, creating a new `ReadonlyNonEmptyArray`.
  61. *
  62. * @example
  63. * import { prepend } from 'fp-ts/ReadonlyArray'
  64. * import { pipe } from 'fp-ts/function'
  65. *
  66. * assert.deepStrictEqual(pipe([2, 3, 4], prepend(1)), [1, 2, 3, 4])
  67. *
  68. * @since 2.10.0
  69. */
  70. export declare const prepend: <A>(head: A) => (tail: readonly A[]) => RNEA.ReadonlyNonEmptyArray<A>
  71. /**
  72. * Less strict version of [`prepend`](#prepend).
  73. *
  74. * @since 2.11.0
  75. */
  76. export declare const prependW: <B>(head: B) => <A>(tail: readonly A[]) => RNEA.ReadonlyNonEmptyArray<B | A>
  77. /**
  78. * Append an element to the end of a `ReadonlyArray`, creating a new `ReadonlyNonEmptyArray`.
  79. *
  80. * @example
  81. * import { append } from 'fp-ts/ReadonlyArray'
  82. * import { pipe } from 'fp-ts/function'
  83. *
  84. * assert.deepStrictEqual(pipe([1, 2, 3], append(4)), [1, 2, 3, 4])
  85. *
  86. * @since 2.10.0
  87. */
  88. export declare const append: <A>(end: A) => (init: readonly A[]) => RNEA.ReadonlyNonEmptyArray<A>
  89. /**
  90. * Less strict version of [`append`](#append).
  91. *
  92. * @since 2.11.0
  93. */
  94. export declare const appendW: <B>(end: B) => <A>(init: readonly A[]) => RNEA.ReadonlyNonEmptyArray<B | A>
  95. /**
  96. * Return a `ReadonlyArray` of length `n` with element `i` initialized with `f(i)`.
  97. *
  98. * **Note**. `n` is normalized to a non negative integer.
  99. *
  100. * @example
  101. * import { makeBy } from 'fp-ts/ReadonlyArray'
  102. *
  103. * const double = (n: number): number => n * 2
  104. * assert.deepStrictEqual(makeBy(5, double), [0, 2, 4, 6, 8])
  105. *
  106. * @category constructors
  107. * @since 2.5.0
  108. */
  109. export declare const makeBy: <A>(n: number, f: (i: number) => A) => readonly A[]
  110. /**
  111. * Create a `ReadonlyArray` containing a value repeated the specified number of times.
  112. *
  113. * **Note**. `n` is normalized to a non negative integer.
  114. *
  115. * @example
  116. * import { replicate } from 'fp-ts/ReadonlyArray'
  117. *
  118. * assert.deepStrictEqual(replicate(3, 'a'), ['a', 'a', 'a'])
  119. *
  120. * @category constructors
  121. * @since 2.5.0
  122. */
  123. export declare const replicate: <A>(n: number, a: A) => readonly A[]
  124. /**
  125. * @category lifting
  126. * @since 2.11.0
  127. */
  128. export declare function fromPredicate<A, B extends A>(refinement: Refinement<A, B>): (a: A) => ReadonlyArray<B>
  129. export declare function fromPredicate<A>(predicate: Predicate<A>): <B extends A>(b: B) => ReadonlyArray<B>
  130. export declare function fromPredicate<A>(predicate: Predicate<A>): (a: A) => ReadonlyArray<A>
  131. /**
  132. * @category conversions
  133. * @since 2.11.0
  134. */
  135. export declare const fromOption: <A>(fa: Option<A>) => ReadonlyArray<A>
  136. /**
  137. * Transforms an `Either` to a `ReadonlyArray`.
  138. *
  139. * @category conversions
  140. * @since 2.11.0
  141. */
  142. export declare const fromEither: <A>(fa: Either<unknown, A>) => ReadonlyArray<A>
  143. /**
  144. * Less strict version of [`match`](#match).
  145. *
  146. * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
  147. *
  148. * @category pattern matching
  149. * @since 2.11.0
  150. */
  151. export declare const matchW: <B, A, C>(
  152. onEmpty: Lazy<B>,
  153. onNonEmpty: (as: RNEA.ReadonlyNonEmptyArray<A>) => C
  154. ) => (as: readonly A[]) => B | C
  155. /**
  156. * @category pattern matching
  157. * @since 2.11.0
  158. */
  159. export declare const match: <B, A>(
  160. onEmpty: Lazy<B>,
  161. onNonEmpty: (as: ReadonlyNonEmptyArray<A>) => B
  162. ) => (as: ReadonlyArray<A>) => B
  163. /**
  164. * Less strict version of [`matchLeft`](#matchleft).
  165. *
  166. * @category pattern matching
  167. * @since 2.11.0
  168. */
  169. export declare const matchLeftW: <B, A, C>(
  170. onEmpty: Lazy<B>,
  171. onNonEmpty: (head: A, tail: readonly A[]) => C
  172. ) => (as: readonly A[]) => B | C
  173. /**
  174. * Break a `ReadonlyArray` into its first element and remaining elements.
  175. *
  176. * @example
  177. * import { matchLeft } from 'fp-ts/ReadonlyArray'
  178. *
  179. * const len: <A>(as: ReadonlyArray<A>) => number = matchLeft(() => 0, (_, tail) => 1 + len(tail))
  180. * assert.strictEqual(len([1, 2, 3]), 3)
  181. *
  182. * @category pattern matching
  183. * @since 2.10.0
  184. */
  185. export declare const matchLeft: <B, A>(
  186. onEmpty: Lazy<B>,
  187. onNonEmpty: (head: A, tail: ReadonlyArray<A>) => B
  188. ) => (as: ReadonlyArray<A>) => B
  189. /**
  190. * Alias of [`matchLeft`](#matchleft).
  191. *
  192. * @category pattern matching
  193. * @since 2.5.0
  194. */
  195. export declare const foldLeft: <A, B>(
  196. onEmpty: Lazy<B>,
  197. onNonEmpty: (head: A, tail: ReadonlyArray<A>) => B
  198. ) => (as: ReadonlyArray<A>) => B
  199. /**
  200. * Less strict version of [`matchRight`](#matchright).
  201. *
  202. * @category pattern matching
  203. * @since 2.11.0
  204. */
  205. export declare const matchRightW: <B, A, C>(
  206. onEmpty: Lazy<B>,
  207. onNonEmpty: (init: readonly A[], last: A) => C
  208. ) => (as: readonly A[]) => B | C
  209. /**
  210. * Break a `ReadonlyArray` into its initial elements and the last element.
  211. *
  212. * @category pattern matching
  213. * @since 2.10.0
  214. */
  215. export declare const matchRight: <B, A>(
  216. onEmpty: Lazy<B>,
  217. onNonEmpty: (init: ReadonlyArray<A>, last: A) => B
  218. ) => (as: ReadonlyArray<A>) => B
  219. /**
  220. * Alias of [`matchRight`](#matchright).
  221. *
  222. * @category pattern matching
  223. * @since 2.5.0
  224. */
  225. export declare const foldRight: <A, B>(
  226. onEmpty: Lazy<B>,
  227. onNonEmpty: (init: ReadonlyArray<A>, last: A) => B
  228. ) => (as: ReadonlyArray<A>) => B
  229. /**
  230. * @category sequencing
  231. * @since 2.7.0
  232. */
  233. export declare const chainWithIndex: <A, B>(f: (i: number, a: A) => readonly B[]) => (as: readonly A[]) => readonly B[]
  234. /**
  235. * Same as `reduce` but it carries over the intermediate steps.
  236. *
  237. * @example
  238. * import { scanLeft } from 'fp-ts/ReadonlyArray'
  239. *
  240. * assert.deepStrictEqual(scanLeft(10, (b, a: number) => b - a)([1, 2, 3]), [10, 9, 7, 4])
  241. *
  242. * @since 2.5.0
  243. */
  244. export declare const scanLeft: <A, B>(b: B, f: (b: B, a: A) => B) => (as: readonly A[]) => RNEA.ReadonlyNonEmptyArray<B>
  245. /**
  246. * Fold an array from the right, keeping all intermediate results instead of only the final result
  247. *
  248. * @example
  249. * import { scanRight } from 'fp-ts/ReadonlyArray'
  250. *
  251. * assert.deepStrictEqual(scanRight(10, (a: number, b) => b - a)([1, 2, 3]), [4, 5, 7, 10])
  252. *
  253. * @since 2.5.0
  254. */
  255. export declare const scanRight: <A, B>(
  256. b: B,
  257. f: (a: A, b: B) => B
  258. ) => (as: readonly A[]) => RNEA.ReadonlyNonEmptyArray<B>
  259. /**
  260. * Calculate the number of elements in a `ReadonlyArray`.
  261. *
  262. * @since 2.10.0
  263. */
  264. export declare const size: <A>(as: readonly A[]) => number
  265. /**
  266. * Test whether an array contains a particular index
  267. *
  268. * @since 2.5.0
  269. */
  270. export declare const isOutOfBound: <A>(i: number, as: ReadonlyArray<A>) => boolean
  271. /**
  272. * This function provides a safe way to read a value at a particular index from an array
  273. *
  274. * @example
  275. * import { lookup } from 'fp-ts/ReadonlyArray'
  276. * import { some, none } from 'fp-ts/Option'
  277. * import { pipe } from 'fp-ts/function'
  278. *
  279. * assert.deepStrictEqual(pipe([1, 2, 3], lookup(1)), some(2))
  280. * assert.deepStrictEqual(pipe([1, 2, 3], lookup(3)), none)
  281. *
  282. * @since 2.5.0
  283. */
  284. export declare function lookup(i: number): <A>(as: ReadonlyArray<A>) => Option<A>
  285. export declare function lookup<A>(i: number, as: ReadonlyArray<A>): Option<A>
  286. /**
  287. * Get the first element in an array, or `None` if the array is empty
  288. *
  289. * @example
  290. * import { head } from 'fp-ts/ReadonlyArray'
  291. * import { some, none } from 'fp-ts/Option'
  292. *
  293. * assert.deepStrictEqual(head([1, 2, 3]), some(1))
  294. * assert.deepStrictEqual(head([]), none)
  295. *
  296. * @since 2.5.0
  297. */
  298. export declare const head: <A>(as: readonly A[]) => Option<A>
  299. /**
  300. * Get the last element in an array, or `None` if the array is empty
  301. *
  302. * @example
  303. * import { last } from 'fp-ts/ReadonlyArray'
  304. * import { some, none } from 'fp-ts/Option'
  305. *
  306. * assert.deepStrictEqual(last([1, 2, 3]), some(3))
  307. * assert.deepStrictEqual(last([]), none)
  308. *
  309. * @since 2.5.0
  310. */
  311. export declare const last: <A>(as: readonly A[]) => Option<A>
  312. /**
  313. * Get all but the first element of an array, creating a new array, or `None` if the array is empty
  314. *
  315. * @example
  316. * import { tail } from 'fp-ts/ReadonlyArray'
  317. * import { some, none } from 'fp-ts/Option'
  318. *
  319. * assert.deepStrictEqual(tail([1, 2, 3]), some([2, 3]))
  320. * assert.deepStrictEqual(tail([]), none)
  321. *
  322. * @since 2.5.0
  323. */
  324. export declare const tail: <A>(as: readonly A[]) => Option<readonly A[]>
  325. /**
  326. * Get all but the last element of an array, creating a new array, or `None` if the array is empty
  327. *
  328. * @example
  329. * import { init } from 'fp-ts/ReadonlyArray'
  330. * import { some, none } from 'fp-ts/Option'
  331. *
  332. * assert.deepStrictEqual(init([1, 2, 3]), some([1, 2]))
  333. * assert.deepStrictEqual(init([]), none)
  334. *
  335. * @since 2.5.0
  336. */
  337. export declare const init: <A>(as: readonly A[]) => Option<readonly A[]>
  338. /**
  339. * Keep only a max number of elements from the start of an `ReadonlyArray`, creating a new `ReadonlyArray`.
  340. *
  341. * **Note**. `n` is normalized to a non negative integer.
  342. *
  343. * @example
  344. * import * as RA from 'fp-ts/ReadonlyArray'
  345. * import { pipe } from 'fp-ts/function'
  346. *
  347. * const input: ReadonlyArray<number> = [1, 2, 3]
  348. * assert.deepStrictEqual(pipe(input, RA.takeLeft(2)), [1, 2])
  349. *
  350. * // out of bounds
  351. * assert.strictEqual(pipe(input, RA.takeLeft(4)), input)
  352. * assert.strictEqual(pipe(input, RA.takeLeft(-1)), input)
  353. *
  354. * @since 2.5.0
  355. */
  356. export declare const takeLeft: (n: number) => <A>(as: readonly A[]) => readonly A[]
  357. /**
  358. * Keep only a max number of elements from the end of an `ReadonlyArray`, creating a new `ReadonlyArray`.
  359. *
  360. * **Note**. `n` is normalized to a non negative integer.
  361. *
  362. * @example
  363. * import * as RA from 'fp-ts/ReadonlyArray'
  364. * import { pipe } from 'fp-ts/function'
  365. *
  366. * const input: ReadonlyArray<number> = [1, 2, 3]
  367. * assert.deepStrictEqual(pipe(input, RA.takeRight(2)), [2, 3])
  368. *
  369. * // out of bounds
  370. * assert.strictEqual(pipe(input, RA.takeRight(4)), input)
  371. * assert.strictEqual(pipe(input, RA.takeRight(-1)), input)
  372. *
  373. * @since 2.5.0
  374. */
  375. export declare const takeRight: (n: number) => <A>(as: readonly A[]) => readonly A[]
  376. /**
  377. * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new array
  378. *
  379. * @example
  380. * import { takeLeftWhile } from 'fp-ts/ReadonlyArray'
  381. *
  382. * assert.deepStrictEqual(takeLeftWhile((n: number) => n % 2 === 0)([2, 4, 3, 6]), [2, 4])
  383. *
  384. * @since 2.5.0
  385. */
  386. export declare function takeLeftWhile<A, B extends A>(
  387. refinement: Refinement<A, B>
  388. ): (as: ReadonlyArray<A>) => ReadonlyArray<B>
  389. export declare function takeLeftWhile<A>(
  390. predicate: Predicate<A>
  391. ): <B extends A>(bs: ReadonlyArray<B>) => ReadonlyArray<B>
  392. export declare function takeLeftWhile<A>(predicate: Predicate<A>): (as: ReadonlyArray<A>) => ReadonlyArray<A>
  393. /**
  394. * @since 2.5.0
  395. */
  396. export interface Spanned<I, R> {
  397. readonly init: ReadonlyArray<I>
  398. readonly rest: ReadonlyArray<R>
  399. }
  400. /**
  401. * Split an array into two parts:
  402. * 1. the longest initial subarray for which all elements satisfy the specified predicate
  403. * 2. the remaining elements
  404. *
  405. * @example
  406. * import { spanLeft } from 'fp-ts/ReadonlyArray'
  407. *
  408. * assert.deepStrictEqual(spanLeft((n: number) => n % 2 === 1)([1, 3, 2, 4, 5]), { init: [1, 3], rest: [2, 4, 5] })
  409. *
  410. * @since 2.5.0
  411. */
  412. export declare function spanLeft<A, B extends A>(refinement: Refinement<A, B>): (as: ReadonlyArray<A>) => Spanned<B, A>
  413. export declare function spanLeft<A>(predicate: Predicate<A>): <B extends A>(bs: ReadonlyArray<B>) => Spanned<B, B>
  414. export declare function spanLeft<A>(predicate: Predicate<A>): (as: ReadonlyArray<A>) => Spanned<A, A>
  415. /**
  416. * Drop a max number of elements from the start of an `ReadonlyArray`, creating a new `ReadonlyArray`.
  417. *
  418. * **Note**. `n` is normalized to a non negative integer.
  419. *
  420. * @example
  421. * import * as RA from 'fp-ts/ReadonlyArray'
  422. * import { pipe } from 'fp-ts/function'
  423. *
  424. * const input: ReadonlyArray<number> = [1, 2, 3]
  425. * assert.deepStrictEqual(pipe(input, RA.dropLeft(2)), [3])
  426. * assert.strictEqual(pipe(input, RA.dropLeft(0)), input)
  427. * assert.strictEqual(pipe(input, RA.dropLeft(-1)), input)
  428. *
  429. * @since 2.5.0
  430. */
  431. export declare const dropLeft: (n: number) => <A>(as: readonly A[]) => readonly A[]
  432. /**
  433. * Drop a max number of elements from the end of an `ReadonlyArray`, creating a new `ReadonlyArray`.
  434. *
  435. * **Note**. `n` is normalized to a non negative integer.
  436. *
  437. * @example
  438. * import * as RA from 'fp-ts/ReadonlyArray'
  439. * import { pipe } from 'fp-ts/function'
  440. *
  441. * const input: ReadonlyArray<number> = [1, 2, 3]
  442. * assert.deepStrictEqual(pipe(input, RA.dropRight(2)), [1])
  443. * assert.strictEqual(pipe(input, RA.dropRight(0)), input)
  444. * assert.strictEqual(pipe(input, RA.dropRight(-1)), input)
  445. *
  446. * @since 2.5.0
  447. */
  448. export declare const dropRight: (n: number) => <A>(as: readonly A[]) => readonly A[]
  449. /**
  450. * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new array
  451. *
  452. * @example
  453. * import { dropLeftWhile } from 'fp-ts/ReadonlyArray'
  454. *
  455. * assert.deepStrictEqual(dropLeftWhile((n: number) => n % 2 === 1)([1, 3, 2, 4, 5]), [2, 4, 5])
  456. *
  457. * @since 2.5.0
  458. */
  459. export declare function dropLeftWhile<A, B extends A>(
  460. refinement: Refinement<A, B>
  461. ): (as: ReadonlyArray<A>) => ReadonlyArray<B>
  462. export declare function dropLeftWhile<A>(
  463. predicate: Predicate<A>
  464. ): <B extends A>(bs: ReadonlyArray<B>) => ReadonlyArray<B>
  465. export declare function dropLeftWhile<A>(predicate: Predicate<A>): (as: ReadonlyArray<A>) => ReadonlyArray<A>
  466. /**
  467. * Find the first index for which a predicate holds
  468. *
  469. * @example
  470. * import { findIndex } from 'fp-ts/ReadonlyArray'
  471. * import { some, none } from 'fp-ts/Option'
  472. *
  473. * assert.deepStrictEqual(findIndex((n: number) => n === 2)([1, 2, 3]), some(1))
  474. * assert.deepStrictEqual(findIndex((n: number) => n === 2)([]), none)
  475. *
  476. * @since 2.5.0
  477. */
  478. export declare const findIndex: <A>(predicate: Predicate<A>) => (as: readonly A[]) => Option<number>
  479. /**
  480. * Find the first element which satisfies a predicate (or a refinement) function
  481. *
  482. * @example
  483. * import { findFirst } from 'fp-ts/ReadonlyArray'
  484. * import { some } from 'fp-ts/Option'
  485. *
  486. * type X = {
  487. * readonly a: number
  488. * readonly b: number
  489. * }
  490. *
  491. * assert.deepStrictEqual(findFirst((x: X) => x.a === 1)([{ a: 1, b: 1 }, { a: 1, b: 2 }]), some({ a: 1, b: 1 }))
  492. *
  493. * @since 2.5.0
  494. */
  495. export declare function findFirst<A, B extends A>(refinement: Refinement<A, B>): (as: ReadonlyArray<A>) => Option<B>
  496. export declare function findFirst<A>(predicate: Predicate<A>): <B extends A>(bs: ReadonlyArray<B>) => Option<B>
  497. export declare function findFirst<A>(predicate: Predicate<A>): (as: ReadonlyArray<A>) => Option<A>
  498. /**
  499. * Find the first element returned by an option based selector function
  500. *
  501. * @example
  502. * import { findFirstMap } from 'fp-ts/ReadonlyArray'
  503. * import { some, none } from 'fp-ts/Option'
  504. *
  505. * interface Person {
  506. * readonly name: string
  507. * readonly age?: number
  508. * }
  509. *
  510. * const persons: ReadonlyArray<Person> = [{ name: 'John' }, { name: 'Mary', age: 45 }, { name: 'Joey', age: 28 }]
  511. *
  512. * // returns the name of the first person that has an age
  513. * assert.deepStrictEqual(findFirstMap((p: Person) => (p.age === undefined ? none : some(p.name)))(persons), some('Mary'))
  514. *
  515. * @since 2.5.0
  516. */
  517. export declare const findFirstMap: <A, B>(f: (a: A) => Option<B>) => (as: readonly A[]) => Option<B>
  518. /**
  519. * Find the last element which satisfies a predicate function
  520. *
  521. * @example
  522. * import { findLast } from 'fp-ts/ReadonlyArray'
  523. * import { some } from 'fp-ts/Option'
  524. *
  525. * type X = {
  526. * readonly a: number
  527. * readonly b: number
  528. * }
  529. *
  530. * assert.deepStrictEqual(findLast((x: X) => x.a === 1)([{ a: 1, b: 1 }, { a: 1, b: 2 }]), some({ a: 1, b: 2 }))
  531. *
  532. * @since 2.5.0
  533. */
  534. export declare function findLast<A, B extends A>(refinement: Refinement<A, B>): (as: ReadonlyArray<A>) => Option<B>
  535. export declare function findLast<A>(predicate: Predicate<A>): <B extends A>(bs: ReadonlyArray<B>) => Option<B>
  536. export declare function findLast<A>(predicate: Predicate<A>): (as: ReadonlyArray<A>) => Option<A>
  537. /**
  538. * Find the last element returned by an option based selector function
  539. *
  540. * @example
  541. * import { findLastMap } from 'fp-ts/ReadonlyArray'
  542. * import { some, none } from 'fp-ts/Option'
  543. *
  544. * interface Person {
  545. * readonly name: string
  546. * readonly age?: number
  547. * }
  548. *
  549. * const persons: ReadonlyArray<Person> = [{ name: 'John' }, { name: 'Mary', age: 45 }, { name: 'Joey', age: 28 }]
  550. *
  551. * // returns the name of the last person that has an age
  552. * assert.deepStrictEqual(findLastMap((p: Person) => (p.age === undefined ? none : some(p.name)))(persons), some('Joey'))
  553. *
  554. * @since 2.5.0
  555. */
  556. export declare const findLastMap: <A, B>(f: (a: A) => Option<B>) => (as: readonly A[]) => Option<B>
  557. /**
  558. * Returns the index of the last element of the list which matches the predicate
  559. *
  560. * @example
  561. * import { findLastIndex } from 'fp-ts/ReadonlyArray'
  562. * import { some, none } from 'fp-ts/Option'
  563. *
  564. * interface X {
  565. * readonly a: number
  566. * readonly b: number
  567. * }
  568. * const xs: ReadonlyArray<X> = [{ a: 1, b: 0 }, { a: 1, b: 1 }]
  569. * assert.deepStrictEqual(findLastIndex((x: { readonly a: number }) => x.a === 1)(xs), some(1))
  570. * assert.deepStrictEqual(findLastIndex((x: { readonly a: number }) => x.a === 4)(xs), none)
  571. *
  572. *
  573. * @since 2.5.0
  574. */
  575. export declare const findLastIndex: <A>(predicate: Predicate<A>) => (as: readonly A[]) => Option<number>
  576. /**
  577. * Insert an element at the specified index, creating a new array, or returning `None` if the index is out of bounds
  578. *
  579. * @example
  580. * import { insertAt } from 'fp-ts/ReadonlyArray'
  581. * import { some } from 'fp-ts/Option'
  582. *
  583. * assert.deepStrictEqual(insertAt(2, 5)([1, 2, 3, 4]), some([1, 2, 5, 3, 4]))
  584. *
  585. * @since 2.5.0
  586. */
  587. export declare const insertAt: <A>(i: number, a: A) => (as: readonly A[]) => Option<RNEA.ReadonlyNonEmptyArray<A>>
  588. /**
  589. * Change the element at the specified index, creating a new array, or returning `None` if the index is out of bounds
  590. *
  591. * @example
  592. * import { updateAt } from 'fp-ts/ReadonlyArray'
  593. * import { some, none } from 'fp-ts/Option'
  594. *
  595. * assert.deepStrictEqual(updateAt(1, 1)([1, 2, 3]), some([1, 1, 3]))
  596. * assert.deepStrictEqual(updateAt(1, 1)([]), none)
  597. *
  598. * @since 2.5.0
  599. */
  600. export declare const updateAt: <A>(i: number, a: A) => (as: readonly A[]) => Option<readonly A[]>
  601. /**
  602. * Delete the element at the specified index, creating a new array, or returning `None` if the index is out of bounds
  603. *
  604. * @example
  605. * import { deleteAt } from 'fp-ts/ReadonlyArray'
  606. * import { some, none } from 'fp-ts/Option'
  607. *
  608. * assert.deepStrictEqual(deleteAt(0)([1, 2, 3]), some([2, 3]))
  609. * assert.deepStrictEqual(deleteAt(1)([]), none)
  610. *
  611. * @since 2.5.0
  612. */
  613. export declare const deleteAt: (i: number) => <A>(as: readonly A[]) => Option<readonly A[]>
  614. /**
  615. * Apply a function to the element at the specified index, creating a new array, or returning `None` if the index is out
  616. * of bounds
  617. *
  618. * @example
  619. * import { modifyAt } from 'fp-ts/ReadonlyArray'
  620. * import { some, none } from 'fp-ts/Option'
  621. *
  622. * const double = (x: number): number => x * 2
  623. * assert.deepStrictEqual(modifyAt(1, double)([1, 2, 3]), some([1, 4, 3]))
  624. * assert.deepStrictEqual(modifyAt(1, double)([]), none)
  625. *
  626. * @since 2.5.0
  627. */
  628. export declare const modifyAt: <A>(i: number, f: (a: A) => A) => (as: readonly A[]) => Option<readonly A[]>
  629. /**
  630. * Reverse an array, creating a new array
  631. *
  632. * @example
  633. * import { reverse } from 'fp-ts/ReadonlyArray'
  634. *
  635. * assert.deepStrictEqual(reverse([1, 2, 3]), [3, 2, 1])
  636. *
  637. * @since 2.5.0
  638. */
  639. export declare const reverse: <A>(as: readonly A[]) => readonly A[]
  640. /**
  641. * Extracts from an array of `Either` all the `Right` elements. All the `Right` elements are extracted in order
  642. *
  643. * @example
  644. * import { rights } from 'fp-ts/ReadonlyArray'
  645. * import { right, left } from 'fp-ts/Either'
  646. *
  647. * assert.deepStrictEqual(rights([right(1), left('foo'), right(2)]), [1, 2])
  648. *
  649. * @since 2.5.0
  650. */
  651. export declare const rights: <E, A>(as: readonly Either<E, A>[]) => readonly A[]
  652. /**
  653. * Extracts from an array of `Either` all the `Left` elements. All the `Left` elements are extracted in order
  654. *
  655. * @example
  656. * import { lefts } from 'fp-ts/ReadonlyArray'
  657. * import { left, right } from 'fp-ts/Either'
  658. *
  659. * assert.deepStrictEqual(lefts([right(1), left('foo'), right(2)]), ['foo'])
  660. *
  661. * @since 2.5.0
  662. */
  663. export declare const lefts: <E, A>(as: readonly Either<E, A>[]) => readonly E[]
  664. /**
  665. * Sort the elements of an array in increasing order, creating a new array
  666. *
  667. * @example
  668. * import { sort } from 'fp-ts/ReadonlyArray'
  669. * import * as N from 'fp-ts/number'
  670. *
  671. * assert.deepStrictEqual(sort(N.Ord)([3, 2, 1]), [1, 2, 3])
  672. *
  673. * @since 2.5.0
  674. */
  675. export declare const sort: <B>(O: Ord<B>) => <A extends B>(as: readonly A[]) => readonly A[]
  676. /**
  677. * Apply a function to pairs of elements at the same index in two arrays, collecting the results in a new array. If one
  678. * input array is short, excess elements of the longer array are discarded.
  679. *
  680. * @example
  681. * import { zipWith } from 'fp-ts/ReadonlyArray'
  682. *
  683. * assert.deepStrictEqual(zipWith([1, 2, 3], ['a', 'b', 'c', 'd'], (n, s) => s + n), ['a1', 'b2', 'c3'])
  684. *
  685. * @since 2.5.0
  686. */
  687. export declare const zipWith: <A, B, C>(fa: readonly A[], fb: readonly B[], f: (a: A, b: B) => C) => readonly C[]
  688. /**
  689. * Takes two arrays and returns an array of corresponding pairs. If one input array is short, excess elements of the
  690. * longer array are discarded
  691. *
  692. * @example
  693. * import { zip } from 'fp-ts/ReadonlyArray'
  694. * import { pipe } from 'fp-ts/function'
  695. *
  696. * assert.deepStrictEqual(pipe([1, 2, 3], zip(['a', 'b', 'c', 'd'])), [[1, 'a'], [2, 'b'], [3, 'c']])
  697. *
  698. * @since 2.5.0
  699. */
  700. export declare function zip<B>(bs: ReadonlyArray<B>): <A>(as: ReadonlyArray<A>) => ReadonlyArray<readonly [A, B]>
  701. export declare function zip<A, B>(as: ReadonlyArray<A>, bs: ReadonlyArray<B>): ReadonlyArray<readonly [A, B]>
  702. /**
  703. * The function is reverse of `zip`. Takes an array of pairs and return two corresponding arrays
  704. *
  705. * @example
  706. * import { unzip } from 'fp-ts/ReadonlyArray'
  707. *
  708. * assert.deepStrictEqual(unzip([[1, 'a'], [2, 'b'], [3, 'c']]), [[1, 2, 3], ['a', 'b', 'c']])
  709. *
  710. * @since 2.5.0
  711. */
  712. export declare const unzip: <A, B>(as: readonly (readonly [A, B])[]) => readonly [readonly A[], readonly B[]]
  713. /**
  714. * Prepend an element to every member of an array
  715. *
  716. * @example
  717. * import { prependAll } from 'fp-ts/ReadonlyArray'
  718. *
  719. * assert.deepStrictEqual(prependAll(9)([1, 2, 3, 4]), [9, 1, 9, 2, 9, 3, 9, 4])
  720. *
  721. * @since 2.10.0
  722. */
  723. export declare const prependAll: <A>(middle: A) => (as: readonly A[]) => readonly A[]
  724. /**
  725. * Places an element in between members of an array
  726. *
  727. * @example
  728. * import { intersperse } from 'fp-ts/ReadonlyArray'
  729. *
  730. * assert.deepStrictEqual(intersperse(9)([1, 2, 3, 4]), [1, 9, 2, 9, 3, 9, 4])
  731. *
  732. * @since 2.9.0
  733. */
  734. export declare const intersperse: <A>(middle: A) => (as: readonly A[]) => readonly A[]
  735. /**
  736. * Rotate a `ReadonlyArray` by `n` steps.
  737. *
  738. * @example
  739. * import { rotate } from 'fp-ts/ReadonlyArray'
  740. *
  741. * assert.deepStrictEqual(rotate(2)([1, 2, 3, 4, 5]), [4, 5, 1, 2, 3])
  742. *
  743. * @since 2.5.0
  744. */
  745. export declare const rotate: (n: number) => <A>(as: readonly A[]) => readonly A[]
  746. /**
  747. * Test if a value is a member of an array. Takes a `Eq<A>` as a single
  748. * argument which returns the function to use to search for a value of type `A` in
  749. * an array of type `ReadonlyArray<A>`.
  750. *
  751. * @example
  752. * import { elem } from 'fp-ts/ReadonlyArray'
  753. * import * as N from 'fp-ts/number'
  754. * import { pipe } from 'fp-ts/function'
  755. *
  756. * assert.strictEqual(pipe([1, 2, 3], elem(N.Eq)(2)), true)
  757. * assert.strictEqual(pipe([1, 2, 3], elem(N.Eq)(0)), false)
  758. *
  759. * @since 2.5.0
  760. */
  761. export declare function elem<A>(E: Eq<A>): {
  762. (a: A): (as: ReadonlyArray<A>) => boolean
  763. (a: A, as: ReadonlyArray<A>): boolean
  764. }
  765. /**
  766. * Remove duplicates from an array, keeping the first occurrence of an element.
  767. *
  768. * @example
  769. * import { uniq } from 'fp-ts/ReadonlyArray'
  770. * import * as N from 'fp-ts/number'
  771. *
  772. * assert.deepStrictEqual(uniq(N.Eq)([1, 2, 1]), [1, 2])
  773. *
  774. * @since 2.5.0
  775. */
  776. export declare const uniq: <A>(E: Eq<A>) => (as: readonly A[]) => readonly A[]
  777. /**
  778. * Sort the elements of an array in increasing order, where elements are compared using first `ords[0]`, then `ords[1]`,
  779. * etc...
  780. *
  781. * @example
  782. * import { sortBy } from 'fp-ts/ReadonlyArray'
  783. * import { contramap } from 'fp-ts/Ord'
  784. * import * as S from 'fp-ts/string'
  785. * import * as N from 'fp-ts/number'
  786. * import { pipe } from 'fp-ts/function'
  787. *
  788. * interface Person {
  789. * readonly name: string
  790. * readonly age: number
  791. * }
  792. * const byName = pipe(S.Ord, contramap((p: Person) => p.name))
  793. * const byAge = pipe(N.Ord, contramap((p: Person) => p.age))
  794. *
  795. * const sortByNameByAge = sortBy([byName, byAge])
  796. *
  797. * const persons = [{ name: 'a', age: 1 }, { name: 'b', age: 3 }, { name: 'c', age: 2 }, { name: 'b', age: 2 }]
  798. * assert.deepStrictEqual(sortByNameByAge(persons), [
  799. * { name: 'a', age: 1 },
  800. * { name: 'b', age: 2 },
  801. * { name: 'b', age: 3 },
  802. * { name: 'c', age: 2 }
  803. * ])
  804. *
  805. * @since 2.5.0
  806. */
  807. export declare const sortBy: <B>(ords: readonly Ord<B>[]) => <A extends B>(as: readonly A[]) => readonly A[]
  808. /**
  809. * A useful recursion pattern for processing a `ReadonlyArray` to produce a new `ReadonlyArray`, often used for "chopping" up the input
  810. * `ReadonlyArray`. Typically `chop` is called with some function that will consume an initial prefix of the `ReadonlyArray` and produce a
  811. * value and the tail of the `ReadonlyArray`.
  812. *
  813. * @example
  814. * import { Eq } from 'fp-ts/Eq'
  815. * import * as RA from 'fp-ts/ReadonlyArray'
  816. * import * as N from 'fp-ts/number'
  817. * import { pipe } from 'fp-ts/function'
  818. *
  819. * const group = <A>(S: Eq<A>): ((as: ReadonlyArray<A>) => ReadonlyArray<ReadonlyArray<A>>) => {
  820. * return RA.chop(as => {
  821. * const { init, rest } = pipe(as, RA.spanLeft((a: A) => S.equals(a, as[0])))
  822. * return [init, rest]
  823. * })
  824. * }
  825. * assert.deepStrictEqual(group(N.Eq)([1, 1, 2, 3, 3, 4]), [[1, 1], [2], [3, 3], [4]])
  826. *
  827. * @since 2.5.0
  828. */
  829. export declare const chop: <A, B>(
  830. f: (as: RNEA.ReadonlyNonEmptyArray<A>) => readonly [B, readonly A[]]
  831. ) => (as: readonly A[]) => readonly B[]
  832. /**
  833. * Splits a `ReadonlyArray` into two pieces, the first piece has max `n` elements.
  834. *
  835. * @example
  836. * import { splitAt } from 'fp-ts/ReadonlyArray'
  837. *
  838. * assert.deepStrictEqual(splitAt(2)([1, 2, 3, 4, 5]), [[1, 2], [3, 4, 5]])
  839. *
  840. * @since 2.5.0
  841. */
  842. export declare const splitAt: (n: number) => <A>(as: readonly A[]) => readonly [readonly A[], readonly A[]]
  843. /**
  844. * Splits a `ReadonlyArray` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
  845. * the `ReadonlyArray`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive
  846. * definition of `chunksOf`; it satisfies the property that:
  847. *
  848. * ```ts
  849. * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))
  850. * ```
  851. *
  852. * whenever `n` evenly divides the length of `as`.
  853. *
  854. * @example
  855. * import { chunksOf } from 'fp-ts/ReadonlyArray'
  856. *
  857. * assert.deepStrictEqual(chunksOf(2)([1, 2, 3, 4, 5]), [[1, 2], [3, 4], [5]])
  858. *
  859. * @since 2.5.0
  860. */
  861. export declare const chunksOf: (n: number) => <A>(as: readonly A[]) => readonly RNEA.ReadonlyNonEmptyArray<A>[]
  862. /**
  863. * @category lifting
  864. * @since 2.11.0
  865. */
  866. export declare const fromOptionK: <A extends readonly unknown[], B>(
  867. f: (...a: A) => Option<B>
  868. ) => (...a: A) => readonly B[]
  869. /**
  870. * `ReadonlyArray` comprehension.
  871. *
  872. * ```
  873. * [ f(x, y, ...) | x ← xs, y ← ys, ..., g(x, y, ...) ]
  874. * ```
  875. *
  876. * @example
  877. * import { comprehension } from 'fp-ts/ReadonlyArray'
  878. * import { tuple } from 'fp-ts/function'
  879. *
  880. * assert.deepStrictEqual(comprehension([[1, 2, 3], ['a', 'b']], tuple, (a, b) => (a + b.length) % 2 === 0), [
  881. * [1, 'a'],
  882. * [1, 'b'],
  883. * [3, 'a'],
  884. * [3, 'b']
  885. * ])
  886. *
  887. * @since 2.5.0
  888. */
  889. export declare function comprehension<A, B, C, D, R>(
  890. input: readonly [ReadonlyArray<A>, ReadonlyArray<B>, ReadonlyArray<C>, ReadonlyArray<D>],
  891. f: (a: A, b: B, c: C, d: D) => R,
  892. g?: (a: A, b: B, c: C, d: D) => boolean
  893. ): ReadonlyArray<R>
  894. export declare function comprehension<A, B, C, R>(
  895. input: readonly [ReadonlyArray<A>, ReadonlyArray<B>, ReadonlyArray<C>],
  896. f: (a: A, b: B, c: C) => R,
  897. g?: (a: A, b: B, c: C) => boolean
  898. ): ReadonlyArray<R>
  899. export declare function comprehension<A, B, R>(
  900. input: readonly [ReadonlyArray<A>, ReadonlyArray<B>],
  901. f: (a: A, b: B) => R,
  902. g?: (a: A, b: B) => boolean
  903. ): ReadonlyArray<R>
  904. export declare function comprehension<A, R>(
  905. input: readonly [ReadonlyArray<A>],
  906. f: (a: A) => R,
  907. g?: (a: A) => boolean
  908. ): ReadonlyArray<R>
  909. /**
  910. * @since 2.11.0
  911. */
  912. export declare const concatW: <B>(second: readonly B[]) => <A>(first: readonly A[]) => readonly (B | A)[]
  913. /**
  914. * @since 2.11.0
  915. */
  916. export declare const concat: <A>(second: ReadonlyArray<A>) => (first: ReadonlyArray<A>) => ReadonlyArray<A>
  917. /**
  918. * Creates an array of unique values, in order, from all given arrays using a `Eq` for equality comparisons
  919. *
  920. * @example
  921. * import { union } from 'fp-ts/ReadonlyArray'
  922. * import * as N from 'fp-ts/number'
  923. * import { pipe } from 'fp-ts/function'
  924. *
  925. * assert.deepStrictEqual(pipe([1, 2], union(N.Eq)([2, 3])), [1, 2, 3])
  926. *
  927. * @since 2.5.0
  928. */
  929. export declare function union<A>(E: Eq<A>): {
  930. (xs: ReadonlyArray<A>): (ys: ReadonlyArray<A>) => ReadonlyArray<A>
  931. (xs: ReadonlyArray<A>, ys: ReadonlyArray<A>): ReadonlyArray<A>
  932. }
  933. /**
  934. * Creates an array of unique values that are included in all given arrays using a `Eq` for equality
  935. * comparisons. The order and references of result values are determined by the first array.
  936. *
  937. * @example
  938. * import { intersection } from 'fp-ts/ReadonlyArray'
  939. * import * as N from 'fp-ts/number'
  940. * import { pipe } from 'fp-ts/function'
  941. *
  942. * assert.deepStrictEqual(pipe([1, 2], intersection(N.Eq)([2, 3])), [2])
  943. *
  944. * @since 2.5.0
  945. */
  946. export declare function intersection<A>(E: Eq<A>): {
  947. (xs: ReadonlyArray<A>): (ys: ReadonlyArray<A>) => ReadonlyArray<A>
  948. (xs: ReadonlyArray<A>, ys: ReadonlyArray<A>): ReadonlyArray<A>
  949. }
  950. /**
  951. * Creates an array of array values not included in the other given array using a `Eq` for equality
  952. * comparisons. The order and references of result values are determined by the first array.
  953. *
  954. * @example
  955. * import { difference } from 'fp-ts/ReadonlyArray'
  956. * import * as N from 'fp-ts/number'
  957. * import { pipe } from 'fp-ts/function'
  958. *
  959. * assert.deepStrictEqual(pipe([1, 2], difference(N.Eq)([2, 3])), [1])
  960. *
  961. * @since 2.5.0
  962. */
  963. export declare function difference<A>(E: Eq<A>): {
  964. (xs: ReadonlyArray<A>): (ys: ReadonlyArray<A>) => ReadonlyArray<A>
  965. (xs: ReadonlyArray<A>, ys: ReadonlyArray<A>): ReadonlyArray<A>
  966. }
  967. /**
  968. * @category constructors
  969. * @since 2.5.0
  970. */
  971. export declare const of: <A>(a: A) => ReadonlyArray<A>
  972. /**
  973. * @since 2.7.0
  974. */
  975. export declare const zero: <A>() => ReadonlyArray<A>
  976. /**
  977. * Less strict version of [`alt`](#alt).
  978. *
  979. * The `W` suffix (short for **W**idening) means that the return types will be merged.
  980. *
  981. * @example
  982. * import * as RA from 'fp-ts/ReadonlyArray'
  983. * import { pipe } from 'fp-ts/function'
  984. *
  985. * assert.deepStrictEqual(
  986. * pipe(
  987. * [1, 2, 3],
  988. * RA.altW(() => ['a', 'b'])
  989. * ),
  990. * [1, 2, 3, 'a', 'b']
  991. * )
  992. *
  993. * @category error handling
  994. * @since 2.9.0
  995. */
  996. export declare const altW: <B>(that: Lazy<readonly B[]>) => <A>(fa: readonly A[]) => readonly (B | A)[]
  997. /**
  998. * Identifies an associative operation on a type constructor. It is similar to `Semigroup`, except that it applies to
  999. * types of kind `* -> *`.
  1000. *
  1001. * In case of `ReadonlyArray` concatenates the inputs into a single array.
  1002. *
  1003. * @example
  1004. * import * as RA from 'fp-ts/ReadonlyArray'
  1005. * import { pipe } from 'fp-ts/function'
  1006. *
  1007. * assert.deepStrictEqual(
  1008. * pipe(
  1009. * [1, 2, 3],
  1010. * RA.alt(() => [4, 5])
  1011. * ),
  1012. * [1, 2, 3, 4, 5]
  1013. * )
  1014. *
  1015. * @category error handling
  1016. * @since 2.5.0
  1017. */
  1018. export declare const alt: <A>(that: Lazy<ReadonlyArray<A>>) => (fa: ReadonlyArray<A>) => ReadonlyArray<A>
  1019. /**
  1020. * @since 2.5.0
  1021. */
  1022. export declare const ap: <A>(fa: ReadonlyArray<A>) => <B>(fab: ReadonlyArray<(a: A) => B>) => ReadonlyArray<B>
  1023. /**
  1024. * Composes computations in sequence, using the return value of one computation to determine the next computation.
  1025. *
  1026. * @example
  1027. * import * as RA from 'fp-ts/ReadonlyArray'
  1028. * import { pipe } from 'fp-ts/function'
  1029. *
  1030. * assert.deepStrictEqual(
  1031. * pipe(
  1032. * [1, 2, 3],
  1033. * RA.chain((n) => [`a${n}`, `b${n}`])
  1034. * ),
  1035. * ['a1', 'b1', 'a2', 'b2', 'a3', 'b3']
  1036. * )
  1037. * assert.deepStrictEqual(
  1038. * pipe(
  1039. * [1, 2, 3],
  1040. * RA.chain(() => [])
  1041. * ),
  1042. * []
  1043. * )
  1044. *
  1045. * @category sequencing
  1046. * @since 2.5.0
  1047. */
  1048. export declare const chain: <A, B>(f: (a: A) => ReadonlyArray<B>) => (ma: ReadonlyArray<A>) => ReadonlyArray<B>
  1049. /**
  1050. * @category sequencing
  1051. * @since 2.5.0
  1052. */
  1053. export declare const flatten: <A>(mma: ReadonlyArray<ReadonlyArray<A>>) => ReadonlyArray<A>
  1054. /**
  1055. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  1056. * use the type constructor `F` to represent some computational context.
  1057. *
  1058. * @category mapping
  1059. * @since 2.5.0
  1060. */
  1061. export declare const map: <A, B>(f: (a: A) => B) => (fa: ReadonlyArray<A>) => ReadonlyArray<B>
  1062. /**
  1063. * @category mapping
  1064. * @since 2.5.0
  1065. */
  1066. export declare const mapWithIndex: <A, B>(f: (i: number, a: A) => B) => (fa: ReadonlyArray<A>) => ReadonlyArray<B>
  1067. /**
  1068. * @category filtering
  1069. * @since 2.5.0
  1070. */
  1071. export declare const separate: <A, B>(fa: readonly Either<A, B>[]) => Separated<readonly A[], readonly B[]>
  1072. /**
  1073. * @category filtering
  1074. * @since 2.5.0
  1075. */
  1076. export declare const filter: {
  1077. <A, B extends A>(refinement: Refinement<A, B>): (as: ReadonlyArray<A>) => ReadonlyArray<B>
  1078. <A>(predicate: Predicate<A>): <B extends A>(bs: ReadonlyArray<B>) => ReadonlyArray<B>
  1079. <A>(predicate: Predicate<A>): (as: ReadonlyArray<A>) => ReadonlyArray<A>
  1080. }
  1081. /**
  1082. * @category filtering
  1083. * @since 2.5.0
  1084. */
  1085. export declare const filterMapWithIndex: <A, B>(f: (i: number, a: A) => Option<B>) => (fa: readonly A[]) => readonly B[]
  1086. /**
  1087. * @category filtering
  1088. * @since 2.5.0
  1089. */
  1090. export declare const filterMap: <A, B>(f: (a: A) => Option<B>) => (fa: ReadonlyArray<A>) => ReadonlyArray<B>
  1091. /**
  1092. * @category filtering
  1093. * @since 2.5.0
  1094. */
  1095. export declare const compact: <A>(fa: ReadonlyArray<Option<A>>) => ReadonlyArray<A>
  1096. /**
  1097. * @category filtering
  1098. * @since 2.5.0
  1099. */
  1100. export declare const partition: {
  1101. <A, B extends A>(refinement: Refinement<A, B>): (
  1102. as: ReadonlyArray<A>
  1103. ) => Separated<ReadonlyArray<A>, ReadonlyArray<B>>
  1104. <A>(predicate: Predicate<A>): <B extends A>(bs: ReadonlyArray<B>) => Separated<ReadonlyArray<B>, ReadonlyArray<B>>
  1105. <A>(predicate: Predicate<A>): (as: ReadonlyArray<A>) => Separated<ReadonlyArray<A>, ReadonlyArray<A>>
  1106. }
  1107. /**
  1108. * @category filtering
  1109. * @since 2.5.0
  1110. */
  1111. export declare const partitionWithIndex: {
  1112. <A, B extends A>(refinementWithIndex: RefinementWithIndex<number, A, B>): (
  1113. as: ReadonlyArray<A>
  1114. ) => Separated<ReadonlyArray<A>, ReadonlyArray<B>>
  1115. <A>(predicateWithIndex: PredicateWithIndex<number, A>): <B extends A>(
  1116. bs: ReadonlyArray<B>
  1117. ) => Separated<ReadonlyArray<B>, ReadonlyArray<B>>
  1118. <A>(predicateWithIndex: PredicateWithIndex<number, A>): (
  1119. as: ReadonlyArray<A>
  1120. ) => Separated<ReadonlyArray<A>, ReadonlyArray<A>>
  1121. }
  1122. /**
  1123. * @category filtering
  1124. * @since 2.5.0
  1125. */
  1126. export declare const partitionMap: <A, B, C>(
  1127. f: (a: A) => Either<B, C>
  1128. ) => (fa: ReadonlyArray<A>) => Separated<ReadonlyArray<B>, ReadonlyArray<C>>
  1129. /**
  1130. * @category filtering
  1131. * @since 2.5.0
  1132. */
  1133. export declare const partitionMapWithIndex: <A, B, C>(
  1134. f: (i: number, a: A) => Either<B, C>
  1135. ) => (fa: readonly A[]) => Separated<readonly B[], readonly C[]>
  1136. /**
  1137. * @category filtering
  1138. * @since 2.5.0
  1139. */
  1140. export declare const filterWithIndex: {
  1141. <A, B extends A>(refinementWithIndex: RefinementWithIndex<number, A, B>): (as: ReadonlyArray<A>) => ReadonlyArray<B>
  1142. <A>(predicateWithIndex: PredicateWithIndex<number, A>): <B extends A>(bs: ReadonlyArray<B>) => ReadonlyArray<B>
  1143. <A>(predicateWithIndex: PredicateWithIndex<number, A>): (as: ReadonlyArray<A>) => ReadonlyArray<A>
  1144. }
  1145. /**
  1146. * @since 2.5.0
  1147. */
  1148. export declare const extend: <A, B>(f: (fa: ReadonlyArray<A>) => B) => (wa: ReadonlyArray<A>) => ReadonlyArray<B>
  1149. /**
  1150. * @since 2.5.0
  1151. */
  1152. export declare const duplicate: <A>(wa: ReadonlyArray<A>) => ReadonlyArray<ReadonlyArray<A>>
  1153. /**
  1154. * @category folding
  1155. * @since 2.5.0
  1156. */
  1157. export declare const foldMapWithIndex: <M>(M: Monoid<M>) => <A>(f: (i: number, a: A) => M) => (fa: readonly A[]) => M
  1158. /**
  1159. * @category folding
  1160. * @since 2.5.0
  1161. */
  1162. export declare const reduce: <A, B>(b: B, f: (b: B, a: A) => B) => (fa: ReadonlyArray<A>) => B
  1163. /**
  1164. * @category folding
  1165. * @since 2.5.0
  1166. */
  1167. export declare const foldMap: <M>(M: Monoid<M>) => <A>(f: (a: A) => M) => (fa: ReadonlyArray<A>) => M
  1168. /**
  1169. * @category folding
  1170. * @since 2.5.0
  1171. */
  1172. export declare const reduceWithIndex: <A, B>(b: B, f: (i: number, b: B, a: A) => B) => (fa: ReadonlyArray<A>) => B
  1173. /**
  1174. * @category folding
  1175. * @since 2.5.0
  1176. */
  1177. export declare const reduceRight: <A, B>(b: B, f: (a: A, b: B) => B) => (fa: ReadonlyArray<A>) => B
  1178. /**
  1179. * @category folding
  1180. * @since 2.5.0
  1181. */
  1182. export declare const reduceRightWithIndex: <A, B>(b: B, f: (i: number, a: A, b: B) => B) => (fa: ReadonlyArray<A>) => B
  1183. /**
  1184. * @category traversing
  1185. * @since 2.6.3
  1186. */
  1187. export declare const traverse: PipeableTraverse1<URI>
  1188. /**
  1189. * @category traversing
  1190. * @since 2.6.3
  1191. */
  1192. export declare const sequence: Traversable1<URI>['sequence']
  1193. /**
  1194. * @category sequencing
  1195. * @since 2.6.3
  1196. */
  1197. export declare const traverseWithIndex: PipeableTraverseWithIndex1<URI, number>
  1198. /**
  1199. * @category filtering
  1200. * @since 2.6.5
  1201. */
  1202. export declare const wither: PipeableWither1<URI>
  1203. /**
  1204. * @category filtering
  1205. * @since 2.6.5
  1206. */
  1207. export declare const wilt: PipeableWilt1<URI>
  1208. /**
  1209. * @since 2.6.6
  1210. */
  1211. export declare const unfold: <A, B>(b: B, f: (b: B) => Option<readonly [A, B]>) => readonly A[]
  1212. /**
  1213. * @category type lambdas
  1214. * @since 2.5.0
  1215. */
  1216. export declare const URI = 'ReadonlyArray'
  1217. /**
  1218. * @category type lambdas
  1219. * @since 2.5.0
  1220. */
  1221. export declare type URI = typeof URI
  1222. declare module './HKT' {
  1223. interface URItoKind<A> {
  1224. readonly [URI]: ReadonlyArray<A>
  1225. }
  1226. }
  1227. /**
  1228. * @category instances
  1229. * @since 2.5.0
  1230. */
  1231. export declare const getShow: <A>(S: Show<A>) => Show<readonly A[]>
  1232. /**
  1233. * @category instances
  1234. * @since 2.5.0
  1235. */
  1236. export declare const getSemigroup: <A = never>() => Semigroup<readonly A[]>
  1237. /**
  1238. * Returns a `Monoid` for `ReadonlyArray<A>`.
  1239. *
  1240. * @example
  1241. * import { getMonoid } from 'fp-ts/ReadonlyArray'
  1242. *
  1243. * const M = getMonoid<number>()
  1244. * assert.deepStrictEqual(M.concat([1, 2], [3, 4]), [1, 2, 3, 4])
  1245. *
  1246. * @category instances
  1247. * @since 2.5.0
  1248. */
  1249. export declare const getMonoid: <A = never>() => Monoid<readonly A[]>
  1250. /**
  1251. * Derives an `Eq` over the `ReadonlyArray` of a given element type from the `Eq` of that type. The derived `Eq` defines two
  1252. * arrays as equal if all elements of both arrays are compared equal pairwise with the given `E`. In case of arrays of
  1253. * different lengths, the result is non equality.
  1254. *
  1255. * @example
  1256. * import * as S from 'fp-ts/string'
  1257. * import { getEq } from 'fp-ts/ReadonlyArray'
  1258. *
  1259. * const E = getEq(S.Eq)
  1260. * assert.strictEqual(E.equals(['a', 'b'], ['a', 'b']), true)
  1261. * assert.strictEqual(E.equals(['a'], []), false)
  1262. *
  1263. * @category instances
  1264. * @since 2.5.0
  1265. */
  1266. export declare const getEq: <A>(E: Eq<A>) => Eq<readonly A[]>
  1267. /**
  1268. * Derives an `Ord` over the `ReadonlyArray` of a given element type from the `Ord` of that type. The ordering between two such
  1269. * arrays is equal to: the first non equal comparison of each arrays elements taken pairwise in increasing order, in
  1270. * case of equality over all the pairwise elements; the longest array is considered the greatest, if both arrays have
  1271. * the same length, the result is equality.
  1272. *
  1273. * @example
  1274. * import { getOrd } from 'fp-ts/ReadonlyArray'
  1275. * import * as S from 'fp-ts/string'
  1276. *
  1277. * const O = getOrd(S.Ord)
  1278. * assert.strictEqual(O.compare(['b'], ['a']), 1)
  1279. * assert.strictEqual(O.compare(['a'], ['a']), 0)
  1280. * assert.strictEqual(O.compare(['a'], ['b']), -1)
  1281. *
  1282. *
  1283. * @category instances
  1284. * @since 2.5.0
  1285. */
  1286. export declare const getOrd: <A>(O: Ord<A>) => Ord<readonly A[]>
  1287. /**
  1288. * @category instances
  1289. * @since 2.11.0
  1290. */
  1291. export declare const getUnionSemigroup: <A>(E: Eq<A>) => Semigroup<readonly A[]>
  1292. /**
  1293. * @category instances
  1294. * @since 2.11.0
  1295. */
  1296. export declare const getUnionMonoid: <A>(E: Eq<A>) => Monoid<readonly A[]>
  1297. /**
  1298. * @category instances
  1299. * @since 2.11.0
  1300. */
  1301. export declare const getIntersectionSemigroup: <A>(E: Eq<A>) => Semigroup<readonly A[]>
  1302. /**
  1303. * @category instances
  1304. * @since 2.11.0
  1305. */
  1306. export declare const getDifferenceMagma: <A>(E: Eq<A>) => Magma<readonly A[]>
  1307. /**
  1308. * @category instances
  1309. * @since 2.7.0
  1310. */
  1311. export declare const Functor: Functor1<URI>
  1312. /**
  1313. * @category mapping
  1314. * @since 2.10.0
  1315. */
  1316. export declare const flap: <A>(a: A) => <B>(fab: readonly ((a: A) => B)[]) => readonly B[]
  1317. /**
  1318. * @category instances
  1319. * @since 2.10.0
  1320. */
  1321. export declare const Pointed: Pointed1<URI>
  1322. /**
  1323. * @category instances
  1324. * @since 2.7.0
  1325. */
  1326. export declare const FunctorWithIndex: FunctorWithIndex1<URI, number>
  1327. /**
  1328. * @category instances
  1329. * @since 2.10.0
  1330. */
  1331. export declare const Apply: Apply1<URI>
  1332. /**
  1333. * Combine two effectful actions, keeping only the result of the first.
  1334. *
  1335. * @since 2.5.0
  1336. */
  1337. export declare const apFirst: <B>(second: readonly B[]) => <A>(first: readonly A[]) => readonly A[]
  1338. /**
  1339. * Combine two effectful actions, keeping only the result of the second.
  1340. *
  1341. * @since 2.5.0
  1342. */
  1343. export declare const apSecond: <B>(second: readonly B[]) => <A>(first: readonly A[]) => readonly B[]
  1344. /**
  1345. * @category instances
  1346. * @since 2.7.0
  1347. */
  1348. export declare const Applicative: Applicative1<URI>
  1349. /**
  1350. * @category instances
  1351. * @since 2.10.0
  1352. */
  1353. export declare const Chain: Chain1<URI>
  1354. /**
  1355. * @category instances
  1356. * @since 2.7.0
  1357. */
  1358. export declare const Monad: Monad1<URI>
  1359. /**
  1360. * Composes computations in sequence, using the return value of one computation to determine the next computation and
  1361. * keeping only the result of the first.
  1362. *
  1363. * @example
  1364. * import * as RA from 'fp-ts/ReadonlyArray'
  1365. * import { pipe } from 'fp-ts/function'
  1366. *
  1367. * assert.deepStrictEqual(
  1368. * pipe(
  1369. * [1, 2, 3],
  1370. * RA.chainFirst(() => ['a', 'b'])
  1371. * ),
  1372. * [1, 1, 2, 2, 3, 3]
  1373. * )
  1374. * assert.deepStrictEqual(
  1375. * pipe(
  1376. * [1, 2, 3],
  1377. * RA.chainFirst(() => [])
  1378. * ),
  1379. * []
  1380. * )
  1381. *
  1382. * @category sequencing
  1383. * @since 2.5.0
  1384. */
  1385. export declare const chainFirst: <A, B>(f: (a: A) => ReadonlyArray<B>) => (first: ReadonlyArray<A>) => ReadonlyArray<A>
  1386. /**
  1387. * @category instances
  1388. * @since 2.7.0
  1389. */
  1390. export declare const Unfoldable: Unfoldable1<URI>
  1391. /**
  1392. * @category instances
  1393. * @since 2.7.0
  1394. */
  1395. export declare const Alt: Alt1<URI>
  1396. /**
  1397. * @category instances
  1398. * @since 2.11.0
  1399. */
  1400. export declare const Zero: Zero1<URI>
  1401. /**
  1402. * @category do notation
  1403. * @since 2.11.0
  1404. */
  1405. export declare const guard: (b: boolean) => readonly void[]
  1406. /**
  1407. * @category instances
  1408. * @since 2.7.0
  1409. */
  1410. export declare const Alternative: Alternative1<URI>
  1411. /**
  1412. * @category instances
  1413. * @since 2.7.0
  1414. */
  1415. export declare const Extend: Extend1<URI>
  1416. /**
  1417. * @category instances
  1418. * @since 2.7.0
  1419. */
  1420. export declare const Compactable: Compactable1<URI>
  1421. /**
  1422. * @category instances
  1423. * @since 2.7.0
  1424. */
  1425. export declare const Filterable: Filterable1<URI>
  1426. /**
  1427. * @category instances
  1428. * @since 2.7.0
  1429. */
  1430. export declare const FilterableWithIndex: FilterableWithIndex1<URI, number>
  1431. /**
  1432. * @category instances
  1433. * @since 2.7.0
  1434. */
  1435. export declare const Foldable: Foldable1<URI>
  1436. /**
  1437. * @category instances
  1438. * @since 2.7.0
  1439. */
  1440. export declare const FoldableWithIndex: FoldableWithIndex1<URI, number>
  1441. /**
  1442. * @category instances
  1443. * @since 2.7.0
  1444. */
  1445. export declare const Traversable: Traversable1<URI>
  1446. /**
  1447. * @category instances
  1448. * @since 2.7.0
  1449. */
  1450. export declare const TraversableWithIndex: TraversableWithIndex1<URI, number>
  1451. /**
  1452. * @category sequencing
  1453. * @since 2.11.0
  1454. */
  1455. export declare const chainRecDepthFirst: <A, B>(f: (a: A) => readonly Either<A, B>[]) => (a: A) => readonly B[]
  1456. /**
  1457. * @category instances
  1458. * @since 2.11.0
  1459. */
  1460. export declare const ChainRecDepthFirst: ChainRec1<URI>
  1461. /**
  1462. * @category sequencing
  1463. * @since 2.11.0
  1464. */
  1465. export declare const chainRecBreadthFirst: <A, B>(f: (a: A) => readonly Either<A, B>[]) => (a: A) => readonly B[]
  1466. /**
  1467. * @category instances
  1468. * @since 2.11.0
  1469. */
  1470. export declare const ChainRecBreadthFirst: ChainRec1<URI>
  1471. /**
  1472. * @category instances
  1473. * @since 2.7.0
  1474. */
  1475. export declare const Witherable: Witherable1<URI>
  1476. /**
  1477. * Filter values inside a context.
  1478. *
  1479. * @example
  1480. * import { pipe } from 'fp-ts/function'
  1481. * import * as RA from 'fp-ts/ReadonlyArray'
  1482. * import * as T from 'fp-ts/Task'
  1483. *
  1484. * const filterE = RA.filterE(T.ApplicativePar)
  1485. * async function test() {
  1486. * assert.deepStrictEqual(
  1487. * await pipe(
  1488. * [-1, 2, 3],
  1489. * filterE((n) => T.of(n > 0))
  1490. * )(),
  1491. * [2, 3]
  1492. * )
  1493. * }
  1494. * test()
  1495. *
  1496. * @since 2.11.0
  1497. */
  1498. export declare const filterE: import('./Witherable').FilterE1<'ReadonlyArray'>
  1499. /**
  1500. * @category instances
  1501. * @since 2.11.0
  1502. */
  1503. export declare const FromEither: FromEither1<URI>
  1504. /**
  1505. * @category lifting
  1506. * @since 2.11.0
  1507. */
  1508. export declare const fromEitherK: <E, A extends ReadonlyArray<unknown>, B>(
  1509. f: (...a: A) => Either<E, B>
  1510. ) => (...a: A) => ReadonlyArray<B>
  1511. /**
  1512. * @category unsafe
  1513. * @since 2.5.0
  1514. */
  1515. export declare const unsafeInsertAt: <A>(i: number, a: A, as: ReadonlyArray<A>) => ReadonlyNonEmptyArray<A>
  1516. /**
  1517. * @category unsafe
  1518. * @since 2.5.0
  1519. */
  1520. export declare const unsafeUpdateAt: <A>(i: number, a: A, as: readonly A[]) => readonly A[]
  1521. /**
  1522. * @category unsafe
  1523. * @since 2.5.0
  1524. */
  1525. export declare const unsafeDeleteAt: <A>(i: number, as: readonly A[]) => readonly A[]
  1526. /**
  1527. * @category conversions
  1528. * @since 2.5.0
  1529. */
  1530. export declare const toArray: <A>(as: readonly A[]) => A[]
  1531. /**
  1532. * @category conversions
  1533. * @since 2.5.0
  1534. */
  1535. export declare const fromArray: <A>(as: A[]) => readonly A[]
  1536. /**
  1537. * An empty array
  1538. *
  1539. * @since 2.5.0
  1540. */
  1541. export declare const empty: ReadonlyArray<never>
  1542. /**
  1543. * Check if a predicate holds true for every array member.
  1544. *
  1545. * @example
  1546. * import { every } from 'fp-ts/ReadonlyArray'
  1547. * import { pipe } from 'fp-ts/function'
  1548. *
  1549. * const isPositive = (n: number): boolean => n > 0
  1550. *
  1551. * assert.deepStrictEqual(pipe([1, 2, 3], every(isPositive)), true)
  1552. * assert.deepStrictEqual(pipe([1, 2, -3], every(isPositive)), false)
  1553. *
  1554. * @since 2.9.0
  1555. */
  1556. export declare function every<A, B extends A>(
  1557. refinement: Refinement<A, B>
  1558. ): Refinement<ReadonlyArray<A>, ReadonlyArray<B>>
  1559. export declare function every<A>(predicate: Predicate<A>): Predicate<ReadonlyArray<A>>
  1560. /**
  1561. * Check if a predicate holds true for any array member.
  1562. *
  1563. * @example
  1564. * import { some } from 'fp-ts/ReadonlyArray'
  1565. * import { pipe } from 'fp-ts/function'
  1566. *
  1567. * const isPositive = (n: number): boolean => n > 0
  1568. *
  1569. * assert.deepStrictEqual(pipe([-1, -2, 3], some(isPositive)), true)
  1570. * assert.deepStrictEqual(pipe([-1, -2, -3], some(isPositive)), false)
  1571. *
  1572. * @since 2.9.0
  1573. */
  1574. export declare const some: <A>(predicate: Predicate<A>) => (as: readonly A[]) => as is RNEA.ReadonlyNonEmptyArray<A>
  1575. /**
  1576. * Alias of [`some`](#some)
  1577. *
  1578. * @since 2.11.0
  1579. */
  1580. export declare const exists: <A>(
  1581. predicate: Predicate<A>
  1582. ) => (as: ReadonlyArray<A>) => as is RNEA.ReadonlyNonEmptyArray<A>
  1583. /**
  1584. * Places an element in between members of a `ReadonlyArray`, then folds the results using the provided `Monoid`.
  1585. *
  1586. * @example
  1587. * import * as S from 'fp-ts/string'
  1588. * import { intercalate } from 'fp-ts/ReadonlyArray'
  1589. *
  1590. * assert.deepStrictEqual(intercalate(S.Monoid)('-')(['a', 'b', 'c']), 'a-b-c')
  1591. *
  1592. * @since 2.12.0
  1593. */
  1594. export declare const intercalate: <A>(M: Monoid<A>) => (middle: A) => (as: readonly A[]) => A
  1595. /**
  1596. * @category do notation
  1597. * @since 2.9.0
  1598. */
  1599. export declare const Do: ReadonlyArray<{}>
  1600. /**
  1601. * @category do notation
  1602. * @since 2.8.0
  1603. */
  1604. export declare const bindTo: <N extends string>(name: N) => <A>(fa: readonly A[]) => readonly { readonly [K in N]: A }[]
  1605. declare const let_: <N extends string, A, B>(
  1606. name: Exclude<N, keyof A>,
  1607. f: (a: A) => B
  1608. ) => (fa: readonly A[]) => readonly { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }[]
  1609. export {
  1610. /**
  1611. * @category do notation
  1612. * @since 2.13.0
  1613. */
  1614. let_ as let
  1615. }
  1616. /**
  1617. * @category do notation
  1618. * @since 2.8.0
  1619. */
  1620. export declare const bind: <N extends string, A, B>(
  1621. name: Exclude<N, keyof A>,
  1622. f: (a: A) => readonly B[]
  1623. ) => (ma: readonly A[]) => readonly { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }[]
  1624. /**
  1625. * @category do notation
  1626. * @since 2.8.0
  1627. */
  1628. export declare const apS: <N extends string, A, B>(
  1629. name: Exclude<N, keyof A>,
  1630. fb: readonly B[]
  1631. ) => (fa: readonly A[]) => readonly { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }[]
  1632. /**
  1633. * Use `ReadonlyNonEmptyArray` module instead.
  1634. *
  1635. * @category zone of death
  1636. * @since 2.5.0
  1637. * @deprecated
  1638. */
  1639. export declare const range: (start: number, end: number) => RNEA.ReadonlyNonEmptyArray<number>
  1640. /**
  1641. * Use [`prepend`](#prepend) instead.
  1642. *
  1643. * @category zone of death
  1644. * @since 2.5.0
  1645. * @deprecated
  1646. */
  1647. export declare const cons: typeof RNEA.cons
  1648. /**
  1649. * Use [`append`](#append) instead.
  1650. *
  1651. * @category zone of death
  1652. * @since 2.5.0
  1653. * @deprecated
  1654. */
  1655. export declare const snoc: <A>(init: readonly A[], end: A) => RNEA.ReadonlyNonEmptyArray<A>
  1656. /**
  1657. * Use [`prependAll`](#prependall) instead.
  1658. *
  1659. * @category zone of death
  1660. * @since 2.9.0
  1661. * @deprecated
  1662. */
  1663. export declare const prependToAll: <A>(middle: A) => (as: readonly A[]) => readonly A[]
  1664. /**
  1665. * This instance is deprecated, use small, specific instances instead.
  1666. * For example if a function needs a `Functor` instance, pass `RA.Functor` instead of `RA.readonlyArray`
  1667. * (where `RA` is from `import RA from 'fp-ts/ReadonlyArray'`)
  1668. *
  1669. * @category zone of death
  1670. * @since 2.5.0
  1671. * @deprecated
  1672. */
  1673. export declare const readonlyArray: FunctorWithIndex1<URI, number> &
  1674. Monad1<URI> &
  1675. Unfoldable1<URI> &
  1676. Alternative1<URI> &
  1677. Extend1<URI> &
  1678. FilterableWithIndex1<URI, number> &
  1679. FoldableWithIndex1<URI, number> &
  1680. TraversableWithIndex1<URI, number> &
  1681. Witherable1<URI>