Created
August 3, 2024 04:35
-
-
Save BiosBoy/2efa95448af7c2a69691bff44302316f to your computer and use it in GitHub Desktop.
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
| const record = #{ name: "Alice", age: 30 }; | |
| const tuple = #[1, 2, 3]; | |
| console.log(record.name); // Alice | |
| console.log(tuple[0]); // 1 | |
| const data = { type: 'user', info: { name: 'Alice', age: 30 } }; | |
| const result = match (data) { | |
| { type: 'user', info: { name } } => `User: ${name}`, | |
| { type: 'admin', info: { name } } => `Admin: ${name}`, | |
| _ => 'Unknown' | |
| }; | |
| console.log(result); // User: Alice | |
| const now = Temporal.Now.plainDateTimeISO(); | |
| const future = now.add({ days: 5 }); | |
| console.log(now.toString()); // 2024-08-03T14:32:00 | |
| console.log(future.toString()); // 2024-08-08T14:32:00 | |
| const result = [1, 2, 3, 4] | |
| |> map(x => x * 2) | |
| |> filter(x => x > 4) | |
| |> reduce((sum, x) => sum + x, 0); | |
| console.log(result); // 14 | |
| import { AsyncLocalStorage } from 'node:async_hooks'; | |
| const asyncLocalStorage = new AsyncLocalStorage(); | |
| asyncLocalStorage.run(new Map(), () => { | |
| asyncLocalStorage.getStore().set('key', 'value'); | |
| setTimeout(() => { | |
| console.log(asyncLocalStorage.getStore().get('key')); // Preserves context | |
| }, 100); | |
| }); | |
| import { featureA } from './moduleA' if (condition); | |
| import * as featureB from './moduleB'; | |
| if (condition) { | |
| const { featureC } = await import('./moduleC'); | |
| featureC(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment