You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>You can combine two contracts with the <code>or</code> combinator. If the first contract fails, the combined contract will succeed if the second passes.</p>
414
+
<p>You can combine two or more contracts with the <code>or</code> combinator. If the first contract fails, the combined contract will succeed if the second passes.</p>
414
415
<preclass="js"><code>@ (Num or Str) -> Str
415
416
function foo(x) { return x.toString(); }
416
417
417
418
foo(24); // passes
418
419
foo("24"); // passes
419
420
foo(false); // error not a Num or Str</code></pre>
420
421
<p>Note that <code>or</code> only makes sense for at most one higher-order contract. For example, <code>Num or (Num) -> Num</code> is fine but <code>(Num) -> Num or (Str) -> Str</code> will not work.</p>
<p>When you have a complicated contract that is repeated in several places it can be convenient to refer to it by a shorter name. For this, you can use <code>let</code> after the <code>@</code> symbol:</p>
423
432
<preclass="js"><code>@ let NumId = (Num) -> Num
0 commit comments