This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export type DeepReadonly<T> = | |
| //Functions are objects, but don't need to be deep readonly | |
| T extends Function ? T : | |
| T extends Map<infer MK, infer MV> ? ReadonlyMap<DeepReadonly<MK>, DeepReadonly<MV>> : | |
| T extends Set<infer E> ? ReadonlySet<DeepReadonly<E>> : | |
| T extends Array<infer E> ? ReadonlyArray<DeepReadonly<E>> : | |
| T extends object ? DeepReadonlyObject<T> : | |
| T; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // -----JS CODE----- | |
| //NOTE: | |
| //To this scipt to work you need to: | |
| // - Put 'Behavior' script on the very top of Objects hierarchy. Use | |
| // + > Helper Scripts > Behavior to add it. You can leave that script | |
| // to work 'On Awake' | |
| // - Put this script on top of the Objects hierarchy, AFTER behavior. Bind | |
| // this script to 'On Start', NOT 'On Awake' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 'probabilities' is an array of pairs [probability, choice] | |
| */ | |
| function chooseWithProbabilities(probabilities) { | |
| const pSum = probabilities.reduce((sum, [p, _]) => sum + p, 0); | |
| if (pSum !== 100.0) { | |
| throw new Error( | |
| 'Sum of the probabilities must be equal to 100. ' | |
| + `Current sum is ${pSum}` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function bind(callable $f, ...$params) | |
| { | |
| return function () use ($f, $params) { | |
| return call_user_func_array($f, $params); | |
| }; | |
| } | |
| function partial(callable $f, ...$params) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function pipeline(callable ...$pipes) { | |
| $pipes_count = count($pipes); | |
| if ($pipes_count === 0) { | |
| return; | |
| } | |
| $last_pipe = $pipes[$pipes_count - 1]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function snake_to_camel_case(string $string): string { | |
| $parts = explode('_', $string); | |
| $parts_count = count($parts); | |
| for ($i = 1; $i < $parts_count; ++$i) { | |
| $parts[$i] = ucfirst($parts[$i]); | |
| } |