### Install @rbxts/remap with npm, pnpm, or yarn Source: https://github.com/littensy/remap/blob/main/README.md This snippet shows the common commands for installing the @rbxts/remap package using different package managers: npm, pnpm, and yarn. ```bash npm install @rbxts/remap pnpm add @rbxts/remap yarn add @rbxts/remap ``` -------------------------------- ### Basic Remap Operations in TypeScript Source: https://github.com/littensy/remap/blob/main/README.md Demonstrates fundamental usage of the Remap module in TypeScript, including assigning properties, deleting entries, and setting values on a ReadonlyMap. ```typescript import Remap from "@rbxts/remap"; let map = new ReadonlyMap(); map = Remap.assign(map, { foo: 1, bar: 2, baz: 3 }, { baz: Remap.None }); map = Remap.delete(map, "foo"); map = Remap.set(map, "baz", 3); ``` -------------------------------- ### Pick Keys for a Subset ReadonlyMap with TypeScript Source: https://github.com/littensy/remap/blob/main/README.md Demonstrates creating a new ReadonlyMap containing only the specified keys using the `Remap.pick` function. This is useful for selecting specific data from a map. ```typescript function pick(object: ReadonlyMap, ...keys: K[]): ReadonlyMap; Remap.pick(map, "foo", "bar"); // { foo: 1, bar: 2 } ``` -------------------------------- ### Remap API Documentation Source: https://github.com/littensy/remap/blob/main/README.md This section covers the core functions provided by the Remap module for manipulating ReadonlyMap objects. ```APIDOC ## set(object, key, value) ### Description Sets the value at `key` to `value` in a ReadonlyMap. ### Method N/A (Function within a module) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```ts import Remap from "@rbxts/remap"; let map = new ReadonlyMap(); Remap.set(map, "foo", 1); ``` ### Response #### Success Response (200) `ReadonlyMap`: A new ReadonlyMap with the updated entry. #### Response Example ```json { "foo": 1 } ``` --- ## delete(object, key) ### Description Deletes the entry with the given `key` from the map. ### Method N/A (Function within a module) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```ts import Remap from "@rbxts/remap"; let map = new ReadonlyMap(["foo", 1]); Remap.delete(map, "foo"); // deletes the entry at "foo" ``` ### Response #### Success Response (200) `ReadonlyMap`: A new ReadonlyMap with the specified entry removed. #### Response Example ```json {} ``` --- ## deleteValue(object, value) ### Description Deletes the entry with the given `value` from the map. ### Method N/A (Function within a module) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```ts import Remap from "@rbxts/remap"; let map = new ReadonlyMap(["foo", 1]); Remap.deleteValue(map, 1); // deletes the entry with the value 1 ``` ### Response #### Success Response (200) `ReadonlyMap`: A new ReadonlyMap with the specified value removed. #### Response Example ```json {} ``` --- ## update(object, key, updater) ### Description Updates the value at `key` with the result of `updater`. Returning `undefined` from `updater` will delete the entry. ### Method N/A (Function within a module) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```ts import Remap from "@rbxts/remap"; let map = new ReadonlyMap(["foo", 1]); Remap.update(map, "foo", (value = 0) => value + 1); // adds 1 to the value at "foo" ``` ### Response #### Success Response (200) `ReadonlyMap`: A new ReadonlyMap with the updated entry. #### Response Example ```json { "foo": 2 } ``` --- ## map(object, updater) ### Description Updates each entry in the map with the result of `updater`. Returning `undefined` from `updater` will delete the entry. ### Method N/A (Function within a module) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```ts import Remap from "@rbxts/remap"; let map = new ReadonlyMap(["foo", 1]); Remap.map(map, (value, key) => value + 1); // adds 1 to each value ``` ### Response #### Success Response (200) `ReadonlyMap`: A new ReadonlyMap with transformed entries. #### Response Example ```json { "foo": 2 } ``` --- ## filter(object, predicate) ### Description Deletes all entries from the map for which `predicate` returns `false`. ### Method N/A (Function within a module) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```ts import Remap from "@rbxts/remap"; let map = new ReadonlyMap(["foo", 1], ["bar", 2]); Remap.filter(map, (value, key) => value > 1); // removes values less than or equal to 1 ``` ### Response #### Success Response (200) `ReadonlyMap`: A new ReadonlyMap containing only the entries that satisfy the predicate. #### Response Example ```json { "bar": 2 } ``` --- ## reduce(object, reducer, initialValue) ### Description Reduces the map to a single value using `reducer`. The result of each call to `reducer` is passed as the first argument to the next call. ### Method N/A (Function within a module) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```ts import Remap from "@rbxts/remap"; let map = new ReadonlyMap(["foo", 1], ["bar", 2]); Remap.reduce(map, (accumulator, value, key) => accumulator + value, 0); // sum of values ``` ### Response #### Success Response (200) `R`: The final reduced value. #### Response Example ```json 3 ``` --- ## assign(object, ...sources) ### Description Returns a new map with the keys and values from `sources` merged into `map`. Use the `Remap.None` symbol to mark a value for deletion. If the key is a string, number, or symbol, you may pass objects to `...sources` instead of maps. ### Method N/A (Function within a module) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```ts import Remap from "@rbxts/remap"; let map = new ReadonlyMap(["foo", 1]); Remap.assign(map, { bar: 2, baz: 3 }, { baz: Remap.None }); // { foo: 1, bar: 2 } ``` ### Response #### Success Response (200) `ReadonlyMap`: A new ReadonlyMap with merged entries. #### Response Example ```json { "foo": 1, "bar": 2 } ``` --- ## clone(object) ### Description Returns a mutable shallow copy of the map. ### Method N/A (Function within a module) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```ts import Remap from "@rbxts/remap"; let map = new ReadonlyMap(["foo", 1]); Remap.clone(map).set("bar", 2); ``` ### Response #### Success Response (200) `Map`: A mutable shallow copy of the input map. #### Response Example ```json { "foo": 1 } ``` --- ## clear(object) ### Description Returns an empty writable map of the same type as `object`. ### Method N/A (Function within a module) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```ts import Remap from "@rbxts/remap"; let map = new ReadonlyMap(["foo", 1]); Remap.clear(map).set("bar", 2); ``` ### Response #### Success Response (200) `Map`: An empty writable map. #### Response Example ```json {} ``` --- ## omit(object, ...keys) ### Description Returns a subset of the map excluding the keys specified. ### Method N/A (Function within a module) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```ts import Remap from "@rbxts/remap"; let map = new ReadonlyMap(["foo", 1], ["bar", 2], ["baz", 3]); Remap.omit(map, "foo", "bar"); // { baz: 3 } ``` ### Response #### Success Response (200) `ReadonlyMap`: A new ReadonlyMap excluding the specified keys. #### Response Example ```json { "baz": 3 } ``` --- ## pick(object, ...keys) ### Description Returns a subset of the object with only the keys specified. ### Method N/A (Function within a module) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```ts import Remap from "@rbxts/remap"; let map = new ReadonlyMap(["foo", 1], ["bar", 2], ["baz", 3]); Remap.pick(map, "foo", "bar"); // { foo: 1, bar: 2 } ``` ### Response #### Success Response (200) `ReadonlyMap`: A new ReadonlyMap containing only the specified keys. #### Response Example ```json { "foo": 1, "bar": 2 } ``` --- ``` -------------------------------- ### Delete Entry by Value Source: https://context7.com/littensy/remap/llms.txt Finds and removes the first entry with a matching value from the map. ```APIDOC ## DELETE /api/remap/delete/value ### Description Finds and removes the first entry with a matching value from the map. ### Method DELETE ### Endpoint /api/remap/delete/value ### Parameters #### Path Parameters None #### Query Parameters - **map** (ReadonlyMap) - Required - The map to modify. - **value** (V) - Required - The value to find and delete the first entry for. #### Request Body None ### Request Example (No request body for this operation, map and value are passed as query parameters) ### Response #### Success Response (200) - **map** (ReadonlyMap) - The modified or original map. #### Response Example ```json { "map": {"player2": 200, "player3": 100} } ``` ``` -------------------------------- ### Merge Maps with Remap.assign Source: https://context7.com/littensy/remap/llms.txt Combines multiple source maps into a single map. Entries from later sources will override entries with the same key from earlier sources. `Remap.None` can be used as a value to delete keys during the merge process. ```typescript import Remap from "@rbxts/remap"; let baseStats = new ReadonlyMap([ ["strength", 10], ["agility", 8], ["intelligence", 12], ]); // Merge with bonus stats let buffed = Remap.assign( baseStats, { strength: 15, defense: 5 }, { agility: 10 } ); // Result: ReadonlyMap { // "strength" => 15, "agility" => 10, // "intelligence" => 12, "defense" => 5 // } // Use None to delete entries let modified = Remap.assign( buffed, { strength: 20 }, { defense: Remap.None } ); // Result: ReadonlyMap { // "strength" => 20, "agility" => 10, "intelligence" => 12 // } // Works with multiple sources let final = Remap.assign(baseStats, { strength: 12 }, { agility: 9 }, { intelligence: 15 }); ``` -------------------------------- ### Set Value Source: https://context7.com/littensy/remap/llms.txt Sets a value at a specific key in the map. Returns the original map if the value is already equal to avoid unnecessary allocations. ```APIDOC ## SET /api/remap/set ### Description Sets a value at a specific key in the map. Returns the original map if the value is already equal to avoid unnecessary allocations. ### Method POST ### Endpoint /api/remap/set ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **map** (ReadonlyMap) - Required - The original map to modify. - **key** (K) - Required - The key to set the value for. - **value** (V) - Required - The value to set. ### Request Example ```json { "map": {"sword": 1}, "key": "sword", "value": 1 } ``` ### Response #### Success Response (200) - **map** (ReadonlyMap) - The modified or original map. #### Response Example ```json { "map": {"sword": 1} } ``` ``` -------------------------------- ### Clone ReadonlyMap to a Mutable Map with TypeScript Source: https://github.com/littensy/remap/blob/main/README.md Demonstrates creating a mutable shallow copy of a ReadonlyMap using `Remap.clone`. The returned `Map` object can be modified. ```typescript function clone(object: ReadonlyMap): Map; Remap.clone(map).set("foo", 1); ``` -------------------------------- ### Assign and Merge into ReadonlyMap with TypeScript Source: https://github.com/littensy/remap/blob/main/README.md Shows how to merge multiple source maps into a target ReadonlyMap using `Remap.assign`. The `Remap.None` symbol can be used to mark values for deletion. ```typescript function assign(map: ReadonlyMap, ...sources: ReadonlyMap[]): ReadonlyMap; Remap.assign(map, { foo: 1, bar: 2, baz: 3 }, { baz: Remap.None }); // { foo: 1, bar: 2 } ``` -------------------------------- ### Create Empty Mutable Map with Remap.clear Source: https://context7.com/littensy/remap/llms.txt Returns a new, empty mutable map that has the same type signature as the input map. This function is useful for resetting state or initializing a new map from scratch, providing a typed empty map based on a template. ```typescript import Remap from "@rbxts/remap"; const template = new ReadonlyMap([ ["a", 1], ["b", 2], ]); // Get empty map of same type const empty = Remap.clear(template); // Result: Map {} // Useful for resetting state let gameState = new ReadonlyMap([ ["paused", true], ["gameOver", false], ]); // Reset to empty state gameState = Remap.clear(gameState); // Can be used to build new state from scratch const fresh = Remap.clear(gameState); fresh.set("initialized", true); ``` -------------------------------- ### Create Mutable Map Copy with Remap.clone Source: https://context7.com/littensy/remap/llms.txt Returns a shallow mutable copy of a map. Modifications made to the cloned map do not affect the original map. This is useful for performing temporary modifications or preparing data before freezing it back into a `ReadonlyMap`. ```typescript import Remap from "@rbxts/remap"; const original = new ReadonlyMap([ ["health", 100], ["mana", 50], ]); // Create mutable copy for temporary modifications const mutable = Remap.clone(original); mutable.set("health", 90); mutable.set("stamina", 75); // Original is unchanged // original: ReadonlyMap { "health" => 100, "mana" => 50 } // mutable: Map { "health" => 90, "mana" => 50, "stamina" => 75 } // Useful for batch operations before freezing const updated = Remap.clone(original); updated.set("health", 120); updated.set("mana", 60); const frozen: ReadonlyMap = updated; ``` -------------------------------- ### Delete Entry by Key Source: https://context7.com/littensy/remap/llms.txt Removes an entry from the map by its key. Returns the original map if the key doesn't exist. ```APIDOC ## DELETE /api/remap/delete/key ### Description Removes an entry from the map by its key. Returns the original map if the key doesn't exist. ### Method DELETE ### Endpoint /api/remap/delete/key ### Parameters #### Path Parameters - **key** (K) - Required - The key of the entry to delete. #### Query Parameters - **map** (ReadonlyMap) - Required - The map to modify. #### Request Body None ### Request Example (No request body for this operation, map is passed as a query parameter) ### Response #### Success Response (200) - **map** (ReadonlyMap) - The modified or original map. #### Response Example ```json { "map": {"sword": 1, "shield": 2} } ``` ``` -------------------------------- ### Pick Keys to Create New Map in TypeScript Source: https://context7.com/littensy/remap/llms.txt Creates a new ReadonlyMap containing only the specified keys from an existing map. This is useful for selecting specific data points for display or further analysis. It accepts the original map and a list of keys to include. ```typescript import Remap from "@rbxts/remap"; let playerData = new ReadonlyMap([ ["id", 12345], ["username", "player1"], ["email", "player1@example.com"], ["score", 1000], ["level", 45], ["createdAt", "2024-01-01"], ]); // Extract only display data const displayInfo = Remap.pick(playerData, "username", "score", "level"); // Result: ReadonlyMap { // "username" => "player1", // "score" => 1000, // "level" => 45 // } // Pick specific stats for comparison let stats = new ReadonlyMap([ ["health", 100], ["mana", 50], ["stamina", 75], ["defense", 20], ]); const combatStats = Remap.pick(stats, "health", "defense"); // Result: ReadonlyMap { "health" => 100, "defense" => 20 } ``` -------------------------------- ### Use Remap.None for Deletions in TypeScript Source: https://context7.com/littensy/remap/llms.txt Utilizes the special `Remap.None` marker within the `assign()` function to designate keys for deletion during map merge operations. This allows for conditional updates and bulk deletions in a single, immutable operation. ```typescript import Remap from "@rbxts/remap"; let config = new ReadonlyMap([ ["theme", "dark"], ["notifications", true], ["autoSave", true], ["beta", true], ]); // Remove beta flag while updating other settings config = Remap.assign( config, { theme: "light", beta: Remap.None, // Mark for deletion } ); // Result: ReadonlyMap { // "theme" => "light", // "notifications" => true, // "autoSave" => true // } // Useful for conditional deletion const shouldRemoveAutoSave = true; config = Remap.assign(config, { notifications: false, autoSave: shouldRemoveAutoSave ? Remap.None : config.get("autoSave"), }); // Multiple deletions in one assign config = Remap.assign(config, { notifications: Remap.None, theme: Remap.None, }); // Result: ReadonlyMap {} (empty) ``` -------------------------------- ### Update Value with Function Source: https://context7.com/littensy/remap/llms.txt Updates the value at a key using an updater function. Returning `undefined` deletes the entry. Returns original map if value unchanged. ```APIDOC ## PUT /api/remap/update ### Description Updates the value at a key using an updater function. Returning `undefined` deletes the entry. Returns original map if value unchanged. ### Method PUT ### Endpoint /api/remap/update ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **map** (ReadonlyMap) - Required - The original map to modify. - **key** (K) - Required - The key of the value to update. - **updater** (function(V | undefined): V | undefined) - Required - The function to update the value. It receives the current value (or undefined if the key doesn't exist) and should return the new value or undefined to delete the entry. ### Request Example ```json { "map": {"gold": 100}, "key": "gold", "updater": "(value = 0) => value + 25" } ``` ### Response #### Success Response (200) - **map** (ReadonlyMap) - The modified or original map. #### Response Example ```json { "map": {"gold": 125} } ``` ``` -------------------------------- ### Reduce Map to a Single Value with Remap.reduce Source: https://context7.com/littensy/remap/llms.txt Aggregates all entries in a map into a single value using a provided reducer function. The accumulator is passed through each iteration, allowing for complex aggregations such as sums, maximums, or building new data structures. ```typescript import Remap from "@rbxts/remap"; let scores = new ReadonlyMap([ ["level1", 100], ["level2", 250], ["level3", 180], ]); // Sum all values const total = Remap.reduce(scores, (acc, value, key) => acc + value, 0); // Result: 530 // Find maximum value const max = Remap.reduce( scores, (acc, value, key) => (value > acc ? value : acc), 0 ); // Result: 250 // Build array of entries const entries = Remap.reduce( scores, (acc, value, key) => { acc.push(`${key}: ${value}`); return acc; }, [] as string[] ); // Result: ["level1: 100", "level2: 250", "level3: 180"] ``` -------------------------------- ### Map Values in ReadonlyMap with TypeScript Source: https://github.com/littensy/remap/blob/main/README.md Shows how to transform each value in a ReadonlyMap using the `Remap.map` function and an updater function. Returning `undefined` from the updater will delete the entry. ```typescript function map(object: ReadonlyMap, updater: (value: V, key: K) => R | undefined): ReadonlyMap; Remap.map(map, (value, key) => value + 1); // adds 1 to each value ``` -------------------------------- ### Change Existing Value Only Source: https://context7.com/littensy/remap/llms.txt Updates a value only if the key exists. Does not create new entries. Returns original map if key doesn't exist or value unchanged. ```APIDOC ## PUT /api/remap/change ### Description Updates a value only if the key exists. Does not create new entries. Returns original map if key doesn't exist or value unchanged. ### Method PUT ### Endpoint /api/remap/change ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **map** (ReadonlyMap) - Required - The original map to modify. - **key** (K) - Required - The key of the value to change. - **updater** (function(V): V) - Required - The function to update the value. It receives the current value and should return the new value. ### Request Example ```json { "map": {"health": 100}, "key": "health", "updater": "(value) => value - 10" } ``` ### Response #### Success Response (200) - **map** (ReadonlyMap) - The modified or original map. #### Response Example ```json { "map": {"health": 90} } ``` ``` -------------------------------- ### Reduce ReadonlyMap to a Single Value with TypeScript Source: https://github.com/littensy/remap/blob/main/README.md Illustrates how to reduce a ReadonlyMap to a single accumulated value using the `Remap.reduce` function and a reducer function. ```typescript function reduce( object: ReadonlyMap, reducer: (accumulator: R, value: V, key: K) => R, initialValue: R, ): R; Remap.reduce(map, (accumulator, value, key) => accumulator + value, 0); // sum of values ``` -------------------------------- ### Omit Keys from ReadonlyMap with TypeScript Source: https://github.com/littensy/remap/blob/main/README.md Shows how to create a new ReadonlyMap that excludes specified keys using the `Remap.omit` function. This is useful for creating subsets of a map. ```typescript function omit(object: ReadonlyMap, ...keys: K[]): ReadonlyMap; Remap.omit(map, "foo", "bar"); // { baz: 3 } ``` -------------------------------- ### Filter Entries in ReadonlyMap with TypeScript Source: https://github.com/littensy/remap/blob/main/README.md Demonstrates how to filter entries from a ReadonlyMap based on a predicate function using `Remap.filter`. Entries for which the predicate returns `false` are removed. ```typescript function filter(object: ReadonlyMap, predicate: (value: V, key: K) => boolean): ReadonlyMap; Remap.filter(map, (value, key) => value > 1); // removes values less than 1 ``` -------------------------------- ### Clear ReadonlyMap to an Empty Mutable Map with TypeScript Source: https://github.com/littensy/remap/blob/main/README.md Illustrates how to create an empty writable map of the same type as the input ReadonlyMap using `Remap.clear`. This is useful for resetting map contents. ```typescript function clear(object: ReadonlyMap): Map; Remap.clear(map).set("foo", 1); ``` -------------------------------- ### Map Entries with Remap.map Source: https://context7.com/littensy/remap/llms.txt Transforms each value in a map using a provided mapping function. Returning `undefined` from the mapping function will delete that specific entry from the resulting map. This function is useful for modifying values, changing value types, or conditionally removing entries. ```typescript import Remap from "@rbxts/remap"; let prices = new ReadonlyMap([ ["apple", 10], ["banana", 5], ["cherry", 15], ]); // Apply discount to all items let discounted = Remap.map(prices, (value, key) => value * 0.8); // Result: ReadonlyMap { "apple" => 8, "banana" => 4, "cherry" => 12 } // Transform values conditionally, remove items under threshold let filtered = Remap.map(discounted, (value, key) => { return value >= 8 ? value : undefined; }); // Result: ReadonlyMap { "apple" => 8, "cherry" => 12 } // Change value types let labels = Remap.map(prices, (value, key) => `${key}: $${value}`); // Result: ReadonlyMap { "apple" => "apple: $10", ... } ``` -------------------------------- ### Delete Entry by Key from ReadonlyMap using TypeScript Source: https://context7.com/littensy/remap/llms.txt Removes an entry from a ReadonlyMap using its key. If the key does not exist in the map, the original map is returned, ensuring immutability. This operation is provided by the Remap library. ```typescript import Remap from "@rbxts/remap"; let inventory = new ReadonlyMap([ ["sword", 1], ["shield", 2], ["potion", 5], ]); // Delete a specific item inventory = Remap.delete(inventory, "potion"); // Result: ReadonlyMap { "sword" => 1, "shield" => 2 } // Deleting non-existent key returns original const sameMap = Remap.delete(inventory, "helmet"); // sameMap === inventory (true) // Also available as deleteKey inventory = Remap.deleteKey(inventory, "shield"); // Result: ReadonlyMap { "sword" => 1 } ``` -------------------------------- ### Set Value in ReadonlyMap with TypeScript Source: https://github.com/littensy/remap/blob/main/README.md Illustrates how to set a key-value pair in a ReadonlyMap using the `Remap.set` function in TypeScript. It returns a new map with the updated value. ```typescript function set(object: ReadonlyMap, key: K, value: V): ReadonlyMap; Remap.set(map, "foo", 1); // { foo: 1 } ``` -------------------------------- ### Update Value in ReadonlyMap with Function using TypeScript Source: https://context7.com/littensy/remap/llms.txt Updates the value associated with a key in a ReadonlyMap using a provided updater function. If the updater function returns `undefined`, the entry is deleted. The original map is returned if the value remains unchanged. This is a core function of the Remap library. ```typescript import Remap from "@rbxts/remap"; let inventory = new ReadonlyMap([ ["gold", 100], ["gems", 50], ]); // Increment a value inventory = Remap.update(inventory, "gold", (value = 0) => value + 25); // Result: ReadonlyMap { "gold" => 125, "gems" => 50 } // Create new entry with default value inventory = Remap.update(inventory, "silver", (value = 0) => value + 10); // Result: ReadonlyMap { "gold" => 125, "gems" => 50, "silver" => 10 } // Delete by returning undefined inventory = Remap.update(inventory, "gems", (value) => { return value && value < 100 ? undefined : value; }); // Result: ReadonlyMap { "gold" => 125, "silver" => 10 } ``` -------------------------------- ### Delete Entry by Value in ReadonlyMap with TypeScript Source: https://github.com/littensy/remap/blob/main/README.md Demonstrates deleting an entry from a ReadonlyMap based on its value using `Remap.deleteValue`. This returns a new map with the entry removed. ```typescript function deleteValue(object: ReadonlyMap, value: V): ReadonlyMap; Remap.deleteValue(map, 1); // deletes the entry with the value 1 ``` -------------------------------- ### Delete Entry from ReadonlyMap with TypeScript Source: https://github.com/littensy/remap/blob/main/README.md Shows how to remove an entry from a ReadonlyMap by its key using the `Remap.delete` function in TypeScript. This operation returns a new map without the specified key. ```typescript function delete(object: ReadonlyMap, key: K): ReadonlyMap; Remap.delete(map, "foo"); // deletes the entry at "foo" ``` -------------------------------- ### Change Existing Value in ReadonlyMap using TypeScript Source: https://context7.com/littensy/remap/llms.txt Updates a value in a ReadonlyMap only if the key already exists. This function, part of the Remap library, does not create new entries. It returns the original map if the key is not found or if the value remains unchanged after the update. ```typescript import Remap from "@rbxts/remap"; let stats = new ReadonlyMap([ ["health", 100], ["mana", 50], ]); // Update existing value stats = Remap.change(stats, "health", (value) => value - 10); // Result: ReadonlyMap { "health" => 90, "mana" => 50 } // Non-existent key returns original map const sameMap = Remap.change(stats, "stamina", (value) => value + 10); // sameMap === stats (true) // Use update() instead if you want to create new entries stats = Remap.update(stats, "stamina", (value = 0) => value + 100); // Result: ReadonlyMap { "health" => 90, "mana" => 50, "stamina" => 100 } ``` -------------------------------- ### Set Value in ReadonlyMap using TypeScript Source: https://context7.com/littensy/remap/llms.txt Sets a value at a specific key in a ReadonlyMap. If the value is already the same, it returns the original map to avoid unnecessary memory allocations. This function is part of the Remap library for immutable map operations. ```typescript import Remap from "@rbxts/remap"; let inventory = new ReadonlyMap(); // Set a single item inventory = Remap.set(inventory, "sword", 1); inventory = Remap.set(inventory, "shield", 2); inventory = Remap.set(inventory, "potion", 5); // Setting the same value returns the original map const sameMap = Remap.set(inventory, "sword", 1); // sameMap === inventory (true) // Result: ReadonlyMap { "sword" => 1, "shield" => 2, "potion" => 5 } ``` -------------------------------- ### Filter Map Entries with Remap.filter Source: https://context7.com/littensy/remap/llms.txt Removes entries from a map that do not satisfy a given predicate function. Only entries for which the predicate returns `true` are kept in the resulting map. This is useful for selecting subsets of data based on key or value conditions. ```typescript import Remap from "@rbxts/remap"; let inventory = new ReadonlyMap([ ["common_item", 50], ["rare_item", 5], ["legendary_item", 1], ["junk", 100], ]); // Keep only valuable items (quantity < 10) inventory = Remap.filter(inventory, (value, key) => value < 10); // Result: ReadonlyMap { "rare_item" => 5, "legendary_item" => 1 } // Filter by key pattern let items = new ReadonlyMap([ ["weapon_sword", 1], ["weapon_bow", 1], ["armor_helmet", 1], ]); let weapons = Remap.filter(items, (value, key) => key.indexOf("weapon_") === 0); // Result: ReadonlyMap { "weapon_sword" => 1, "weapon_bow" => 1 } ``` -------------------------------- ### Delete Entry by Value from ReadonlyMap using TypeScript Source: https://context7.com/littensy/remap/llms.txt Finds and removes the first entry in a ReadonlyMap that matches a specific value. If the value is not found, the original map is returned. This function is part of the Remap library for immutable data structures. ```typescript import Remap from "@rbxts/remap"; let scores = new ReadonlyMap([ ["player1", 100], ["player2", 200], ["player3", 100], ]); // Delete first entry with value 100 scores = Remap.deleteValue(scores, 100); // Result: ReadonlyMap { "player2" => 200, "player3" => 100 } // Only the first matching value is removed scores = Remap.deleteValue(scores, 100); // Result: ReadonlyMap { "player2" => 200 } // Returns original if value not found const sameMap = Remap.deleteValue(scores, 999); // sameMap === scores (true) ``` -------------------------------- ### Update Value in ReadonlyMap with TypeScript Source: https://github.com/littensy/remap/blob/main/README.md Explains how to update an existing value in a ReadonlyMap using `Remap.update` and a provided updater function. Returning `undefined` from the updater will delete the entry. ```typescript function update(object: ReadonlyMap, key: K, updater: (value?: V) => V | undefined): ReadonlyMap; Remap.update(map, "foo", (value = 0) => value + 1); // adds 1 to the value at "foo" ``` -------------------------------- ### Omit Keys from Map in TypeScript Source: https://context7.com/littensy/remap/llms.txt Creates a new ReadonlyMap excluding specified keys. This function is useful for removing sensitive or irrelevant data before further processing or display. It takes the original map and a list of keys to omit as arguments. ```typescript import Remap from "@rbxts/remap"; let userData = new ReadonlyMap([ ["username", "player1"], ["email", "player1@example.com"], ["password", "secret123"], ["score", 1000], ]); // Remove sensitive data const publicData = Remap.omit(userData, "password", "email"); // Result: ReadonlyMap { // "username" => "player1", // "score" => 1000 // } // Omit multiple keys at once let inventory = new ReadonlyMap([ ["sword", 1], ["shield", 1], ["potion", 5], ["junk1", 10], ["junk2", 20], ]); const cleaned = Remap.omit(inventory, "junk1", "junk2"); // Result: ReadonlyMap { "sword" => 1, "shield" => 1, "potion" => 5 } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.