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

422 lines
12 KiB

  1. import { Compactable2 } from './Compactable'
  2. import { Either } from './Either'
  3. import { Eq } from './Eq'
  4. import { Filterable2 } from './Filterable'
  5. import { FilterableWithIndex2C } from './FilterableWithIndex'
  6. import { Foldable, Foldable1, Foldable2, Foldable2C, Foldable3 } from './Foldable'
  7. import { FoldableWithIndex2C } from './FoldableWithIndex'
  8. import { Functor2 } from './Functor'
  9. import { HKT, Kind, Kind2, Kind3, URIS, URIS2, URIS3 } from './HKT'
  10. import { Magma } from './Magma'
  11. import { Monoid } from './Monoid'
  12. import * as O from './Option'
  13. import { Ord } from './Ord'
  14. import { Predicate } from './Predicate'
  15. import { Refinement } from './Refinement'
  16. import { Semigroup } from './Semigroup'
  17. import { Separated } from './Separated'
  18. import { Show } from './Show'
  19. import { TraversableWithIndex2C } from './TraversableWithIndex'
  20. import { Unfoldable, Unfoldable1 } from './Unfoldable'
  21. import { Witherable2C } from './Witherable'
  22. import Option = O.Option
  23. /**
  24. * @category instances
  25. * @since 2.0.0
  26. */
  27. export declare const getShow: <K, A>(SK: Show<K>, SA: Show<A>) => Show<Map<K, A>>
  28. /**
  29. * Calculate the number of key/value pairs in a map
  30. *
  31. * @since 2.0.0
  32. */
  33. export declare const size: <K, A>(m: Map<K, A>) => number
  34. /**
  35. * Test whether or not a map is empty
  36. *
  37. * @since 2.0.0
  38. */
  39. export declare const isEmpty: <K, A>(m: Map<K, A>) => boolean
  40. /**
  41. * Test whether or not a key exists in a map
  42. *
  43. * @since 2.0.0
  44. */
  45. export declare const member: <K>(E: Eq<K>) => {
  46. (k: K): <A>(m: Map<K, A>) => boolean
  47. <A>(k: K, m: Map<K, A>): boolean
  48. }
  49. /**
  50. * Test whether or not a value is a member of a map
  51. *
  52. * @since 2.0.0
  53. */
  54. export declare const elem: <A>(E: Eq<A>) => {
  55. (a: A): <K>(m: Map<K, A>) => boolean
  56. <K>(a: A, m: Map<K, A>): boolean
  57. }
  58. /**
  59. * Get a sorted `Array` of the keys contained in a `Map`.
  60. *
  61. * @since 2.0.0
  62. */
  63. export declare const keys: <K>(O: Ord<K>) => <A>(m: Map<K, A>) => K[]
  64. /**
  65. * Get a sorted `Array` of the values contained in a `Map`.
  66. *
  67. * @since 2.0.0
  68. */
  69. export declare const values: <A>(O: Ord<A>) => <K>(m: Map<K, A>) => A[]
  70. /**
  71. * @since 2.0.0
  72. */
  73. export declare function collect<K>(O: Ord<K>): <A, B>(f: (k: K, a: A) => B) => (m: Map<K, A>) => Array<B>
  74. /**
  75. * Get a sorted `Array` of the key/value pairs contained in a `Map`.
  76. *
  77. * @since 2.0.0
  78. */
  79. export declare function toArray<K>(O: Ord<K>): <A>(m: Map<K, A>) => Array<[K, A]>
  80. /**
  81. * Unfolds a map into a list of key/value pairs
  82. *
  83. * @since 2.0.0
  84. */
  85. export declare function toUnfoldable<K, F extends URIS>(
  86. ord: Ord<K>,
  87. U: Unfoldable1<F>
  88. ): <A>(d: Map<K, A>) => Kind<F, [K, A]>
  89. export declare function toUnfoldable<K, F>(ord: Ord<K>, U: Unfoldable<F>): <A>(d: Map<K, A>) => HKT<F, [K, A]>
  90. /**
  91. * Insert or replace a key/value pair in a `Map`.
  92. *
  93. * @since 2.0.0
  94. */
  95. export declare const upsertAt: <K>(E: Eq<K>) => <A>(k: K, a: A) => (m: Map<K, A>) => Map<K, A>
  96. /**
  97. * Delete a key and value from a map
  98. *
  99. * @since 2.0.0
  100. */
  101. export declare const deleteAt: <K>(E: Eq<K>) => (k: K) => <A>(m: Map<K, A>) => Map<K, A>
  102. /**
  103. * @since 2.0.0
  104. */
  105. export declare const updateAt: <K>(E: Eq<K>) => <A>(k: K, a: A) => (m: Map<K, A>) => O.Option<Map<K, A>>
  106. /**
  107. * @since 2.0.0
  108. */
  109. export declare const modifyAt: <K>(E: Eq<K>) => <A>(k: K, f: (a: A) => A) => (m: Map<K, A>) => O.Option<Map<K, A>>
  110. /**
  111. * Delete a key and value from a map, returning the value as well as the subsequent map
  112. *
  113. * @since 2.0.0
  114. */
  115. export declare function pop<K>(E: Eq<K>): (k: K) => <A>(m: Map<K, A>) => Option<[A, Map<K, A>]>
  116. /**
  117. * Lookup the value for a key in a `Map`.
  118. * If the result is a `Some`, the existing key is also returned.
  119. *
  120. * @since 2.0.0
  121. */
  122. export declare function lookupWithKey<K>(E: Eq<K>): {
  123. (k: K): <A>(m: Map<K, A>) => Option<[K, A]>
  124. <A>(k: K, m: Map<K, A>): Option<[K, A]>
  125. }
  126. /**
  127. * Lookup the value for a key in a `Map`.
  128. *
  129. * @since 2.0.0
  130. */
  131. export declare const lookup: <K>(E: Eq<K>) => {
  132. (k: K): <A>(m: Map<K, A>) => Option<A>
  133. <A>(k: K, m: Map<K, A>): Option<A>
  134. }
  135. /**
  136. * Test whether or not one `Map` contains all of the keys and values contained in another `Map`
  137. *
  138. * @since 2.0.0
  139. */
  140. export declare const isSubmap: <K, A>(
  141. SK: Eq<K>,
  142. SA: Eq<A>
  143. ) => {
  144. (that: Map<K, A>): (me: Map<K, A>) => boolean
  145. (me: Map<K, A>, that: Map<K, A>): boolean
  146. }
  147. /**
  148. * @category instances
  149. * @since 2.0.0
  150. */
  151. export declare const getEq: <K, A>(SK: Eq<K>, SA: Eq<A>) => Eq<Map<K, A>>
  152. /**
  153. * Gets `Monoid` instance for Maps given `Semigroup` instance for their values
  154. *
  155. * @category instances
  156. * @since 2.0.0
  157. */
  158. export declare function getMonoid<K, A>(SK: Eq<K>, SA: Semigroup<A>): Monoid<Map<K, A>>
  159. /**
  160. * Create a map with one key/value pair
  161. *
  162. * @since 2.0.0
  163. */
  164. export declare const singleton: <K, A>(k: K, a: A) => Map<K, A>
  165. /**
  166. * Create a map from a foldable collection of key/value pairs, using the
  167. * specified `Magma` to combine values for duplicate keys.
  168. *
  169. * @category constructors
  170. * @since 2.0.0
  171. */
  172. export declare function fromFoldable<F extends URIS3, K, A>(
  173. E: Eq<K>,
  174. M: Magma<A>,
  175. F: Foldable3<F>
  176. ): <R, E>(fka: Kind3<F, R, E, [K, A]>) => Map<K, A>
  177. export declare function fromFoldable<F extends URIS2, K, A>(
  178. E: Eq<K>,
  179. M: Magma<A>,
  180. F: Foldable2<F>
  181. ): <E>(fka: Kind2<F, E, [K, A]>) => Map<K, A>
  182. export declare function fromFoldable<F extends URIS, K, A>(
  183. E: Eq<K>,
  184. M: Magma<A>,
  185. F: Foldable1<F>
  186. ): (fka: Kind<F, [K, A]>) => Map<K, A>
  187. export declare function fromFoldable<F, K, A>(E: Eq<K>, M: Magma<A>, F: Foldable<F>): (fka: HKT<F, [K, A]>) => Map<K, A>
  188. /**
  189. * @since 2.10.0
  190. */
  191. export declare const partitionMapWithIndex: <K, A, B, C>(
  192. f: (k: K, a: A) => Either<B, C>
  193. ) => (fa: Map<K, A>) => Separated<Map<K, B>, Map<K, C>>
  194. /**
  195. * @since 2.10.0
  196. */
  197. export declare function partitionWithIndex<K, A, B extends A>(
  198. predicateWithIndex: (k: K, a: A) => a is B
  199. ): (fa: Map<K, A>) => Separated<Map<K, A>, Map<K, B>>
  200. export declare function partitionWithIndex<K, A>(
  201. predicateWithIndex: (k: K, a: A) => boolean
  202. ): <B extends A>(fb: Map<K, B>) => Separated<Map<K, B>, Map<K, B>>
  203. export declare function partitionWithIndex<K, A>(
  204. predicateWithIndex: (k: K, a: A) => boolean
  205. ): (fa: Map<K, A>) => Separated<Map<K, A>, Map<K, A>>
  206. /**
  207. * @since 2.10.0
  208. */
  209. export declare const filterMapWithIndex: <K, A, B>(f: (k: K, a: A) => O.Option<B>) => (fa: Map<K, A>) => Map<K, B>
  210. /**
  211. * @since 2.10.0
  212. */
  213. export declare function filterWithIndex<K, A, B extends A>(p: (k: K, a: A) => a is B): (m: Map<K, A>) => Map<K, B>
  214. export declare function filterWithIndex<K, A>(p: (k: K, a: A) => boolean): <B extends A>(m: Map<K, B>) => Map<K, B>
  215. export declare function filterWithIndex<K, A>(p: (k: K, a: A) => boolean): (m: Map<K, A>) => Map<K, A>
  216. /**
  217. * @category filtering
  218. * @since 2.0.0
  219. */
  220. export declare const compact: <K, A>(fa: Map<K, O.Option<A>>) => Map<K, A>
  221. /**
  222. * @category filtering
  223. * @since 2.0.0
  224. */
  225. export declare const filter: {
  226. <A, B extends A>(refinement: Refinement<A, B>): <K>(fa: Map<K, A>) => Map<K, B>
  227. <A>(predicate: Predicate<A>): <K, B extends A>(fb: Map<K, B>) => Map<K, B>
  228. <A>(predicate: Predicate<A>): <K>(fa: Map<K, A>) => Map<K, A>
  229. }
  230. /**
  231. * @category filtering
  232. * @since 2.0.0
  233. */
  234. export declare const filterMap: <A, B>(f: (a: A) => Option<B>) => <K>(fa: Map<K, A>) => Map<K, B>
  235. /**
  236. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  237. * use the type constructor `F` to represent some computational context.
  238. *
  239. * @category mapping
  240. * @since 2.0.0
  241. */
  242. export declare const map: <A, B>(f: (a: A) => B) => <K>(fa: Map<K, A>) => Map<K, B>
  243. /**
  244. * @category mapping
  245. * @since 2.7.1
  246. */
  247. export declare const mapWithIndex: <K, A, B>(f: (k: K, a: A) => B) => (fa: Map<K, A>) => Map<K, B>
  248. /**
  249. * @category filtering
  250. * @since 2.0.0
  251. */
  252. export declare const partition: {
  253. <A, B extends A>(refinement: Refinement<A, B>): <K>(fa: Map<K, A>) => Separated<Map<K, A>, Map<K, B>>
  254. <A>(predicate: Predicate<A>): <K, B extends A>(fb: Map<K, B>) => Separated<Map<K, B>, Map<K, B>>
  255. <A>(predicate: Predicate<A>): <K>(fa: Map<K, A>) => Separated<Map<K, A>, Map<K, A>>
  256. }
  257. /**
  258. * @category filtering
  259. * @since 2.0.0
  260. */
  261. export declare const partitionMap: <A, B, C>(
  262. f: (a: A) => Either<B, C>
  263. ) => <K>(fa: Map<K, A>) => Separated<Map<K, B>, Map<K, C>>
  264. /**
  265. * @category filtering
  266. * @since 2.0.0
  267. */
  268. export declare const separate: <K, A, B>(fa: Map<K, Either<A, B>>) => Separated<Map<K, A>, Map<K, B>>
  269. /**
  270. * @category type lambdas
  271. * @since 2.0.0
  272. */
  273. export declare const URI = 'Map'
  274. /**
  275. * @category type lambdas
  276. * @since 2.0.0
  277. */
  278. export declare type URI = typeof URI
  279. declare module './HKT' {
  280. interface URItoKind2<E, A> {
  281. readonly [URI]: Map<E, A>
  282. }
  283. }
  284. /**
  285. * @category instances
  286. * @since 2.11.0
  287. */
  288. export declare const getUnionSemigroup: <K, A>(E: Eq<K>, S: Semigroup<A>) => Semigroup<Map<K, A>>
  289. /**
  290. * @category instances
  291. * @since 2.11.0
  292. */
  293. export declare const getUnionMonoid: <K, A>(E: Eq<K>, S: Semigroup<A>) => Monoid<Map<K, A>>
  294. /**
  295. * @category instances
  296. * @since 2.11.0
  297. */
  298. export declare const getIntersectionSemigroup: <K, A>(E: Eq<K>, S: Semigroup<A>) => Semigroup<Map<K, A>>
  299. /**
  300. * @category instances
  301. * @since 2.11.0
  302. */
  303. export declare const getDifferenceMagma: <K>(E: Eq<K>) => <A>() => Magma<Map<K, A>>
  304. /**
  305. * @category filtering
  306. * @since 2.0.0
  307. */
  308. export declare function getFilterableWithIndex<K = never>(): FilterableWithIndex2C<URI, K, K>
  309. /**
  310. * @category filtering
  311. * @since 2.0.0
  312. */
  313. export declare function getWitherable<K>(O: Ord<K>): Witherable2C<URI, K> & TraversableWithIndex2C<URI, K, K>
  314. /**
  315. * @category folding
  316. * @since 2.11.0
  317. */
  318. export declare const reduce: <K>(O: Ord<K>) => <B, A>(b: B, f: (b: B, a: A) => B) => (m: Map<K, A>) => B
  319. /**
  320. * @category folding
  321. * @since 2.11.0
  322. */
  323. export declare const foldMap: <K>(O: Ord<K>) => <M>(M: Monoid<M>) => <A>(f: (a: A) => M) => (m: Map<K, A>) => M
  324. /**
  325. * @category folding
  326. * @since 2.11.0
  327. */
  328. export declare const reduceRight: <K>(O: Ord<K>) => <B, A>(b: B, f: (a: A, b: B) => B) => (m: Map<K, A>) => B
  329. /**
  330. * @category folding
  331. * @since 2.11.0
  332. */
  333. export declare const getFoldable: <K>(O: Ord<K>) => Foldable2C<'Map', K>
  334. /**
  335. * @category folding
  336. * @since 2.11.0
  337. */
  338. export declare const reduceWithIndex: <K>(O: Ord<K>) => <B, A>(b: B, f: (k: K, b: B, a: A) => B) => (m: Map<K, A>) => B
  339. /**
  340. * @category folding
  341. * @since 2.11.0
  342. */
  343. export declare const foldMapWithIndex: <K>(
  344. O: Ord<K>
  345. ) => <M>(M: Monoid<M>) => <A>(f: (k: K, a: A) => M) => (m: Map<K, A>) => M
  346. /**
  347. * @category folding
  348. * @since 2.11.0
  349. */
  350. export declare const reduceRightWithIndex: <K>(
  351. O: Ord<K>
  352. ) => <B, A>(b: B, f: (k: K, a: A, b: B) => B) => (m: Map<K, A>) => B
  353. /**
  354. * @category folding
  355. * @since 2.10.0
  356. */
  357. export declare const getFoldableWithIndex: <K>(O: Ord<K>) => FoldableWithIndex2C<'Map', K, K>
  358. /**
  359. * @category traversing
  360. * @since 2.10.0
  361. */
  362. export declare const getTraversableWithIndex: <K>(O: Ord<K>) => TraversableWithIndex2C<'Map', K, K>
  363. /**
  364. * @category instances
  365. * @since 2.7.0
  366. */
  367. export declare const Functor: Functor2<URI>
  368. /**
  369. * @category mapping
  370. * @since 2.10.0
  371. */
  372. export declare const flap: <A>(a: A) => <E, B>(fab: Map<E, (a: A) => B>) => Map<E, B>
  373. /**
  374. * @category instances
  375. * @since 2.7.0
  376. */
  377. export declare const Compactable: Compactable2<URI>
  378. /**
  379. * @category instances
  380. * @since 2.7.0
  381. */
  382. export declare const Filterable: Filterable2<URI>
  383. /**
  384. * @since 2.11.0
  385. */
  386. export declare const union: <K, A>(E: Eq<K>, M: Magma<A>) => (second: Map<K, A>) => (first: Map<K, A>) => Map<K, A>
  387. /**
  388. * @since 2.11.0
  389. */
  390. export declare const intersection: <K, A>(
  391. E: Eq<K>,
  392. M: Magma<A>
  393. ) => (second: Map<K, A>) => (first: Map<K, A>) => Map<K, A>
  394. /**
  395. * @since 2.11.0
  396. */
  397. export declare const difference: <K>(E: Eq<K>) => <A>(_second: Map<K, A>) => (first: Map<K, A>) => Map<K, A>
  398. /**
  399. * Use a `new Map()` instead.
  400. *
  401. * @category zone of death
  402. * @since 2.0.0
  403. * @deprecated
  404. */
  405. export declare const empty: Map<never, never>
  406. /**
  407. * Use [`upsertAt`](#upsertat) instead.
  408. *
  409. * @category zone of death
  410. * @since 2.0.0
  411. * @deprecated
  412. */
  413. export declare const insertAt: <K>(E: Eq<K>) => <A>(k: K, a: A) => (m: Map<K, A>) => Map<K, A>
  414. /**
  415. * Use [`Filterable`](#filterable) instead.
  416. *
  417. * @category zone of death
  418. * @since 2.0.0
  419. * @deprecated
  420. */
  421. export declare const map_: Filterable2<URI>