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

IOOption.js 14 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.Monad = exports.Alternative = exports.guard = exports.Zero = exports.Alt = exports.chainFirst = exports.Chain = exports.Applicative = exports.apSecond = exports.apFirst = exports.Apply = exports.Pointed = exports.flap = exports.Functor = exports.URI = exports.partitionMap = exports.partition = exports.filterMap = exports.filter = exports.separate = exports.compact = exports.none = exports.zero = exports.altW = exports.alt = exports.flatten = exports.chain = exports.of = exports.ap = exports.map = exports.chainOptionK = exports.fromOptionK = exports.chainNullableK = exports.fromNullableK = exports.fromNullable = exports.toNullable = exports.toUndefined = exports.getOrElseW = exports.getOrElse = exports.matchEW = exports.fold = exports.matchE = exports.matchW = exports.match = exports.fromIOEither = exports.fromIO = exports.fromEither = exports.fromOption = exports.fromPredicate = exports.some = void 0;
  27. exports.traverseReadonlyArrayWithIndex = exports.traverseReadonlyNonEmptyArrayWithIndex = exports.ApT = exports.apS = exports.bind = exports.let = exports.bindTo = exports.Do = exports.chainFirstEitherK = exports.chainEitherK = exports.fromEitherK = exports.FromEither = exports.chainFirstIOK = exports.chainIOK = exports.fromIOK = exports.FromIO = exports.Filterable = exports.Compactable = exports.MonadIO = void 0;
  28. var Apply_1 = require("./Apply");
  29. var Chain_1 = require("./Chain");
  30. var Compactable_1 = require("./Compactable");
  31. var Filterable_1 = require("./Filterable");
  32. var FromEither_1 = require("./FromEither");
  33. var FromIO_1 = require("./FromIO");
  34. var function_1 = require("./function");
  35. var Functor_1 = require("./Functor");
  36. var _ = __importStar(require("./internal"));
  37. var O = __importStar(require("./Option"));
  38. var OT = __importStar(require("./OptionT"));
  39. var I = __importStar(require("./IO"));
  40. var Zero_1 = require("./Zero");
  41. // -------------------------------------------------------------------------------------
  42. // constructors
  43. // -------------------------------------------------------------------------------------
  44. /**
  45. * @category constructors
  46. * @since 2.12.0
  47. */
  48. exports.some = OT.some(I.Pointed);
  49. /**
  50. * @category lifting
  51. * @since 2.12.0
  52. */
  53. exports.fromPredicate = OT.fromPredicate(I.Pointed);
  54. // -------------------------------------------------------------------------------------
  55. // conversions
  56. // -------------------------------------------------------------------------------------
  57. /**
  58. * @category conversions
  59. * @since 2.12.0
  60. */
  61. exports.fromOption = I.of;
  62. /**
  63. * @category conversions
  64. * @since 2.12.0
  65. */
  66. exports.fromEither = OT.fromEither(I.Pointed);
  67. /**
  68. * @category conversions
  69. * @since 2.12.0
  70. */
  71. exports.fromIO = OT.fromF(I.Functor);
  72. /**
  73. * @category conversions
  74. * @since 2.12.0
  75. */
  76. exports.fromIOEither = I.map(O.fromEither);
  77. /**
  78. * @category pattern matching
  79. * @since 2.12.0
  80. */
  81. exports.match = OT.match(I.Functor);
  82. /**
  83. * Less strict version of [`match`](#match).
  84. *
  85. * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
  86. *
  87. * @category pattern matching
  88. * @since 2.12.0
  89. */
  90. exports.matchW = exports.match;
  91. /**
  92. * The `E` suffix (short for **E**ffect) means that the handlers return an effect (`IO`).
  93. *
  94. * @category pattern matching
  95. * @since 2.12.0
  96. */
  97. exports.matchE =
  98. /*#__PURE__*/ OT.matchE(I.Chain);
  99. /**
  100. * Alias of [`matchE`](#matche).
  101. *
  102. * @category pattern matching
  103. * @since 2.12.0
  104. */
  105. exports.fold = exports.matchE;
  106. /**
  107. * Less strict version of [`matchE`](#matche).
  108. *
  109. * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
  110. *
  111. * @category pattern matching
  112. * @since 2.12.0
  113. */
  114. exports.matchEW = exports.matchE;
  115. /**
  116. * @category error handling
  117. * @since 2.12.0
  118. */
  119. exports.getOrElse = OT.getOrElse(I.Monad);
  120. /**
  121. * Less strict version of [`getOrElse`](#getorelse).
  122. *
  123. * The `W` suffix (short for **W**idening) means that the handler return type will be merged.
  124. *
  125. * @category error handling
  126. * @since 2.12.0
  127. */
  128. exports.getOrElseW = exports.getOrElse;
  129. /**
  130. * @category conversions
  131. * @since 2.12.0
  132. */
  133. exports.toUndefined = I.map(O.toUndefined);
  134. /**
  135. * @category conversions
  136. * @since 2.12.0
  137. */
  138. exports.toNullable = I.map(O.toNullable);
  139. /**
  140. * @category conversions
  141. * @since 2.12.0
  142. */
  143. exports.fromNullable = OT.fromNullable(I.Pointed);
  144. /**
  145. * @category lifting
  146. * @since 2.12.0
  147. */
  148. exports.fromNullableK = OT.fromNullableK(I.Pointed);
  149. /**
  150. * @category sequencing
  151. * @since 2.12.0
  152. */
  153. exports.chainNullableK = OT.chainNullableK(I.Monad);
  154. // -------------------------------------------------------------------------------------
  155. // combinators
  156. // -------------------------------------------------------------------------------------
  157. /**
  158. * @category lifting
  159. * @since 2.12.0
  160. */
  161. exports.fromOptionK =
  162. /*#__PURE__*/ OT.fromOptionK(I.Pointed);
  163. /**
  164. * @category sequencing
  165. * @since 2.12.0
  166. */
  167. exports.chainOptionK =
  168. /*#__PURE__*/ OT.chainOptionK(I.Monad);
  169. /**
  170. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  171. * use the type constructor `F` to represent some computational context.
  172. *
  173. * @category mapping
  174. * @since 2.12.0
  175. */
  176. exports.map = OT.map(I.Functor);
  177. /**
  178. * @since 2.12.0
  179. */
  180. exports.ap = OT.ap(I.Apply);
  181. /**
  182. * @category constructors
  183. * @since 2.12.0
  184. */
  185. exports.of = exports.some;
  186. /**
  187. * @category sequencing
  188. * @since 2.12.0
  189. */
  190. exports.chain = OT.chain(I.Monad);
  191. /**
  192. * @category sequencing
  193. * @since 2.12.0
  194. */
  195. exports.flatten = (0, exports.chain)(function_1.identity);
  196. /**
  197. * @category error handling
  198. * @since 2.12.0
  199. */
  200. exports.alt = OT.alt(I.Monad);
  201. /**
  202. * Less strict version of [`alt`](#alt).
  203. *
  204. * The `W` suffix (short for **W**idening) means that the return types will be merged.
  205. *
  206. * @category error handling
  207. * @since 2.12.0
  208. */
  209. exports.altW = exports.alt;
  210. /**
  211. * @since 2.12.0
  212. */
  213. exports.zero = OT.zero(I.Pointed);
  214. /**
  215. * @category constructors
  216. * @since 2.12.0
  217. */
  218. exports.none = (0, exports.zero)();
  219. /**
  220. * @category filtering
  221. * @since 2.12.0
  222. */
  223. exports.compact = (0, Compactable_1.compact)(I.Functor, O.Compactable);
  224. /**
  225. * @category filtering
  226. * @since 2.12.0
  227. */
  228. exports.separate = (0, Compactable_1.separate)(I.Functor, O.Compactable, O.Functor);
  229. /**
  230. * @category filtering
  231. * @since 2.12.0
  232. */
  233. exports.filter = (0, Filterable_1.filter)(I.Functor, O.Filterable);
  234. /**
  235. * @category filtering
  236. * @since 2.12.0
  237. */
  238. exports.filterMap = (0, Filterable_1.filterMap)(I.Functor, O.Filterable);
  239. /**
  240. * @category filtering
  241. * @since 2.12.0
  242. */
  243. exports.partition = (0, Filterable_1.partition)(I.Functor, O.Filterable);
  244. /**
  245. * @category filtering
  246. * @since 2.12.0
  247. */
  248. exports.partitionMap = (0, Filterable_1.partitionMap)(I.Functor, O.Filterable);
  249. // -------------------------------------------------------------------------------------
  250. // instances
  251. // -------------------------------------------------------------------------------------
  252. var _map = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.map)(f)); };
  253. /* istanbul ignore next */
  254. var _ap = function (fab, fa) { return (0, function_1.pipe)(fab, (0, exports.ap)(fa)); };
  255. /* istanbul ignore next */
  256. var _chain = function (ma, f) { return (0, function_1.pipe)(ma, (0, exports.chain)(f)); };
  257. /* istanbul ignore next */
  258. var _alt = function (fa, that) { return (0, function_1.pipe)(fa, (0, exports.alt)(that)); };
  259. /* istanbul ignore next */
  260. var _filter = function (fa, predicate) { return (0, function_1.pipe)(fa, (0, exports.filter)(predicate)); };
  261. /* istanbul ignore next */
  262. var _filterMap = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.filterMap)(f)); };
  263. /* istanbul ignore next */
  264. var _partition = function (fa, predicate) {
  265. return (0, function_1.pipe)(fa, (0, exports.partition)(predicate));
  266. };
  267. /* istanbul ignore next */
  268. var _partitionMap = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.partitionMap)(f)); };
  269. /**
  270. * @category type lambdas
  271. * @since 2.12.0
  272. */
  273. exports.URI = 'IOOption';
  274. /**
  275. * @category instances
  276. * @since 2.12.0
  277. */
  278. exports.Functor = {
  279. URI: exports.URI,
  280. map: _map
  281. };
  282. /**
  283. * @category mapping
  284. * @since 2.12.0
  285. */
  286. exports.flap = (0, Functor_1.flap)(exports.Functor);
  287. /**
  288. * @category instances
  289. * @since 2.12.0
  290. */
  291. exports.Pointed = {
  292. URI: exports.URI,
  293. of: exports.of
  294. };
  295. /**
  296. * @category instances
  297. * @since 2.12.0
  298. */
  299. exports.Apply = {
  300. URI: exports.URI,
  301. map: _map,
  302. ap: _ap
  303. };
  304. /**
  305. * Combine two effectful actions, keeping only the result of the first.
  306. *
  307. * @since 2.12.0
  308. */
  309. exports.apFirst = (0, Apply_1.apFirst)(exports.Apply);
  310. /**
  311. * Combine two effectful actions, keeping only the result of the second.
  312. *
  313. * @since 2.12.0
  314. */
  315. exports.apSecond = (0, Apply_1.apSecond)(exports.Apply);
  316. /**
  317. * @category instances
  318. * @since 2.12.0
  319. */
  320. exports.Applicative = {
  321. URI: exports.URI,
  322. map: _map,
  323. ap: _ap,
  324. of: exports.of
  325. };
  326. /**
  327. * @category instances
  328. * @since 2.12.0
  329. */
  330. exports.Chain = {
  331. URI: exports.URI,
  332. map: _map,
  333. ap: _ap,
  334. chain: _chain
  335. };
  336. /**
  337. * Composes computations in sequence, using the return value of one computation to determine the next computation and
  338. * keeping only the result of the first.
  339. *
  340. * @category sequencing
  341. * @since 2.12.0
  342. */
  343. exports.chainFirst =
  344. /*#__PURE__*/ (0, Chain_1.chainFirst)(exports.Chain);
  345. /**
  346. * @category instances
  347. * @since 2.12.0
  348. */
  349. exports.Alt = {
  350. URI: exports.URI,
  351. map: _map,
  352. alt: _alt
  353. };
  354. /**
  355. * @category instances
  356. * @since 2.12.0
  357. */
  358. exports.Zero = {
  359. URI: exports.URI,
  360. zero: exports.zero
  361. };
  362. /**
  363. * @category do notation
  364. * @since 2.12.0
  365. */
  366. exports.guard = (0, Zero_1.guard)(exports.Zero, exports.Pointed);
  367. /**
  368. * @category instances
  369. * @since 2.12.0
  370. */
  371. exports.Alternative = {
  372. URI: exports.URI,
  373. map: _map,
  374. ap: _ap,
  375. of: exports.of,
  376. alt: _alt,
  377. zero: exports.zero
  378. };
  379. /**
  380. * @category instances
  381. * @since 2.12.0
  382. */
  383. exports.Monad = {
  384. URI: exports.URI,
  385. map: _map,
  386. ap: _ap,
  387. of: exports.of,
  388. chain: _chain
  389. };
  390. /**
  391. * @category instances
  392. * @since 2.12.0
  393. */
  394. exports.MonadIO = {
  395. URI: exports.URI,
  396. map: _map,
  397. ap: _ap,
  398. of: exports.of,
  399. chain: _chain,
  400. fromIO: exports.fromIO
  401. };
  402. /**
  403. * @category instances
  404. * @since 2.12.0
  405. */
  406. exports.Compactable = {
  407. URI: exports.URI,
  408. compact: exports.compact,
  409. separate: exports.separate
  410. };
  411. /**
  412. * @category instances
  413. * @since 2.12.0
  414. */
  415. exports.Filterable = {
  416. URI: exports.URI,
  417. map: _map,
  418. compact: exports.compact,
  419. separate: exports.separate,
  420. filter: _filter,
  421. filterMap: _filterMap,
  422. partition: _partition,
  423. partitionMap: _partitionMap
  424. };
  425. /**
  426. * @category instances
  427. * @since 2.12.0
  428. */
  429. exports.FromIO = {
  430. URI: exports.URI,
  431. fromIO: exports.fromIO
  432. };
  433. /**
  434. * @category lifting
  435. * @since 2.12.0
  436. */
  437. exports.fromIOK =
  438. /*#__PURE__*/ (0, FromIO_1.fromIOK)(exports.FromIO);
  439. /**
  440. * @category sequencing
  441. * @since 2.12.0
  442. */
  443. exports.chainIOK = (0, FromIO_1.chainIOK)(exports.FromIO, exports.Chain);
  444. /**
  445. * @category sequencing
  446. * @since 2.12.0
  447. */
  448. exports.chainFirstIOK =
  449. /*#__PURE__*/ (0, FromIO_1.chainFirstIOK)(exports.FromIO, exports.Chain);
  450. /**
  451. * @category instances
  452. * @since 2.12.0
  453. */
  454. exports.FromEither = {
  455. URI: exports.URI,
  456. fromEither: exports.fromEither
  457. };
  458. /**
  459. * @category lifting
  460. * @since 2.12.0
  461. */
  462. exports.fromEitherK = (0, FromEither_1.fromEitherK)(exports.FromEither);
  463. /**
  464. * @category sequencing
  465. * @since 2.12.0
  466. */
  467. exports.chainEitherK =
  468. /*#__PURE__*/ (0, FromEither_1.chainEitherK)(exports.FromEither, exports.Chain);
  469. /**
  470. * @category sequencing
  471. * @since 2.12.0
  472. */
  473. exports.chainFirstEitherK =
  474. /*#__PURE__*/ (0, FromEither_1.chainFirstEitherK)(exports.FromEither, exports.Chain);
  475. // -------------------------------------------------------------------------------------
  476. // do notation
  477. // -------------------------------------------------------------------------------------
  478. /**
  479. * @category do notation
  480. * @since 2.12.0
  481. */
  482. exports.Do = (0, exports.of)(_.emptyRecord);
  483. /**
  484. * @category do notation
  485. * @since 2.12.0
  486. */
  487. exports.bindTo = (0, Functor_1.bindTo)(exports.Functor);
  488. var let_ = /*#__PURE__*/ (0, Functor_1.let)(exports.Functor);
  489. exports.let = let_;
  490. /**
  491. * @category do notation
  492. * @since 2.12.0
  493. */
  494. exports.bind = (0, Chain_1.bind)(exports.Chain);
  495. /**
  496. * @category do notation
  497. * @since 2.12.0
  498. */
  499. exports.apS = (0, Apply_1.apS)(exports.Apply);
  500. /**
  501. * @since 2.12.0
  502. */
  503. exports.ApT = (0, exports.of)(_.emptyReadonlyArray);
  504. // -------------------------------------------------------------------------------------
  505. // array utils
  506. // -------------------------------------------------------------------------------------
  507. /**
  508. * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(Applicative)`.
  509. *
  510. * @category traversing
  511. * @since 2.12.0
  512. */
  513. var traverseReadonlyNonEmptyArrayWithIndex = function (f) {
  514. return (0, function_1.flow)(I.traverseReadonlyNonEmptyArrayWithIndex(f), I.map(O.traverseReadonlyNonEmptyArrayWithIndex(function_1.SK)));
  515. };
  516. exports.traverseReadonlyNonEmptyArrayWithIndex = traverseReadonlyNonEmptyArrayWithIndex;
  517. /**
  518. * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.
  519. *
  520. * @category traversing
  521. * @since 2.12.0
  522. */
  523. var traverseReadonlyArrayWithIndex = function (f) {
  524. var g = (0, exports.traverseReadonlyNonEmptyArrayWithIndex)(f);
  525. return function (as) { return (_.isNonEmpty(as) ? g(as) : exports.ApT); };
  526. };
  527. exports.traverseReadonlyArrayWithIndex = traverseReadonlyArrayWithIndex;