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

417 строки
12 KiB

  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.sequenceArray = exports.traverseArray = exports.traverseArrayWithIndex = exports.traverseReadonlyArrayWithIndex = exports.traverseReadonlyNonEmptyArrayWithIndex = exports.ApT = exports.apSW = exports.apS = exports.bindW = exports.bind = exports.bindTo = exports.Do = exports.chainFirstReaderKW = exports.chainFirstReaderK = exports.chainReaderKW = exports.chainReaderK = exports.fromReaderK = exports.asks = exports.ask = exports.FromReader = exports.chainFirstIOK = exports.chainIOK = exports.fromIOK = exports.FromIO = exports.chainFirstW = exports.chainFirst = exports.MonadIO = exports.Monad = exports.Chain = exports.Applicative = exports.apSecond = exports.apFirst = exports.Apply = exports.Pointed = exports.flap = exports.Functor = exports.URI = exports.flatten = exports.flattenW = exports.chainW = exports.chain = exports.of = exports.apW = exports.ap = exports.map = exports.asksReaderIO = exports.asksReaderIOW = exports.local = exports.fromIO = exports.fromReader = void 0;
  27. var Apply_1 = require("./Apply");
  28. var Chain_1 = require("./Chain");
  29. var FromIO_1 = require("./FromIO");
  30. var FromReader_1 = require("./FromReader");
  31. var function_1 = require("./function");
  32. var Functor_1 = require("./Functor");
  33. var _ = __importStar(require("./internal"));
  34. var I = __importStar(require("./IO"));
  35. var R = __importStar(require("./Reader"));
  36. var RT = __importStar(require("./ReaderT"));
  37. // -------------------------------------------------------------------------------------
  38. // conversions
  39. // -------------------------------------------------------------------------------------
  40. /**
  41. * @category conversions
  42. * @since 2.13.0
  43. */
  44. exports.fromReader = RT.fromReader(I.Pointed);
  45. /**
  46. * @category conversions
  47. * @since 2.13.0
  48. */
  49. exports.fromIO = R.of;
  50. // -------------------------------------------------------------------------------------
  51. // combinators
  52. // -------------------------------------------------------------------------------------
  53. /**
  54. * Changes the value of the local context during the execution of the action `ma` (similar to `Contravariant`'s
  55. * `contramap`).
  56. *
  57. * @since 2.13.0
  58. */
  59. exports.local = R.local;
  60. /**
  61. * Less strict version of [`asksReaderIO`](#asksreaderio).
  62. *
  63. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  64. *
  65. * @category constructors
  66. * @since 2.13.0
  67. */
  68. exports.asksReaderIOW = R.asksReaderW;
  69. /**
  70. * Effectfully accesses the environment.
  71. *
  72. * @category constructors
  73. * @since 2.13.0
  74. */
  75. exports.asksReaderIO = exports.asksReaderIOW;
  76. var _map = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.map)(f)); };
  77. var _ap = function (fab, fa) { return (0, function_1.pipe)(fab, (0, exports.ap)(fa)); };
  78. var _chain = function (ma, f) { return (0, function_1.pipe)(ma, (0, exports.chain)(f)); };
  79. /**
  80. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  81. * use the type constructor `F` to represent some computational context.
  82. *
  83. * @category mapping
  84. * @since 2.13.0
  85. */
  86. exports.map = RT.map(I.Functor);
  87. /**
  88. * @since 2.13.0
  89. */
  90. exports.ap =
  91. /*#__PURE__*/ RT.ap(I.Apply);
  92. /**
  93. * Less strict version of [`ap`](#ap).
  94. *
  95. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  96. *
  97. * @since 2.13.0
  98. */
  99. exports.apW = exports.ap;
  100. /**
  101. * @category constructors
  102. * @since 2.13.0
  103. */
  104. exports.of = RT.of(I.Pointed);
  105. /**
  106. * Composes computations in sequence, using the return value of one computation to determine the next computation.
  107. *
  108. * @category sequencing
  109. * @since 2.13.0
  110. */
  111. exports.chain =
  112. /*#__PURE__*/ RT.chain(I.Monad);
  113. /**
  114. * Less strict version of [`chain`](#chain).
  115. *
  116. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  117. *
  118. * @category sequencing
  119. * @since 2.13.0
  120. */
  121. exports.chainW = exports.chain;
  122. /**
  123. * Less strict version of [`flatten`](#flatten).
  124. *
  125. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  126. *
  127. * @category sequencing
  128. * @since 2.13.0
  129. */
  130. exports.flattenW =
  131. /*#__PURE__*/ (0, exports.chainW)(function_1.identity);
  132. /**
  133. * @category sequencing
  134. * @since 2.13.0
  135. */
  136. exports.flatten = exports.flattenW;
  137. /**
  138. * @category type lambdas
  139. * @since 2.13.0
  140. */
  141. exports.URI = 'ReaderIO';
  142. /**
  143. * @category instances
  144. * @since 2.13.0
  145. */
  146. exports.Functor = {
  147. URI: exports.URI,
  148. map: _map
  149. };
  150. /**
  151. * @category mapping
  152. * @since 2.13.0
  153. */
  154. exports.flap = (0, Functor_1.flap)(exports.Functor);
  155. /**
  156. * @category instances
  157. * @since 2.13.0
  158. */
  159. exports.Pointed = {
  160. URI: exports.URI,
  161. of: exports.of
  162. };
  163. /**
  164. * @category instances
  165. * @since 2.13.0
  166. */
  167. exports.Apply = {
  168. URI: exports.URI,
  169. map: _map,
  170. ap: _ap
  171. };
  172. /**
  173. * Combine two effectful actions, keeping only the result of the first.
  174. *
  175. * @since 2.13.0
  176. */
  177. exports.apFirst = (0, Apply_1.apFirst)(exports.Apply);
  178. /**
  179. * Combine two effectful actions, keeping only the result of the second.
  180. *
  181. * @since 2.13.0
  182. */
  183. exports.apSecond = (0, Apply_1.apSecond)(exports.Apply);
  184. /**
  185. * @category instances
  186. * @since 2.13.0
  187. */
  188. exports.Applicative = {
  189. URI: exports.URI,
  190. map: _map,
  191. ap: _ap,
  192. of: exports.of
  193. };
  194. /**
  195. * @category instances
  196. * @since 2.13.0
  197. */
  198. exports.Chain = {
  199. URI: exports.URI,
  200. map: _map,
  201. ap: _ap,
  202. chain: _chain
  203. };
  204. /**
  205. * @category instances
  206. * @since 2.13.0
  207. */
  208. exports.Monad = {
  209. URI: exports.URI,
  210. map: _map,
  211. of: exports.of,
  212. ap: _ap,
  213. chain: _chain
  214. };
  215. /**
  216. * @category instances
  217. * @since 2.13.0
  218. */
  219. exports.MonadIO = {
  220. URI: exports.URI,
  221. map: _map,
  222. of: exports.of,
  223. ap: _ap,
  224. chain: _chain,
  225. fromIO: exports.fromIO
  226. };
  227. /**
  228. * Composes computations in sequence, using the return value of one computation to determine the next computation and
  229. * keeping only the result of the first.
  230. *
  231. * @category sequencing
  232. * @since 2.13.0
  233. */
  234. exports.chainFirst =
  235. /*#__PURE__*/ (0, Chain_1.chainFirst)(exports.Chain);
  236. /**
  237. * Less strict version of [`chainFirst`](#chainfirst).
  238. *
  239. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  240. *
  241. * @category sequencing
  242. * @since 2.13.0
  243. */
  244. exports.chainFirstW = exports.chainFirst;
  245. /**
  246. * @category instances
  247. * @since 2.13.0
  248. */
  249. exports.FromIO = {
  250. URI: exports.URI,
  251. fromIO: exports.fromIO
  252. };
  253. /**
  254. * @category lifting
  255. * @since 2.13.0
  256. */
  257. exports.fromIOK = (0, FromIO_1.fromIOK)(exports.FromIO);
  258. /**
  259. * @category sequencing
  260. * @since 2.13.0
  261. */
  262. exports.chainIOK =
  263. /*#__PURE__*/ (0, FromIO_1.chainIOK)(exports.FromIO, exports.Chain);
  264. /**
  265. * @category sequencing
  266. * @since 2.13.0
  267. */
  268. exports.chainFirstIOK =
  269. /*#__PURE__*/ (0, FromIO_1.chainFirstIOK)(exports.FromIO, exports.Chain);
  270. /**
  271. * @category instances
  272. * @since 2.13.0
  273. */
  274. exports.FromReader = {
  275. URI: exports.URI,
  276. fromReader: exports.fromReader
  277. };
  278. /**
  279. * Reads the current context.
  280. *
  281. * @category constructors
  282. * @since 2.13.0
  283. */
  284. exports.ask = (0, FromReader_1.ask)(exports.FromReader);
  285. /**
  286. * Projects a value from the global context in a `ReaderIO`.
  287. *
  288. * @category constructors
  289. * @since 2.13.0
  290. */
  291. exports.asks = (0, FromReader_1.asks)(exports.FromReader);
  292. /**
  293. * @category lifting
  294. * @since 2.13.0
  295. */
  296. exports.fromReaderK = (0, FromReader_1.fromReaderK)(exports.FromReader);
  297. /**
  298. * @category sequencing
  299. * @since 2.13.0
  300. */
  301. exports.chainReaderK =
  302. /*#__PURE__*/ (0, FromReader_1.chainReaderK)(exports.FromReader, exports.Chain);
  303. /**
  304. * Less strict version of [`chainReaderK`](#chainreaderk).
  305. *
  306. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  307. *
  308. * @category sequencing
  309. * @since 2.13.0
  310. */
  311. exports.chainReaderKW = exports.chainReaderK;
  312. /**
  313. * @category sequencing
  314. * @since 2.13.0
  315. */
  316. exports.chainFirstReaderK =
  317. /*#__PURE__*/ (0, FromReader_1.chainFirstReaderK)(exports.FromReader, exports.Chain);
  318. /**
  319. * Less strict version of [`chainFirstReaderK`](#chainfirstreaderk).
  320. *
  321. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  322. *
  323. * @category sequencing
  324. * @since 2.13.0
  325. */
  326. exports.chainFirstReaderKW = exports.chainFirstReaderK;
  327. // -------------------------------------------------------------------------------------
  328. // do notation
  329. // -------------------------------------------------------------------------------------
  330. /**
  331. * @category do notation
  332. * @since 2.13.0
  333. */
  334. exports.Do = (0, exports.of)(_.emptyRecord);
  335. /**
  336. * @category do notation
  337. * @since 2.13.0
  338. */
  339. exports.bindTo = (0, Functor_1.bindTo)(exports.Functor);
  340. /**
  341. * @category do notation
  342. * @since 2.13.0
  343. */
  344. exports.bind = (0, Chain_1.bind)(exports.Chain);
  345. /**
  346. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  347. *
  348. * @category do notation
  349. * @since 2.13.0
  350. */
  351. exports.bindW = exports.bind;
  352. /**
  353. * @category do notation
  354. * @since 2.13.0
  355. */
  356. exports.apS = (0, Apply_1.apS)(exports.Apply);
  357. /**
  358. * Less strict version of [`apS`](#aps).
  359. *
  360. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  361. *
  362. * @category do notation
  363. * @since 2.13.0
  364. */
  365. exports.apSW = exports.apS;
  366. /**
  367. * @since 2.13.0
  368. */
  369. exports.ApT = (0, exports.of)(_.emptyReadonlyArray);
  370. // -------------------------------------------------------------------------------------
  371. // array utils
  372. // -------------------------------------------------------------------------------------
  373. /**
  374. * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(Applicative)`.
  375. *
  376. * @category traversing
  377. * @since 2.13.0
  378. */
  379. var traverseReadonlyNonEmptyArrayWithIndex = function (f) {
  380. return (0, function_1.flow)(R.traverseReadonlyNonEmptyArrayWithIndex(f), R.map(I.traverseReadonlyNonEmptyArrayWithIndex(function_1.SK)));
  381. };
  382. exports.traverseReadonlyNonEmptyArrayWithIndex = traverseReadonlyNonEmptyArrayWithIndex;
  383. /**
  384. * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.
  385. *
  386. * @category traversing
  387. * @since 2.13.0
  388. */
  389. var traverseReadonlyArrayWithIndex = function (f) {
  390. var g = (0, exports.traverseReadonlyNonEmptyArrayWithIndex)(f);
  391. return function (as) { return (_.isNonEmpty(as) ? g(as) : exports.ApT); };
  392. };
  393. exports.traverseReadonlyArrayWithIndex = traverseReadonlyArrayWithIndex;
  394. /**
  395. * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.
  396. *
  397. * @category traversing
  398. * @since 2.13.0
  399. */
  400. exports.traverseArrayWithIndex = exports.traverseReadonlyArrayWithIndex;
  401. /**
  402. * Equivalent to `ReadonlyArray#traverse(Applicative)`.
  403. *
  404. * @category traversing
  405. * @since 2.13.0
  406. */
  407. var traverseArray = function (f) { return (0, exports.traverseReadonlyArrayWithIndex)(function (_, a) { return f(a); }); };
  408. exports.traverseArray = traverseArray;
  409. /**
  410. * Equivalent to `ReadonlyArray#sequence(Applicative)`.
  411. *
  412. * @category traversing
  413. * @since 2.13.0
  414. */
  415. exports.sequenceArray =
  416. /*#__PURE__*/ (0, exports.traverseArray)(function_1.identity);