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

571 lines
13 KiB

  1. /**
  2. * @since 2.0.0
  3. */
  4. import { BooleanAlgebra } from './BooleanAlgebra'
  5. import { Monoid } from './Monoid'
  6. import { Ring } from './Ring'
  7. import { Semigroup } from './Semigroup'
  8. import { Semiring } from './Semiring'
  9. /**
  10. * @category instances
  11. * @since 2.10.0
  12. */
  13. export declare const getBooleanAlgebra: <B>(B: BooleanAlgebra<B>) => <A = never>() => BooleanAlgebra<(a: A) => B>
  14. /**
  15. * Unary functions form a semigroup as long as you can provide a semigroup for the codomain.
  16. *
  17. * @example
  18. * import { Predicate, getSemigroup } from 'fp-ts/function'
  19. * import * as B from 'fp-ts/boolean'
  20. *
  21. * const f: Predicate<number> = (n) => n <= 2
  22. * const g: Predicate<number> = (n) => n >= 0
  23. *
  24. * const S1 = getSemigroup(B.SemigroupAll)<number>()
  25. *
  26. * assert.deepStrictEqual(S1.concat(f, g)(1), true)
  27. * assert.deepStrictEqual(S1.concat(f, g)(3), false)
  28. *
  29. * const S2 = getSemigroup(B.SemigroupAny)<number>()
  30. *
  31. * assert.deepStrictEqual(S2.concat(f, g)(1), true)
  32. * assert.deepStrictEqual(S2.concat(f, g)(3), true)
  33. *
  34. * @category instances
  35. * @since 2.10.0
  36. */
  37. export declare const getSemigroup: <S>(S: Semigroup<S>) => <A = never>() => Semigroup<(a: A) => S>
  38. /**
  39. * Unary functions form a monoid as long as you can provide a monoid for the codomain.
  40. *
  41. * @example
  42. * import { Predicate } from 'fp-ts/Predicate'
  43. * import { getMonoid } from 'fp-ts/function'
  44. * import * as B from 'fp-ts/boolean'
  45. *
  46. * const f: Predicate<number> = (n) => n <= 2
  47. * const g: Predicate<number> = (n) => n >= 0
  48. *
  49. * const M1 = getMonoid(B.MonoidAll)<number>()
  50. *
  51. * assert.deepStrictEqual(M1.concat(f, g)(1), true)
  52. * assert.deepStrictEqual(M1.concat(f, g)(3), false)
  53. *
  54. * const M2 = getMonoid(B.MonoidAny)<number>()
  55. *
  56. * assert.deepStrictEqual(M2.concat(f, g)(1), true)
  57. * assert.deepStrictEqual(M2.concat(f, g)(3), true)
  58. *
  59. * @category instances
  60. * @since 2.10.0
  61. */
  62. export declare const getMonoid: <M>(M: Monoid<M>) => <A = never>() => Monoid<(a: A) => M>
  63. /**
  64. * @category instances
  65. * @since 2.10.0
  66. */
  67. export declare const getSemiring: <A, B>(S: Semiring<B>) => Semiring<(a: A) => B>
  68. /**
  69. * @category instances
  70. * @since 2.10.0
  71. */
  72. export declare const getRing: <A, B>(R: Ring<B>) => Ring<(a: A) => B>
  73. /**
  74. * @since 2.11.0
  75. */
  76. export declare const apply: <A>(a: A) => <B>(f: (a: A) => B) => B
  77. /**
  78. * A *thunk*
  79. *
  80. * @since 2.0.0
  81. */
  82. export interface Lazy<A> {
  83. (): A
  84. }
  85. /**
  86. * @example
  87. * import { FunctionN } from 'fp-ts/function'
  88. *
  89. * export const sum: FunctionN<[number, number], number> = (a, b) => a + b
  90. *
  91. * @since 2.0.0
  92. */
  93. export interface FunctionN<A extends ReadonlyArray<unknown>, B> {
  94. (...args: A): B
  95. }
  96. /**
  97. * @since 2.0.0
  98. */
  99. export declare function identity<A>(a: A): A
  100. /**
  101. * @since 2.0.0
  102. */
  103. export declare const unsafeCoerce: <A, B>(a: A) => B
  104. /**
  105. * @since 2.0.0
  106. */
  107. export declare function constant<A>(a: A): Lazy<A>
  108. /**
  109. * A thunk that returns always `true`.
  110. *
  111. * @since 2.0.0
  112. */
  113. export declare const constTrue: Lazy<boolean>
  114. /**
  115. * A thunk that returns always `false`.
  116. *
  117. * @since 2.0.0
  118. */
  119. export declare const constFalse: Lazy<boolean>
  120. /**
  121. * A thunk that returns always `null`.
  122. *
  123. * @since 2.0.0
  124. */
  125. export declare const constNull: Lazy<null>
  126. /**
  127. * A thunk that returns always `undefined`.
  128. *
  129. * @since 2.0.0
  130. */
  131. export declare const constUndefined: Lazy<undefined>
  132. /**
  133. * A thunk that returns always `void`.
  134. *
  135. * @since 2.0.0
  136. */
  137. export declare const constVoid: Lazy<void>
  138. /**
  139. * Flips the arguments of a curried function.
  140. *
  141. * @example
  142. * import { flip } from 'fp-ts/function'
  143. *
  144. * const f = (a: number) => (b: string) => a - b.length
  145. *
  146. * assert.strictEqual(flip(f)('aaa')(2), -1)
  147. *
  148. * @since 2.0.0
  149. */
  150. export declare function flip<A, B, C>(f: (a: A) => (b: B) => C): (b: B) => (a: A) => C
  151. /** @deprecated */
  152. export declare function flip<A, B, C>(f: (a: A, b: B) => C): (b: B, a: A) => C
  153. /**
  154. * Performs left-to-right function composition. The first argument may have any arity, the remaining arguments must be unary.
  155. *
  156. * See also [`pipe`](#pipe).
  157. *
  158. * @example
  159. * import { flow } from 'fp-ts/function'
  160. *
  161. * const len = (s: string): number => s.length
  162. * const double = (n: number): number => n * 2
  163. *
  164. * const f = flow(len, double)
  165. *
  166. * assert.strictEqual(f('aaa'), 6)
  167. *
  168. * @since 2.0.0
  169. */
  170. export declare function flow<A extends ReadonlyArray<unknown>, B>(ab: (...a: A) => B): (...a: A) => B
  171. export declare function flow<A extends ReadonlyArray<unknown>, B, C>(
  172. ab: (...a: A) => B,
  173. bc: (b: B) => C
  174. ): (...a: A) => C
  175. export declare function flow<A extends ReadonlyArray<unknown>, B, C, D>(
  176. ab: (...a: A) => B,
  177. bc: (b: B) => C,
  178. cd: (c: C) => D
  179. ): (...a: A) => D
  180. export declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E>(
  181. ab: (...a: A) => B,
  182. bc: (b: B) => C,
  183. cd: (c: C) => D,
  184. de: (d: D) => E
  185. ): (...a: A) => E
  186. export declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F>(
  187. ab: (...a: A) => B,
  188. bc: (b: B) => C,
  189. cd: (c: C) => D,
  190. de: (d: D) => E,
  191. ef: (e: E) => F
  192. ): (...a: A) => F
  193. export declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G>(
  194. ab: (...a: A) => B,
  195. bc: (b: B) => C,
  196. cd: (c: C) => D,
  197. de: (d: D) => E,
  198. ef: (e: E) => F,
  199. fg: (f: F) => G
  200. ): (...a: A) => G
  201. export declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H>(
  202. ab: (...a: A) => B,
  203. bc: (b: B) => C,
  204. cd: (c: C) => D,
  205. de: (d: D) => E,
  206. ef: (e: E) => F,
  207. fg: (f: F) => G,
  208. gh: (g: G) => H
  209. ): (...a: A) => H
  210. export declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I>(
  211. ab: (...a: A) => B,
  212. bc: (b: B) => C,
  213. cd: (c: C) => D,
  214. de: (d: D) => E,
  215. ef: (e: E) => F,
  216. fg: (f: F) => G,
  217. gh: (g: G) => H,
  218. hi: (h: H) => I
  219. ): (...a: A) => I
  220. export declare function flow<A extends ReadonlyArray<unknown>, B, C, D, E, F, G, H, I, J>(
  221. ab: (...a: A) => B,
  222. bc: (b: B) => C,
  223. cd: (c: C) => D,
  224. de: (d: D) => E,
  225. ef: (e: E) => F,
  226. fg: (f: F) => G,
  227. gh: (g: G) => H,
  228. hi: (h: H) => I,
  229. ij: (i: I) => J
  230. ): (...a: A) => J
  231. /**
  232. * @since 2.0.0
  233. */
  234. export declare function tuple<T extends ReadonlyArray<any>>(...t: T): T
  235. /**
  236. * @since 2.0.0
  237. */
  238. export declare function increment(n: number): number
  239. /**
  240. * @since 2.0.0
  241. */
  242. export declare function decrement(n: number): number
  243. /**
  244. * @since 2.0.0
  245. */
  246. export declare function absurd<A>(_: never): A
  247. /**
  248. * Creates a tupled version of this function: instead of `n` arguments, it accepts a single tuple argument.
  249. *
  250. * @example
  251. * import { tupled } from 'fp-ts/function'
  252. *
  253. * const add = tupled((x: number, y: number): number => x + y)
  254. *
  255. * assert.strictEqual(add([1, 2]), 3)
  256. *
  257. * @since 2.4.0
  258. */
  259. export declare function tupled<A extends ReadonlyArray<unknown>, B>(f: (...a: A) => B): (a: A) => B
  260. /**
  261. * Inverse function of `tupled`
  262. *
  263. * @since 2.4.0
  264. */
  265. export declare function untupled<A extends ReadonlyArray<unknown>, B>(f: (a: A) => B): (...a: A) => B
  266. /**
  267. * Pipes the value of an expression into a pipeline of functions.
  268. *
  269. * See also [`flow`](#flow).
  270. *
  271. * @example
  272. * import { pipe } from 'fp-ts/function'
  273. *
  274. * const len = (s: string): number => s.length
  275. * const double = (n: number): number => n * 2
  276. *
  277. * // without pipe
  278. * assert.strictEqual(double(len('aaa')), 6)
  279. *
  280. * // with pipe
  281. * assert.strictEqual(pipe('aaa', len, double), 6)
  282. *
  283. * @since 2.6.3
  284. */
  285. export declare function pipe<A>(a: A): A
  286. export declare function pipe<A, B>(a: A, ab: (a: A) => B): B
  287. export declare function pipe<A, B, C>(a: A, ab: (a: A) => B, bc: (b: B) => C): C
  288. export declare function pipe<A, B, C, D>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): D
  289. export declare function pipe<A, B, C, D, E>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): E
  290. export declare function pipe<A, B, C, D, E, F>(
  291. a: A,
  292. ab: (a: A) => B,
  293. bc: (b: B) => C,
  294. cd: (c: C) => D,
  295. de: (d: D) => E,
  296. ef: (e: E) => F
  297. ): F
  298. export declare function pipe<A, B, C, D, E, F, G>(
  299. a: A,
  300. ab: (a: A) => B,
  301. bc: (b: B) => C,
  302. cd: (c: C) => D,
  303. de: (d: D) => E,
  304. ef: (e: E) => F,
  305. fg: (f: F) => G
  306. ): G
  307. export declare function pipe<A, B, C, D, E, F, G, H>(
  308. a: A,
  309. ab: (a: A) => B,
  310. bc: (b: B) => C,
  311. cd: (c: C) => D,
  312. de: (d: D) => E,
  313. ef: (e: E) => F,
  314. fg: (f: F) => G,
  315. gh: (g: G) => H
  316. ): H
  317. export declare function pipe<A, B, C, D, E, F, G, H, I>(
  318. a: A,
  319. ab: (a: A) => B,
  320. bc: (b: B) => C,
  321. cd: (c: C) => D,
  322. de: (d: D) => E,
  323. ef: (e: E) => F,
  324. fg: (f: F) => G,
  325. gh: (g: G) => H,
  326. hi: (h: H) => I
  327. ): I
  328. export declare function pipe<A, B, C, D, E, F, G, H, I, J>(
  329. a: A,
  330. ab: (a: A) => B,
  331. bc: (b: B) => C,
  332. cd: (c: C) => D,
  333. de: (d: D) => E,
  334. ef: (e: E) => F,
  335. fg: (f: F) => G,
  336. gh: (g: G) => H,
  337. hi: (h: H) => I,
  338. ij: (i: I) => J
  339. ): J
  340. export declare function pipe<A, B, C, D, E, F, G, H, I, J, K>(
  341. a: A,
  342. ab: (a: A) => B,
  343. bc: (b: B) => C,
  344. cd: (c: C) => D,
  345. de: (d: D) => E,
  346. ef: (e: E) => F,
  347. fg: (f: F) => G,
  348. gh: (g: G) => H,
  349. hi: (h: H) => I,
  350. ij: (i: I) => J,
  351. jk: (j: J) => K
  352. ): K
  353. export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L>(
  354. a: A,
  355. ab: (a: A) => B,
  356. bc: (b: B) => C,
  357. cd: (c: C) => D,
  358. de: (d: D) => E,
  359. ef: (e: E) => F,
  360. fg: (f: F) => G,
  361. gh: (g: G) => H,
  362. hi: (h: H) => I,
  363. ij: (i: I) => J,
  364. jk: (j: J) => K,
  365. kl: (k: K) => L
  366. ): L
  367. export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(
  368. a: A,
  369. ab: (a: A) => B,
  370. bc: (b: B) => C,
  371. cd: (c: C) => D,
  372. de: (d: D) => E,
  373. ef: (e: E) => F,
  374. fg: (f: F) => G,
  375. gh: (g: G) => H,
  376. hi: (h: H) => I,
  377. ij: (i: I) => J,
  378. jk: (j: J) => K,
  379. kl: (k: K) => L,
  380. lm: (l: L) => M
  381. ): M
  382. export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(
  383. a: A,
  384. ab: (a: A) => B,
  385. bc: (b: B) => C,
  386. cd: (c: C) => D,
  387. de: (d: D) => E,
  388. ef: (e: E) => F,
  389. fg: (f: F) => G,
  390. gh: (g: G) => H,
  391. hi: (h: H) => I,
  392. ij: (i: I) => J,
  393. jk: (j: J) => K,
  394. kl: (k: K) => L,
  395. lm: (l: L) => M,
  396. mn: (m: M) => N
  397. ): N
  398. export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(
  399. a: A,
  400. ab: (a: A) => B,
  401. bc: (b: B) => C,
  402. cd: (c: C) => D,
  403. de: (d: D) => E,
  404. ef: (e: E) => F,
  405. fg: (f: F) => G,
  406. gh: (g: G) => H,
  407. hi: (h: H) => I,
  408. ij: (i: I) => J,
  409. jk: (j: J) => K,
  410. kl: (k: K) => L,
  411. lm: (l: L) => M,
  412. mn: (m: M) => N,
  413. no: (n: N) => O
  414. ): O
  415. export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(
  416. a: A,
  417. ab: (a: A) => B,
  418. bc: (b: B) => C,
  419. cd: (c: C) => D,
  420. de: (d: D) => E,
  421. ef: (e: E) => F,
  422. fg: (f: F) => G,
  423. gh: (g: G) => H,
  424. hi: (h: H) => I,
  425. ij: (i: I) => J,
  426. jk: (j: J) => K,
  427. kl: (k: K) => L,
  428. lm: (l: L) => M,
  429. mn: (m: M) => N,
  430. no: (n: N) => O,
  431. op: (o: O) => P
  432. ): P
  433. export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(
  434. a: A,
  435. ab: (a: A) => B,
  436. bc: (b: B) => C,
  437. cd: (c: C) => D,
  438. de: (d: D) => E,
  439. ef: (e: E) => F,
  440. fg: (f: F) => G,
  441. gh: (g: G) => H,
  442. hi: (h: H) => I,
  443. ij: (i: I) => J,
  444. jk: (j: J) => K,
  445. kl: (k: K) => L,
  446. lm: (l: L) => M,
  447. mn: (m: M) => N,
  448. no: (n: N) => O,
  449. op: (o: O) => P,
  450. pq: (p: P) => Q
  451. ): Q
  452. export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R>(
  453. a: A,
  454. ab: (a: A) => B,
  455. bc: (b: B) => C,
  456. cd: (c: C) => D,
  457. de: (d: D) => E,
  458. ef: (e: E) => F,
  459. fg: (f: F) => G,
  460. gh: (g: G) => H,
  461. hi: (h: H) => I,
  462. ij: (i: I) => J,
  463. jk: (j: J) => K,
  464. kl: (k: K) => L,
  465. lm: (l: L) => M,
  466. mn: (m: M) => N,
  467. no: (n: N) => O,
  468. op: (o: O) => P,
  469. pq: (p: P) => Q,
  470. qr: (q: Q) => R
  471. ): R
  472. export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S>(
  473. a: A,
  474. ab: (a: A) => B,
  475. bc: (b: B) => C,
  476. cd: (c: C) => D,
  477. de: (d: D) => E,
  478. ef: (e: E) => F,
  479. fg: (f: F) => G,
  480. gh: (g: G) => H,
  481. hi: (h: H) => I,
  482. ij: (i: I) => J,
  483. jk: (j: J) => K,
  484. kl: (k: K) => L,
  485. lm: (l: L) => M,
  486. mn: (m: M) => N,
  487. no: (n: N) => O,
  488. op: (o: O) => P,
  489. pq: (p: P) => Q,
  490. qr: (q: Q) => R,
  491. rs: (r: R) => S
  492. ): S
  493. export declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T>(
  494. a: A,
  495. ab: (a: A) => B,
  496. bc: (b: B) => C,
  497. cd: (c: C) => D,
  498. de: (d: D) => E,
  499. ef: (e: E) => F,
  500. fg: (f: F) => G,
  501. gh: (g: G) => H,
  502. hi: (h: H) => I,
  503. ij: (i: I) => J,
  504. jk: (j: J) => K,
  505. kl: (k: K) => L,
  506. lm: (l: L) => M,
  507. mn: (m: M) => N,
  508. no: (n: N) => O,
  509. op: (o: O) => P,
  510. pq: (p: P) => Q,
  511. qr: (q: Q) => R,
  512. rs: (r: R) => S,
  513. st: (s: S) => T
  514. ): T
  515. /**
  516. * Type hole simulation
  517. *
  518. * @since 2.7.0
  519. */
  520. export declare const hole: <T>() => T
  521. /**
  522. * @since 2.11.0
  523. */
  524. export declare const SK: <A, B>(_: A, b: B) => B
  525. /**
  526. * Use `Refinement` module instead.
  527. *
  528. * @category zone of death
  529. * @since 2.0.0
  530. * @deprecated
  531. */
  532. export interface Refinement<A, B extends A> {
  533. (a: A): a is B
  534. }
  535. /**
  536. * Use `Predicate` module instead.
  537. *
  538. * @category zone of death
  539. * @since 2.0.0
  540. * @deprecated
  541. */
  542. export interface Predicate<A> {
  543. (a: A): boolean
  544. }
  545. /**
  546. * Use `Predicate` module instead.
  547. *
  548. * @category zone of death
  549. * @since 2.0.0
  550. * @deprecated
  551. */
  552. export declare function not<A>(predicate: Predicate<A>): Predicate<A>
  553. /**
  554. * Use `Endomorphism` module instead.
  555. *
  556. * @category zone of death
  557. * @since 2.0.0
  558. * @deprecated
  559. */
  560. export interface Endomorphism<A> {
  561. (a: A): A
  562. }
  563. /**
  564. * Use `Endomorphism` module instead.
  565. *
  566. * @category zone of death
  567. * @since 2.10.0
  568. * @deprecated
  569. */
  570. export declare const getEndomorphismMonoid: <A = never>() => Monoid<Endomorphism<A>>