-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
UserID.hh
33 lines (29 loc) · 979 Bytes
/
UserID.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?hh // strict
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
require_once $_SERVER['DOCUMENT_ROOT'].'/core/funs/init.php';
// Outside of this file, no one knows that these types are ints. They do know
// that USER_ID is an ID and COW_ID is an ID
newtype ID = int;
newtype USER_ID as ID = ID;
newtype COW_ID as ID = ID;
function assert_user_id(int $x): USER_ID {
// Everyone knows all user ids are odd
invariant($x % 2, sprintf('Invalid user ID: %d', $x));
return $x;
}
function assert_cow_id(int $x): COW_ID {
// Everyone knows all cow ids are even
invariant($x % 2 === 0, sprintf('Invalid cow ID: %d', $x));
return $x;
}
function id_to_int(ID $id): int {
return $id;
}