{"id":"cizzles/set","name":"set","scope":"cizzles","platform":"roblox","description":"A Luau function that converts a list into a set.","version":"1.0.0","latest":"1.0.0","versions":["1.0.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"f7d209cd3351e3993e45490991c21f8150d0d090999bd4d2c2c204b3a5252798","likes":0,"downloads":0,"install":"forest install cizzles/set","url":"https://forest.dev/p/roblox/cizzles/set","files":"https://api.forest.dev/ai/package/roblox/cizzles/set/files","readme":"# Set\nSet is a Luau module and Wally package which returns a function that converts a list into a set.\n\n## What is a Set?\nIn computer science, a set is an abstract data type that can store unique values, without any particular order.\n\nWant more information? [Read the Docs!](https://www.lua.org/pil/11.5.html)\n\n### Examples of Sets:\nUsing Roster Notation, a Mathematical Set can be represented as: \n\nA = {4, 2, 1, 3}\n\nAn Empty (Null) Set (or a set that contains no values) can be represented as:\n\nA = {}\n\nA Singleton Set (or a set that only contains one value) can be represented as:\n\nA = {x}\n\n### Why use Sets in Luau?\nUnlike Python, C#, and several other programming languages, in Luau there is no built-in function nor method to check if an item is in a list. Ergo, in Luau, we can just turn our list into a set instead of writing spaghetti code to check if an item is in a list. In Luau, a simple and efficient way to represent a set is to put the set elements as indices in a table. Then, instead of searching a table for a given element, you can just index the table and test whether the result is nil or not. \n\nStill confused? Check [Usage](https://github.com/cizzles/Set#Usage) for an example.\n\n## Install\nInstallation is simple; choose your workflow.\n\n**Roblox Studio Workflow:**\n1. Get [Set](https://www.roblox.com/library/10174561493) from the Roblox Library\n2. Parent Set to ReplicatedStorage\n3. Require the \"Set\" ModuleScript from ReplicatedStorage\n\n\t```lua\n\tlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\n\tlocal Set = require(ReplicatedStorage.Set)\n\t```\n\n**Rojo & Wally Workflow:**\n1. Add [Set](https://wally.run/package/cizzles/set) as a [Wally](https://github.com/UpliftGames/wally#installation) Dependency\n\n\t`Set = \"cizzles/set@x\"`\n\n2. Use [Rojo](https://rojo.space/docs/v7/getting-started/installation/) to point the Wally Packages to ReplicatedStorage\n3. Require the \"Set\" Package (ModuleScript) from ReplicatedStorage\n\n\t```lua\n\tlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\n\tlocal Set = require(ReplicatedStorage.Packages.Set)\n\t```\n\n## Usage\nSet can be used in both client (local) scripts and server (regular) scripts. Personally, I recommend the following syntax when using Set:\n```lua\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\nlocal Set = require(ReplicatedStorage.Set)\n\nlocal Fruits = Set {\"Apple\", \"Banana\", \"Cherry\"}\n\nif Fruits[\"Cherry\"] then\n\tprint(\"Yes\")\nelse\n\tprint(\"No\")\nend\n```\n\nHowever, you can obviously also use parentheses, semicolons, etc. when declaring Set:\n```lua\nlocal Fruits = Set({\"Apple\", \"Banana\", \"Cherry\"});\n```\n\nMoreover, Set supports other data types, not just strings:\n```lua\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\nlocal Set = require(ReplicatedStorage.Set)\n\nlocal Fruits = {\"Apple\", \"Banana\", \"Cherry\"}\nlocal New = Set {true, Fruits, \"Cherry\"}\n\nif New[Fruits] then\n\tprint(\"Yes\")\nelse\n\tprint(\"No\")\nend\n```\n\n## Config\nIn the \"Set\" Module you can configure the syntax for Set to be \"DEFAULT\" or \"NEW\".\n\n**Default Syntax:**\n\nModuleScript:\n```lua\nlocal Syntax = \"DEFAULT\"\n```\nUsage:\n\n[See Above](https://github.com/cizzles/Set#Usage)\n\n**New Syntax:**\n\nModuleScript:\n```lua\nlocal Syntax = \"NEW\"\n```\nUsage:\n```lua\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\nlocal Set = require(ReplicatedStorage.Set)\n\nlocal Fruits = Set.new({\"Apple\", \"Banana\", \"Cherry\"})\n\nif Fruits[\"Cherry\"] then\n\tprint(\"Yes\")\nelse\n\tprint(\"No\")\nend\n```\n\n## Changelog\n**1.0.0**\n- Initial Release\n","readmeTruncated":false}