版博士V2.0程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

461 satır
12 KiB

  1. /**
  2. * `IOOption<A>` represents a synchronous computation that either yields a value of type `A` or nothing.
  3. *
  4. * If you want to represent a synchronous computation that never fails, please see `IO`.
  5. * If you want to represent a synchronous computation that may fail, please see `IOEither`.
  6. *
  7. * @since 2.12.0
  8. */
  9. import { Alt1 } from './Alt'
  10. import { Alternative1 } from './Alternative'
  11. import { Applicative1 } from './Applicative'
  12. import { Apply1 } from './Apply'
  13. import { Chain1 } from './Chain'
  14. import { Compactable1 } from './Compactable'
  15. import { Either } from './Either'
  16. import { Filterable1 } from './Filterable'
  17. import { FromEither1 } from './FromEither'
  18. import { FromIO1 } from './FromIO'
  19. import { Lazy } from './function'
  20. import { Functor1 } from './Functor'
  21. import { Monad1 } from './Monad'
  22. import { MonadIO1 } from './MonadIO'
  23. import * as O from './Option'
  24. import { Pointed1 } from './Pointed'
  25. import { Predicate } from './Predicate'
  26. import { ReadonlyNonEmptyArray } from './ReadonlyNonEmptyArray'
  27. import { Refinement } from './Refinement'
  28. import { Separated } from './Separated'
  29. import * as I from './IO'
  30. import { IOEither } from './IOEither'
  31. import { Zero1 } from './Zero'
  32. import IO = I.IO
  33. import Option = O.Option
  34. /**
  35. * @category model
  36. * @since 2.12.0
  37. */
  38. export interface IOOption<A> extends IO<Option<A>> {}
  39. /**
  40. * @category constructors
  41. * @since 2.12.0
  42. */
  43. export declare const some: <A>(a: A) => IOOption<A>
  44. /**
  45. * @category lifting
  46. * @since 2.12.0
  47. */
  48. export declare const fromPredicate: {
  49. <A, B extends A>(refinement: Refinement<A, B>): (a: A) => IOOption<B>
  50. <A>(predicate: Predicate<A>): <B extends A>(b: B) => IOOption<B>
  51. <A>(predicate: Predicate<A>): (a: A) => IOOption<A>
  52. }
  53. /**
  54. * @category conversions
  55. * @since 2.12.0
  56. */
  57. export declare const fromOption: <A>(fa: Option<A>) => IOOption<A>
  58. /**
  59. * @category conversions
  60. * @since 2.12.0
  61. */
  62. export declare const fromEither: <A>(fa: Either<unknown, A>) => IOOption<A>
  63. /**
  64. * @category conversions
  65. * @since 2.12.0
  66. */
  67. export declare const fromIO: <A>(fa: IO<A>) => IOOption<A>
  68. /**
  69. * @category conversions
  70. * @since 2.12.0
  71. */
  72. export declare const fromIOEither: <A>(fa: IOEither<unknown, A>) => IOOption<A>
  73. /**
  74. * @category pattern matching
  75. * @since 2.12.0
  76. */
  77. export declare const match: <B, A>(onNone: () => B, onSome: (a: A) => B) => (ma: IOOption<A>) => IO<B>
  78. /**
  79. * Less strict version of [`match`](#match).
  80. *
  81. * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
  82. *
  83. * @category pattern matching
  84. * @since 2.12.0
  85. */
  86. export declare const matchW: <B, A, C>(onNone: () => B, onSome: (a: A) => C) => (ma: IOOption<A>) => IO<B | C>
  87. /**
  88. * The `E` suffix (short for **E**ffect) means that the handlers return an effect (`IO`).
  89. *
  90. * @category pattern matching
  91. * @since 2.12.0
  92. */
  93. export declare const matchE: <B, A>(onNone: () => IO<B>, onSome: (a: A) => IO<B>) => (ma: IOOption<A>) => IO<B>
  94. /**
  95. * Alias of [`matchE`](#matche).
  96. *
  97. * @category pattern matching
  98. * @since 2.12.0
  99. */
  100. export declare const fold: <B, A>(onNone: () => I.IO<B>, onSome: (a: A) => I.IO<B>) => (ma: IOOption<A>) => I.IO<B>
  101. /**
  102. * Less strict version of [`matchE`](#matche).
  103. *
  104. * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
  105. *
  106. * @category pattern matching
  107. * @since 2.12.0
  108. */
  109. export declare const matchEW: <B, C, A>(onNone: () => IO<B>, onSome: (a: A) => IO<C>) => (ma: IOOption<A>) => IO<B | C>
  110. /**
  111. * @category error handling
  112. * @since 2.12.0
  113. */
  114. export declare const getOrElse: <A>(onNone: Lazy<IO<A>>) => (fa: IOOption<A>) => IO<A>
  115. /**
  116. * Less strict version of [`getOrElse`](#getorelse).
  117. *
  118. * The `W` suffix (short for **W**idening) means that the handler return type will be merged.
  119. *
  120. * @category error handling
  121. * @since 2.12.0
  122. */
  123. export declare const getOrElseW: <B>(onNone: Lazy<IO<B>>) => <A>(ma: IOOption<A>) => IO<A | B>
  124. /**
  125. * @category conversions
  126. * @since 2.12.0
  127. */
  128. export declare const toUndefined: <A>(ma: IOOption<A>) => IO<A | undefined>
  129. /**
  130. * @category conversions
  131. * @since 2.12.0
  132. */
  133. export declare const toNullable: <A>(ma: IOOption<A>) => IO<A | null>
  134. /**
  135. * @category conversions
  136. * @since 2.12.0
  137. */
  138. export declare const fromNullable: <A>(a: A) => IOOption<NonNullable<A>>
  139. /**
  140. * @category lifting
  141. * @since 2.12.0
  142. */
  143. export declare const fromNullableK: <A extends ReadonlyArray<unknown>, B>(
  144. f: (...a: A) => B | null | undefined
  145. ) => (...a: A) => IOOption<NonNullable<B>>
  146. /**
  147. * @category sequencing
  148. * @since 2.12.0
  149. */
  150. export declare const chainNullableK: <A, B>(
  151. f: (a: A) => B | null | undefined
  152. ) => (ma: IOOption<A>) => IOOption<NonNullable<B>>
  153. /**
  154. * @category lifting
  155. * @since 2.12.0
  156. */
  157. export declare const fromOptionK: <A extends ReadonlyArray<unknown>, B>(
  158. f: (...a: A) => Option<B>
  159. ) => (...a: A) => IOOption<B>
  160. /**
  161. * @category sequencing
  162. * @since 2.12.0
  163. */
  164. export declare const chainOptionK: <A, B>(f: (a: A) => Option<B>) => (ma: IOOption<A>) => IOOption<B>
  165. /**
  166. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  167. * use the type constructor `F` to represent some computational context.
  168. *
  169. * @category mapping
  170. * @since 2.12.0
  171. */
  172. export declare const map: <A, B>(f: (a: A) => B) => (fa: IOOption<A>) => IOOption<B>
  173. /**
  174. * @since 2.12.0
  175. */
  176. export declare const ap: <A>(fa: IOOption<A>) => <B>(fab: IOOption<(a: A) => B>) => IOOption<B>
  177. /**
  178. * @category constructors
  179. * @since 2.12.0
  180. */
  181. export declare const of: <A>(a: A) => IOOption<A>
  182. /**
  183. * @category sequencing
  184. * @since 2.12.0
  185. */
  186. export declare const chain: <A, B>(f: (a: A) => IOOption<B>) => (ma: IOOption<A>) => IOOption<B>
  187. /**
  188. * @category sequencing
  189. * @since 2.12.0
  190. */
  191. export declare const flatten: <A>(mma: IOOption<IOOption<A>>) => IOOption<A>
  192. /**
  193. * @category error handling
  194. * @since 2.12.0
  195. */
  196. export declare const alt: <A>(second: Lazy<IOOption<A>>) => (first: IOOption<A>) => IOOption<A>
  197. /**
  198. * Less strict version of [`alt`](#alt).
  199. *
  200. * The `W` suffix (short for **W**idening) means that the return types will be merged.
  201. *
  202. * @category error handling
  203. * @since 2.12.0
  204. */
  205. export declare const altW: <B>(second: Lazy<IOOption<B>>) => <A>(first: IOOption<A>) => IOOption<A | B>
  206. /**
  207. * @since 2.12.0
  208. */
  209. export declare const zero: <A>() => IOOption<A>
  210. /**
  211. * @category constructors
  212. * @since 2.12.0
  213. */
  214. export declare const none: IOOption<never>
  215. /**
  216. * @category filtering
  217. * @since 2.12.0
  218. */
  219. export declare const compact: Compactable1<URI>['compact']
  220. /**
  221. * @category filtering
  222. * @since 2.12.0
  223. */
  224. export declare const separate: Compactable1<URI>['separate']
  225. /**
  226. * @category filtering
  227. * @since 2.12.0
  228. */
  229. export declare const filter: {
  230. <A, B extends A>(refinement: Refinement<A, B>): (fb: IOOption<A>) => IOOption<B>
  231. <A>(predicate: Predicate<A>): <B extends A>(fb: IOOption<B>) => IOOption<B>
  232. <A>(predicate: Predicate<A>): (fa: IOOption<A>) => IOOption<A>
  233. }
  234. /**
  235. * @category filtering
  236. * @since 2.12.0
  237. */
  238. export declare const filterMap: <A, B>(f: (a: A) => Option<B>) => (fga: IOOption<A>) => IOOption<B>
  239. /**
  240. * @category filtering
  241. * @since 2.12.0
  242. */
  243. export declare const partition: {
  244. <A, B extends A>(refinement: Refinement<A, B>): (fb: IOOption<A>) => Separated<IOOption<A>, IOOption<B>>
  245. <A>(predicate: Predicate<A>): <B extends A>(fb: IOOption<B>) => Separated<IOOption<B>, IOOption<B>>
  246. <A>(predicate: Predicate<A>): (fa: IOOption<A>) => Separated<IOOption<A>, IOOption<A>>
  247. }
  248. /**
  249. * @category filtering
  250. * @since 2.12.0
  251. */
  252. export declare const partitionMap: <A, B, C>(
  253. f: (a: A) => Either<B, C>
  254. ) => (fa: IOOption<A>) => Separated<IOOption<B>, IOOption<C>>
  255. /**
  256. * @category type lambdas
  257. * @since 2.12.0
  258. */
  259. export declare const URI = 'IOOption'
  260. /**
  261. * @category type lambdas
  262. * @since 2.12.0
  263. */
  264. export declare type URI = typeof URI
  265. declare module './HKT' {
  266. interface URItoKind<A> {
  267. readonly [URI]: IOOption<A>
  268. }
  269. }
  270. /**
  271. * @category instances
  272. * @since 2.12.0
  273. */
  274. export declare const Functor: Functor1<URI>
  275. /**
  276. * @category mapping
  277. * @since 2.12.0
  278. */
  279. export declare const flap: <A>(a: A) => <B>(fab: IOOption<(a: A) => B>) => IOOption<B>
  280. /**
  281. * @category instances
  282. * @since 2.12.0
  283. */
  284. export declare const Pointed: Pointed1<URI>
  285. /**
  286. * @category instances
  287. * @since 2.12.0
  288. */
  289. export declare const Apply: Apply1<URI>
  290. /**
  291. * Combine two effectful actions, keeping only the result of the first.
  292. *
  293. * @since 2.12.0
  294. */
  295. export declare const apFirst: <B>(second: IOOption<B>) => <A>(first: IOOption<A>) => IOOption<A>
  296. /**
  297. * Combine two effectful actions, keeping only the result of the second.
  298. *
  299. * @since 2.12.0
  300. */
  301. export declare const apSecond: <B>(second: IOOption<B>) => <A>(first: IOOption<A>) => IOOption<B>
  302. /**
  303. * @category instances
  304. * @since 2.12.0
  305. */
  306. export declare const Applicative: Applicative1<URI>
  307. /**
  308. * @category instances
  309. * @since 2.12.0
  310. */
  311. export declare const Chain: Chain1<URI>
  312. /**
  313. * Composes computations in sequence, using the return value of one computation to determine the next computation and
  314. * keeping only the result of the first.
  315. *
  316. * @category sequencing
  317. * @since 2.12.0
  318. */
  319. export declare const chainFirst: <A, B>(f: (a: A) => IOOption<B>) => (first: IOOption<A>) => IOOption<A>
  320. /**
  321. * @category instances
  322. * @since 2.12.0
  323. */
  324. export declare const Alt: Alt1<URI>
  325. /**
  326. * @category instances
  327. * @since 2.12.0
  328. */
  329. export declare const Zero: Zero1<URI>
  330. /**
  331. * @category do notation
  332. * @since 2.12.0
  333. */
  334. export declare const guard: (b: boolean) => IOOption<void>
  335. /**
  336. * @category instances
  337. * @since 2.12.0
  338. */
  339. export declare const Alternative: Alternative1<URI>
  340. /**
  341. * @category instances
  342. * @since 2.12.0
  343. */
  344. export declare const Monad: Monad1<URI>
  345. /**
  346. * @category instances
  347. * @since 2.12.0
  348. */
  349. export declare const MonadIO: MonadIO1<URI>
  350. /**
  351. * @category instances
  352. * @since 2.12.0
  353. */
  354. export declare const Compactable: Compactable1<URI>
  355. /**
  356. * @category instances
  357. * @since 2.12.0
  358. */
  359. export declare const Filterable: Filterable1<URI>
  360. /**
  361. * @category instances
  362. * @since 2.12.0
  363. */
  364. export declare const FromIO: FromIO1<URI>
  365. /**
  366. * @category lifting
  367. * @since 2.12.0
  368. */
  369. export declare const fromIOK: <A extends ReadonlyArray<unknown>, B>(f: (...a: A) => I.IO<B>) => (...a: A) => IOOption<B>
  370. /**
  371. * @category sequencing
  372. * @since 2.12.0
  373. */
  374. export declare const chainIOK: <A, B>(f: (a: A) => I.IO<B>) => (first: IOOption<A>) => IOOption<B>
  375. /**
  376. * @category sequencing
  377. * @since 2.12.0
  378. */
  379. export declare const chainFirstIOK: <A, B>(f: (a: A) => I.IO<B>) => (first: IOOption<A>) => IOOption<A>
  380. /**
  381. * @category instances
  382. * @since 2.12.0
  383. */
  384. export declare const FromEither: FromEither1<URI>
  385. /**
  386. * @category lifting
  387. * @since 2.12.0
  388. */
  389. export declare const fromEitherK: <E, A extends ReadonlyArray<unknown>, B>(
  390. f: (...a: A) => Either<E, B>
  391. ) => (...a: A) => IOOption<B>
  392. /**
  393. * @category sequencing
  394. * @since 2.12.0
  395. */
  396. export declare const chainEitherK: <E, A, B>(f: (a: A) => Either<E, B>) => (ma: IOOption<A>) => IOOption<B>
  397. /**
  398. * @category sequencing
  399. * @since 2.12.0
  400. */
  401. export declare const chainFirstEitherK: <E, A, B>(f: (a: A) => Either<E, B>) => (ma: IOOption<A>) => IOOption<A>
  402. /**
  403. * @category do notation
  404. * @since 2.12.0
  405. */
  406. export declare const Do: IOOption<{}>
  407. /**
  408. * @category do notation
  409. * @since 2.12.0
  410. */
  411. export declare const bindTo: <N extends string>(name: N) => <A>(fa: IOOption<A>) => IOOption<{ readonly [K in N]: A }>
  412. declare const let_: <N extends string, A, B>(
  413. name: Exclude<N, keyof A>,
  414. f: (a: A) => B
  415. ) => (fa: IOOption<A>) => IOOption<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
  416. export {
  417. /**
  418. * @category do notation
  419. * @since 2.13.0
  420. */
  421. let_ as let
  422. }
  423. /**
  424. * @category do notation
  425. * @since 2.12.0
  426. */
  427. export declare const bind: <N extends string, A, B>(
  428. name: Exclude<N, keyof A>,
  429. f: (a: A) => IOOption<B>
  430. ) => (ma: IOOption<A>) => IOOption<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
  431. /**
  432. * @category do notation
  433. * @since 2.12.0
  434. */
  435. export declare const apS: <N extends string, A, B>(
  436. name: Exclude<N, keyof A>,
  437. fb: IOOption<B>
  438. ) => (fa: IOOption<A>) => IOOption<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
  439. /**
  440. * @since 2.12.0
  441. */
  442. export declare const ApT: IOOption<readonly []>
  443. /**
  444. * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(Applicative)`.
  445. *
  446. * @category traversing
  447. * @since 2.12.0
  448. */
  449. export declare const traverseReadonlyNonEmptyArrayWithIndex: <A, B>(
  450. f: (index: number, a: A) => IOOption<B>
  451. ) => (as: ReadonlyNonEmptyArray<A>) => IOOption<ReadonlyNonEmptyArray<B>>
  452. /**
  453. * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.
  454. *
  455. * @category traversing
  456. * @since 2.12.0
  457. */
  458. export declare const traverseReadonlyArrayWithIndex: <A, B>(
  459. f: (index: number, a: A) => IOOption<B>
  460. ) => (as: readonly A[]) => IOOption<readonly B[]>