BVB Source Codes

prettier Show refine.js Source code

Return Download prettier: download refine.js Source code - Download prettier Source code - Type:.js
  1. // @flow
  2.  
  3. /*
  4.   $Pred<N> is an "abstract predicate type", i.e. denotes a (function) type that
  5.   refines N variables. So if `cb` is a function, then it should be refining
  6.   exactly N argument. It is abstract in that we do not need to specify:
  7.   (a) which variables are going to be refined (just the number), or (b) what
  8.   exactly the refinement (predicate) is going to be.
  9.  
  10.   $Refine<T,P,k> is a refinement type, that refines type T with the k-th
  11.   argument that gets refined by an abstract preficate type P.
  12. */
  13. declare function refine<T, P: $Pred<1>>(v: T, cb: P): $Refine<T,P,1>;
  14. // function refine(v, cb)
  15. // { if (cb(v)) { return v; } else { throw new Error(); } }
  16.  
  17. /*
  18.   Use case
  19. */
  20. declare var a: mixed;
  21. var b = refine(a, is_string);
  22. (b: string);
  23.  
  24. declare function refine_fst<T, P: $Pred<2>>(v: T, w: T, cb: P): $Refine<T,P,1>;
  25. // function refine_fst(v, w, cb)
  26. // { if (cb(v, w)) { return v; } else { throw new Error(); } }
  27.  
  28. declare var c: mixed;
  29. declare var d: mixed;
  30.  
  31. var e = refine2(c, d, is_string_and_number);
  32. (e: string);
  33.  
  34.  
  35. declare function refine2<T, P: $Pred<2>>(v: T, w: T, cb: P): $Refine<T,P,1>;
  36.  
  37. // function refine_fst(v, w, cb)
  38. // { if (cb(v, w)) { return w; } else { throw new Error(); } }
  39.  
  40. function is_string(x): boolean %checks {
  41.   return typeof x === "string";
  42. }
  43.  
  44. function is_string_and_number(x, y): %checks {
  45.   return typeof x === "string" && typeof y === "number";
  46. }
  47.  
downloadrefine.js Source code - Download prettier Source code
Related Source Codes/Software:
storybook - 2017-06-07
ionicons - The premium icon font for Ionic ... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
parse-server - Parse-compatible API server module for Node/Expres... 2017-06-07
inferno - An extremely fast, React-like JavaScript library f... 2017-06-08
guetzli - Perceptual JPEG encoder 2017-06-08
cs-video-courses - List of Computer Science courses with video lectur... 2017-06-08
interviews - Everything you need to know to get the job. 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top