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

356 rivejä
9.5 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.tuple = exports.mapLeft = exports.map = exports.Traversable = exports.Foldable = exports.Comonad = exports.Semigroupoid = exports.Bifunctor = exports.flap = exports.Functor = exports.URI = exports.sequence = exports.traverse = exports.reduceRight = exports.reduce = exports.foldMap = exports.extract = exports.duplicate = exports.extend = exports.compose = exports.mapSnd = exports.mapFst = exports.bimap = exports.getChainRec = exports.getMonad = exports.getChain = exports.getApplicative = exports.getApply = exports.swap = exports.snd = exports.fst = void 0;
  27. var RT = __importStar(require("./ReadonlyTuple"));
  28. var Functor_1 = require("./Functor");
  29. var function_1 = require("./function");
  30. // -------------------------------------------------------------------------------------
  31. // model
  32. // -------------------------------------------------------------------------------------
  33. /**
  34. * @since 2.0.0
  35. */
  36. exports.fst = RT.fst;
  37. /**
  38. * @since 2.0.0
  39. */
  40. exports.snd = RT.snd;
  41. /**
  42. * @since 2.0.0
  43. */
  44. var swap = function (ea) { return [(0, exports.snd)(ea), (0, exports.fst)(ea)]; };
  45. exports.swap = swap;
  46. /**
  47. * @category instances
  48. * @since 2.0.0
  49. */
  50. function getApply(S) {
  51. return {
  52. URI: exports.URI,
  53. _E: undefined,
  54. map: _map,
  55. ap: function (fab, fa) { return [(0, exports.fst)(fab)((0, exports.fst)(fa)), S.concat((0, exports.snd)(fab), (0, exports.snd)(fa))]; }
  56. };
  57. }
  58. exports.getApply = getApply;
  59. var of = function (M) {
  60. return function (a) {
  61. return [a, M.empty];
  62. };
  63. };
  64. /**
  65. * @category instances
  66. * @since 2.0.0
  67. */
  68. function getApplicative(M) {
  69. var A = getApply(M);
  70. return {
  71. URI: exports.URI,
  72. _E: undefined,
  73. map: A.map,
  74. ap: A.ap,
  75. of: of(M)
  76. };
  77. }
  78. exports.getApplicative = getApplicative;
  79. /**
  80. * @category instances
  81. * @since 2.0.0
  82. */
  83. function getChain(S) {
  84. var A = getApply(S);
  85. return {
  86. URI: exports.URI,
  87. _E: undefined,
  88. map: A.map,
  89. ap: A.ap,
  90. chain: function (ma, f) {
  91. var _a = f((0, exports.fst)(ma)), b = _a[0], s = _a[1];
  92. return [b, S.concat((0, exports.snd)(ma), s)];
  93. }
  94. };
  95. }
  96. exports.getChain = getChain;
  97. /**
  98. * @category instances
  99. * @since 2.0.0
  100. */
  101. function getMonad(M) {
  102. var C = getChain(M);
  103. return {
  104. URI: exports.URI,
  105. _E: undefined,
  106. map: C.map,
  107. ap: C.ap,
  108. chain: C.chain,
  109. of: of(M)
  110. };
  111. }
  112. exports.getMonad = getMonad;
  113. /**
  114. * @category instances
  115. * @since 2.0.0
  116. */
  117. function getChainRec(M) {
  118. var chainRec = function (a, f) {
  119. var result = f(a);
  120. var acc = M.empty;
  121. var s = (0, exports.fst)(result);
  122. while (s._tag === 'Left') {
  123. acc = M.concat(acc, (0, exports.snd)(result));
  124. result = f(s.left);
  125. s = (0, exports.fst)(result);
  126. }
  127. return [s.right, M.concat(acc, (0, exports.snd)(result))];
  128. };
  129. var C = getChain(M);
  130. return {
  131. URI: exports.URI,
  132. _E: undefined,
  133. map: C.map,
  134. ap: C.ap,
  135. chain: C.chain,
  136. chainRec: chainRec
  137. };
  138. }
  139. exports.getChainRec = getChainRec;
  140. /* istanbul ignore next */
  141. var _compose = function (bc, ab) { return (0, function_1.pipe)(bc, (0, exports.compose)(ab)); };
  142. /* istanbul ignore next */
  143. var _map = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.mapFst)(f)); };
  144. /* istanbul ignore next */
  145. var _bimap = function (fa, f, g) { return (0, function_1.pipe)(fa, (0, exports.bimap)(f, g)); };
  146. /* istanbul ignore next */
  147. var _mapLeft = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.mapSnd)(f)); };
  148. /* istanbul ignore next */
  149. var _extend = function (wa, f) { return (0, function_1.pipe)(wa, (0, exports.extend)(f)); };
  150. /* istanbul ignore next */
  151. var _reduce = function (fa, b, f) { return (0, function_1.pipe)(fa, (0, exports.reduce)(b, f)); };
  152. /* istanbul ignore next */
  153. var _foldMap = function (M) {
  154. var foldMapM = (0, exports.foldMap)(M);
  155. return function (fa, f) { return (0, function_1.pipe)(fa, foldMapM(f)); };
  156. };
  157. /* istanbul ignore next */
  158. var _reduceRight = function (fa, b, f) { return (0, function_1.pipe)(fa, (0, exports.reduceRight)(b, f)); };
  159. /* istanbul ignore next */
  160. function _traverse(F) {
  161. var traverseF = (0, exports.traverse)(F);
  162. return function (ta, f) { return (0, function_1.pipe)(ta, traverseF(f)); };
  163. }
  164. /**
  165. * Map a pair of functions over the two type arguments of the bifunctor.
  166. *
  167. * @category mapping
  168. * @since 2.0.0
  169. */
  170. var bimap = function (f, g) { return function (fa) {
  171. return [g((0, exports.fst)(fa)), f((0, exports.snd)(fa))];
  172. }; };
  173. exports.bimap = bimap;
  174. /**
  175. * Map a function over the first component of a `Tuple`.
  176. *
  177. * This is the `map` operation of the `Functor` instance.
  178. *
  179. * @category mapping
  180. * @since 2.0.0
  181. */
  182. var mapFst = function (f) { return function (fa) { return [f((0, exports.fst)(fa)), (0, exports.snd)(fa)]; }; };
  183. exports.mapFst = mapFst;
  184. /**
  185. * Map a function over the second component of a `Tuple`.
  186. *
  187. * This is the `mapLeft` operation of the `Bifunctor` instance.
  188. *
  189. * @category mapping
  190. * @since 2.10.0
  191. */
  192. var mapSnd = function (f) { return function (fa) { return [(0, exports.fst)(fa), f((0, exports.snd)(fa))]; }; };
  193. exports.mapSnd = mapSnd;
  194. /**
  195. * @since 2.0.0
  196. */
  197. var compose = function (ab) { return function (bc) { return [(0, exports.fst)(bc), (0, exports.snd)(ab)]; }; };
  198. exports.compose = compose;
  199. /**
  200. * @since 2.0.0
  201. */
  202. var extend = function (f) { return function (wa) { return [f(wa), (0, exports.snd)(wa)]; }; };
  203. exports.extend = extend;
  204. /**
  205. * @since 2.0.0
  206. */
  207. exports.duplicate = (0, exports.extend)(function_1.identity);
  208. /**
  209. * @category Extract
  210. * @since 2.6.2
  211. */
  212. exports.extract = RT.extract;
  213. /**
  214. * @category folding
  215. * @since 2.0.0
  216. */
  217. exports.foldMap = RT.foldMap;
  218. /**
  219. * @category folding
  220. * @since 2.0.0
  221. */
  222. exports.reduce = RT.reduce;
  223. /**
  224. * @category folding
  225. * @since 2.0.0
  226. */
  227. exports.reduceRight = RT.reduceRight;
  228. /**
  229. * @category traversing
  230. * @since 2.6.3
  231. */
  232. var traverse = function (F) {
  233. return function (f) { return function (ta) { return F.map(f((0, exports.fst)(ta)), function (b) { return [b, (0, exports.snd)(ta)]; }); }; };
  234. };
  235. exports.traverse = traverse;
  236. /**
  237. * @category traversing
  238. * @since 2.6.3
  239. */
  240. var sequence = function (F) {
  241. return function (fas) {
  242. return F.map((0, exports.fst)(fas), function (a) { return [a, (0, exports.snd)(fas)]; });
  243. };
  244. };
  245. exports.sequence = sequence;
  246. /**
  247. * @category type lambdas
  248. * @since 2.0.0
  249. */
  250. exports.URI = 'Tuple';
  251. /**
  252. * @category instances
  253. * @since 2.7.0
  254. */
  255. exports.Functor = {
  256. URI: exports.URI,
  257. map: _map
  258. };
  259. /**
  260. * @category mapping
  261. * @since 2.10.0
  262. */
  263. exports.flap = (0, Functor_1.flap)(exports.Functor);
  264. /**
  265. * @category instances
  266. * @since 2.7.0
  267. */
  268. exports.Bifunctor = {
  269. URI: exports.URI,
  270. bimap: _bimap,
  271. mapLeft: _mapLeft
  272. };
  273. /**
  274. * @category instances
  275. * @since 2.7.0
  276. */
  277. exports.Semigroupoid = {
  278. URI: exports.URI,
  279. compose: _compose
  280. };
  281. /**
  282. * @category instances
  283. * @since 2.7.0
  284. */
  285. exports.Comonad = {
  286. URI: exports.URI,
  287. map: _map,
  288. extend: _extend,
  289. extract: exports.extract
  290. };
  291. /**
  292. * @category instances
  293. * @since 2.7.0
  294. */
  295. exports.Foldable = {
  296. URI: exports.URI,
  297. reduce: _reduce,
  298. foldMap: _foldMap,
  299. reduceRight: _reduceRight
  300. };
  301. /**
  302. * @category instances
  303. * @since 2.7.0
  304. */
  305. exports.Traversable = {
  306. URI: exports.URI,
  307. map: _map,
  308. reduce: _reduce,
  309. foldMap: _foldMap,
  310. reduceRight: _reduceRight,
  311. traverse: _traverse,
  312. sequence: exports.sequence
  313. };
  314. // -------------------------------------------------------------------------------------
  315. // deprecated
  316. // -------------------------------------------------------------------------------------
  317. /**
  318. * Use [`mapFst`](#mapfst) instead.
  319. *
  320. * @category zone of death
  321. * @since 2.0.0
  322. * @deprecated
  323. */
  324. exports.map = exports.mapFst;
  325. /**
  326. * Use [`mapSnd`](#mapsnd) instead.
  327. *
  328. * @category zone of death
  329. * @since 2.0.0
  330. * @deprecated
  331. */
  332. exports.mapLeft = exports.mapSnd;
  333. /**
  334. * This instance is deprecated, use small, specific instances instead.
  335. * For example if a function needs a `Functor` instance, pass `T.Functor` instead of `T.tuple`
  336. * (where `T` is from `import T from 'fp-ts/Tuple'`)
  337. *
  338. * @category zone of death
  339. * @since 2.0.0
  340. * @deprecated
  341. */
  342. exports.tuple = {
  343. URI: exports.URI,
  344. compose: _compose,
  345. map: _map,
  346. bimap: _bimap,
  347. mapLeft: _mapLeft,
  348. extract: exports.extract,
  349. extend: _extend,
  350. reduce: _reduce,
  351. foldMap: _foldMap,
  352. reduceRight: _reduceRight,
  353. traverse: _traverse,
  354. sequence: exports.sequence
  355. };