Created
January 13, 2023 08:22
-
-
Save Msirkovsky/1eebd8adba0389d2f799061f35ed2dab to your computer and use it in GitHub Desktop.
This file contains 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: "S. Holmes", age: 27 } | |
const record2 = Record.fromEntries([["age", 27], #["name", "S. Holmes"]]) // Note that any iterable of entries will work | |
const tuple = Tuple(...[1, 2, 3]) | |
const tuple2 = Tuple.from([1, 2, 3]) // Note that an iterable will work as well | |
record == #{ name: "S. Holmes", age: 27 } => true | |
tuple == #[1, 2, 3]) => true | |
// JS Compiler throws an error when using a non-primitive value | |
Record({ a: {} }) // TypeError: Can't convert Object with a non-const value to record | |
Tuple.from([{}, {} , {}]) // TypeError: Can't convert Iterable with a non-const value to tuple | |
// Convert back to object/array is simple: | |
const obj = { ...record } | |
const arr = [ ...tuple ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment