Guest User

Untitled

a guest
Jun 23rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import * as I from 'immutable'
  2. import { l, t, validater } from './t'
  3.  
  4. function IOMap<K extends t.Any, V extends t.Any>(keyType: K, valueType: V) {
  5.  
  6. type Key = t.TypeOf<K>
  7. type Value = t.TypeOf<V>
  8. type M = I.Map<Key, Value>
  9.  
  10. const Entries = t.array(t.tuple([ keyType, valueType ]))
  11. type Entries = t.TypeOf<typeof Entries>
  12.  
  13. type Type = t.Type<M> & {
  14. of: (value: Entries) => M
  15. }
  16.  
  17. const Type: Type = {
  18. _A: t._A,
  19. name: `Map<${keyType.name}, ${valueType.name}>'`,
  20. validate: (value: object, context) =>
  21. Entries.validate(Object.entries(value), context)
  22. .chain(entries => t.success(I.Map<Key, Value>(entries))),
  23. of: (entries: Entries): M => I.Map<Key, Value>(entries)
  24. }
  25.  
  26. return Type //{ Map, Type }
  27.  
  28. }
  29. namespace IOMap {
  30. export const of = I.Map.of
  31. export const isMap = I.Map.of
  32. }
  33.  
  34. export default IOMap
Add Comment
Please, Sign In to add comment