版博士V2.0程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ReaderIO.js 9.3 KiB

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