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

327 lines
7.2 KiB

  1. import { apFirst as apFirst_, apS as apS_, apSecond as apSecond_ } from './Apply';
  2. import { bind as bind_, chainFirst as chainFirst_ } from './Chain';
  3. import { tailRec } from './ChainRec';
  4. import { identity as id, pipe } from './function';
  5. import { let as let__, bindTo as bindTo_, flap as flap_ } from './Functor';
  6. import * as _ from './internal';
  7. var _map = function (fa, f) { return pipe(fa, map(f)); };
  8. var _ap = function (fab, fa) { return pipe(fab, ap(fa)); };
  9. var _chain = function (ma, f) { return pipe(ma, chain(f)); };
  10. /* istanbul ignore next */
  11. var _reduce = function (fa, b, f) { return pipe(fa, reduce(b, f)); };
  12. /* istanbul ignore next */
  13. var _foldMap = function (M) { return function (fa, f) { return pipe(fa, foldMap(M)(f)); }; };
  14. /* istanbul ignore next */
  15. var _reduceRight = function (fa, b, f) { return pipe(fa, reduceRight(b, f)); };
  16. /* istanbul ignore next */
  17. var _alt = function (fa, that) { return pipe(fa, alt(that)); };
  18. /* istanbul ignore next */
  19. var _extend = function (wa, f) { return pipe(wa, extend(f)); };
  20. /* istanbul ignore next */
  21. var _traverse = function (F) {
  22. var traverseF = traverse(F);
  23. return function (ta, f) { return pipe(ta, traverseF(f)); };
  24. };
  25. var _chainRec = tailRec;
  26. /**
  27. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  28. * use the type constructor `F` to represent some computational context.
  29. *
  30. * @category mapping
  31. * @since 2.0.0
  32. */
  33. export var map = function (f) { return function (fa) { return f(fa); }; };
  34. /**
  35. * @since 2.0.0
  36. */
  37. export var ap = function (fa) { return function (fab) { return fab(fa); }; };
  38. /**
  39. * @category constructors
  40. * @since 2.0.0
  41. */
  42. export var of = id;
  43. /**
  44. * Composes computations in sequence, using the return value of one computation to determine the next computation.
  45. *
  46. * @category sequencing
  47. * @since 2.0.0
  48. */
  49. export var chain = function (f) { return function (ma) { return f(ma); }; };
  50. /**
  51. * @since 2.0.0
  52. */
  53. export var extend = function (f) { return function (wa) { return f(wa); }; };
  54. /**
  55. * @category Extract
  56. * @since 2.6.2
  57. */
  58. export var extract = id;
  59. /**
  60. * @since 2.0.0
  61. */
  62. export var duplicate = /*#__PURE__*/ extend(id);
  63. /**
  64. * @category sequencing
  65. * @since 2.0.0
  66. */
  67. export var flatten = /*#__PURE__*/ chain(id);
  68. /**
  69. * @category folding
  70. * @since 2.0.0
  71. */
  72. export var reduce = function (b, f) { return function (fa) { return f(b, fa); }; };
  73. /**
  74. * @category folding
  75. * @since 2.0.0
  76. */
  77. export var foldMap = function () { return function (f) { return function (fa) { return f(fa); }; }; };
  78. /**
  79. * @category folding
  80. * @since 2.0.0
  81. */
  82. export var reduceRight = function (b, f) { return function (fa) { return f(fa, b); }; };
  83. /**
  84. * @category traversing
  85. * @since 2.6.3
  86. */
  87. export var traverse = function (F) {
  88. return function (f) {
  89. return function (ta) {
  90. return F.map(f(ta), id);
  91. };
  92. };
  93. };
  94. /**
  95. * @category traversing
  96. * @since 2.6.3
  97. */
  98. export var sequence = function (F) {
  99. return function (ta) {
  100. return F.map(ta, id);
  101. };
  102. };
  103. /**
  104. * Less strict version of [`alt`](#alt).
  105. *
  106. * The `W` suffix (short for **W**idening) means that the return types will be merged.
  107. *
  108. * @category error handling
  109. * @since 2.9.0
  110. */
  111. export var altW = function () { return id; };
  112. /**
  113. * Identifies an associative operation on a type constructor. It is similar to `Semigroup`, except that it applies to
  114. * types of kind `* -> *`.
  115. *
  116. * @category error handling
  117. * @since 2.0.0
  118. */
  119. export var alt = altW;
  120. /**
  121. * @category type lambdas
  122. * @since 2.0.0
  123. */
  124. export var URI = 'Identity';
  125. /**
  126. * @category instances
  127. * @since 2.0.0
  128. */
  129. export var getShow = id;
  130. /**
  131. * @category instances
  132. * @since 2.0.0
  133. */
  134. export var getEq = id;
  135. /**
  136. * @category instances
  137. * @since 2.7.0
  138. */
  139. export var Functor = {
  140. URI: URI,
  141. map: _map
  142. };
  143. /**
  144. * @category mapping
  145. * @since 2.10.0
  146. */
  147. export var flap = /*#__PURE__*/ flap_(Functor);
  148. /**
  149. * @category instances
  150. * @since 2.10.0
  151. */
  152. export var Pointed = {
  153. URI: URI,
  154. of: of
  155. };
  156. /**
  157. * @category instances
  158. * @since 2.10.0
  159. */
  160. export var Apply = {
  161. URI: URI,
  162. map: _map,
  163. ap: _ap
  164. };
  165. /**
  166. * Combine two effectful actions, keeping only the result of the first.
  167. *
  168. * @since 2.0.0
  169. */
  170. export var apFirst = /*#__PURE__*/ apFirst_(Apply);
  171. /**
  172. * Combine two effectful actions, keeping only the result of the second.
  173. *
  174. * @since 2.0.0
  175. */
  176. export var apSecond = /*#__PURE__*/ apSecond_(Apply);
  177. /**
  178. * @category instances
  179. * @since 2.7.0
  180. */
  181. export var Applicative = {
  182. URI: URI,
  183. map: _map,
  184. ap: _ap,
  185. of: of
  186. };
  187. /**
  188. * @category instances
  189. * @since 2.10.0
  190. */
  191. export var Chain = {
  192. URI: URI,
  193. map: _map,
  194. ap: _ap,
  195. chain: _chain
  196. };
  197. /**
  198. * @category instances
  199. * @since 2.7.0
  200. */
  201. export var Monad = {
  202. URI: URI,
  203. map: _map,
  204. ap: _ap,
  205. of: of,
  206. chain: _chain
  207. };
  208. /**
  209. * Composes computations in sequence, using the return value of one computation to determine the next computation and
  210. * keeping only the result of the first.
  211. *
  212. * @category sequencing
  213. * @since 2.0.0
  214. */
  215. export var chainFirst = /*#__PURE__*/ chainFirst_(Chain);
  216. /**
  217. * @category instances
  218. * @since 2.7.0
  219. */
  220. export var Foldable = {
  221. URI: URI,
  222. reduce: _reduce,
  223. foldMap: _foldMap,
  224. reduceRight: _reduceRight
  225. };
  226. /**
  227. * @category instances
  228. * @since 2.7.0
  229. */
  230. export var Traversable = {
  231. URI: URI,
  232. map: _map,
  233. reduce: _reduce,
  234. foldMap: _foldMap,
  235. reduceRight: _reduceRight,
  236. traverse: _traverse,
  237. sequence: sequence
  238. };
  239. /**
  240. * @category instances
  241. * @since 2.7.0
  242. */
  243. export var Alt = {
  244. URI: URI,
  245. map: _map,
  246. alt: _alt
  247. };
  248. /**
  249. * @category instances
  250. * @since 2.7.0
  251. */
  252. export var Comonad = {
  253. URI: URI,
  254. map: _map,
  255. extend: _extend,
  256. extract: extract
  257. };
  258. /**
  259. * @category instances
  260. * @since 2.7.0
  261. */
  262. export var ChainRec = {
  263. URI: URI,
  264. map: _map,
  265. ap: _ap,
  266. chain: _chain,
  267. chainRec: _chainRec
  268. };
  269. // -------------------------------------------------------------------------------------
  270. // do notation
  271. // -------------------------------------------------------------------------------------
  272. /**
  273. * @category do notation
  274. * @since 2.9.0
  275. */
  276. export var Do = /*#__PURE__*/ of(_.emptyRecord);
  277. /**
  278. * @category do notation
  279. * @since 2.8.0
  280. */
  281. export var bindTo = /*#__PURE__*/ bindTo_(Functor);
  282. var let_ = /*#__PURE__*/ let__(Functor);
  283. export {
  284. /**
  285. * @category do notation
  286. * @since 2.13.0
  287. */
  288. let_ as let };
  289. /**
  290. * @category do notation
  291. * @since 2.8.0
  292. */
  293. export var bind = /*#__PURE__*/ bind_(Chain);
  294. /**
  295. * @category do notation
  296. * @since 2.8.0
  297. */
  298. export var apS = /*#__PURE__*/ apS_(Apply);
  299. // -------------------------------------------------------------------------------------
  300. // deprecated
  301. // -------------------------------------------------------------------------------------
  302. /**
  303. * This instance is deprecated, use small, specific instances instead.
  304. * For example if a function needs a `Functor` instance, pass `I.Functor` instead of `I.identity`
  305. * (where `I` is from `import I from 'fp-ts/Identity'`)
  306. *
  307. * @category zone of death
  308. * @since 2.0.0
  309. * @deprecated
  310. */
  311. export var identity = {
  312. URI: URI,
  313. map: _map,
  314. ap: _ap,
  315. of: of,
  316. chain: _chain,
  317. reduce: _reduce,
  318. foldMap: _foldMap,
  319. reduceRight: _reduceRight,
  320. traverse: _traverse,
  321. sequence: sequence,
  322. alt: _alt,
  323. extract: extract,
  324. extend: _extend,
  325. chainRec: _chainRec
  326. };