{"id":19469555,"url":"https://github.com/hackerkid/learn-elixir","last_synced_at":"2026-03-19T10:03:06.194Z","repository":{"id":71211547,"uuid":"403352909","full_name":"hackerkid/learn-elixir","owner":"hackerkid","description":"My notes on learning Elixir","archived":false,"fork":false,"pushed_at":"2021-09-05T16:16:37.000Z","size":3,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-25T14:39:45.009Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hackerkid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-05T16:05:17.000Z","updated_at":"2023-07-22T09:30:42.000Z","dependencies_parsed_at":"2023-05-23T14:02:00.644Z","dependency_job_id":null,"html_url":"https://github.com/hackerkid/learn-elixir","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hackerkid/learn-elixir","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerkid%2Flearn-elixir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerkid%2Flearn-elixir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerkid%2Flearn-elixir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerkid%2Flearn-elixir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hackerkid","download_url":"https://codeload.github.com/hackerkid/learn-elixir/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerkid%2Flearn-elixir/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29991302,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T01:47:34.672Z","status":"online","status_checked_at":"2026-03-02T02:00:07.342Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T18:51:59.797Z","updated_at":"2026-03-02T03:05:52.442Z","avatar_url":"https://github.com/hackerkid.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"My notes on learning Elixir from https://elixir-lang.org/getting-started/\n\nYou need access to Elixir REPL for trying out the example. Install at https://elixir-lang.org/install.html\n\n### Getting into the Elixir REPL\n\nYou can use the `iex` command to enter into the REPL after installing it.\n\n### Getting help\n\nUse the `h`\n\n```exs\niex\u003e h Kernel.trunc\n```\n\nIf the function has multiple signatures, specify the number of signatures to select the function.\n\n```exs\niex\u003e h Kernel.trunc/1\n```\n\n### Booleans\n\n`true` and `false`\n\nYou can compare like\n\n`true` == `false`\n\n\n### Checking data type\n\n`is_boolean`, `is_integer`, `is_float`, `is_number` etc.\n\n### Atoms (Symbols)\n\nThey are constants.\n\nExample\n\n`:apple`, `:orange` etc\n\nAtoms are equal if the names are equal\n\n```exs\niex\u003e :apple == :orange`\ntrue\n```\n\n`true` and `false` are also atoms. You can skip `:` for them.\n\n```exs\n\u003e :true == true\ntrue\n```\n\n### Strings\n\nEncoded using double quotes.\n\nSupports string interpolation.\n\n```exs\niex\u003e string = \"hello\"\n\"hello\"\niex\u003e \"#{string} world\"\n\"hello world\"\n```\n\nYou can print using\n```exs\niex\u003e IO.puts(\"hello\")\nhello\n:ok\n```\n\nStrings are represented as bytes. `ö` takes 2 bytes to be represnted in UTF-8.\n\nYou can concatenate strings using `\u003c\u003e`\n\n```exs\niex(47)\u003e x = \"hello\"\n\"hello\"\niex(48)\u003e y = \"world\"\n\"world\"\niex(49)\u003e x \u003c\u003e \" \" \u003c\u003e y\n\"hello world\"\n```\n\n```exs\niex\u003e is_binary(\"hellö\")\ntrue\niex\u003e byte_size(\"hellö\")\n6\niex\u003e String.length(\"hellö\")\n5\niex\u003e String.upcase(\"hello\")\n\"HELLO\"\n```\n\n### Anonymous functions\n\n\n```exs\niex\u003e add = fn a, b -\u003e a + b end\n#Function\u003c43.40011524/2 in :erl_eval.expr/5\u003e\niex\u003e add(1, 3)\n** (CompileError) iex:5: undefined function add/2\n\niex\u003e add.(1, 3)\n4\niex\u003e is_function(add)\ntrue\n```\n\nThe `.` is required to distinguish between normal functions.\n\nYou can access the variables that are in scope when the function is defined.\n\n```exs\niex\u003e x = 7\n7\niex\u003e print_x = fn -\u003e IO.puts(x) end\n#Function\u003c45.40011524/0 in :erl_eval.expr/5\u003e\niex\u003e print_x.()\n7\n:ok\n```\n\nVariabled declared inside the function does not affect the surrounding environment\n\n```exs\n#Function\u003c45.40011524/0 in :erl_eval.expr/5\u003e\niex\u003e y = 2                  \n2\niex\u003e set_y = fn -\u003e y = 3 end\nwarning: variable \"y\" is unused (there is a variable with the same name in the context, use the pin operator (^) to match on it or prefix this variable with underscore if it is not meant to be used)\n  iex:14\n\n#Function\u003c45.40011524/0 in :erl_eval.expr/5\u003e\niex\u003e set_y.()\n3\niex\u003e y\n2\n```\n\n### Lists\n\nLists are implemented as Linked Lists.\n\n```exs\niex\u003e list = [1, 2, \"three\", :four, true, false]  \n[1, 2, \"three\", :four, true, false]\n```\n\nYou can concatenate or subtract lists. Returns a new list. The Elixr data structures are immutable.\n```exs\niex(17)\u003e list = [1, 2, \"three\", :four, true, false]  \n[1, 2, \"three\", :four, true, false]\niex(18)\u003e [1, 2] ++ [3, 4]\n[1, 2, 3, 4]\niex(19)\u003e [1, 2, 3, 4, 5, true, false] -- [4, 5, false]\n[1, 2, 3, true]\n```\n\nHead is the first element and tail is the remaining elements.\n```\niex(23)\u003e hd(x)\n1\niex(24)\u003e tl(x)\n[2, 3, 4, 5]\n```\n\nYou can use `length` to get the length of the list. Since list is a linked\nlist the length operation takes linear time. In general, \"length\" is used to\nrefer for operations that take linear time and size is used for operations that\ndon't constant time.\n\n\n### Tuples\n\nTuples are stored continously in memory.\n\n```\niex\u003e x = {1, \"2\", :hello, true, [1, 2]}\n{1, \"2\", :hello, true, [1, 2]}\n```\n\nSo unlike lists you can access them using index.\n\n```exs\niex\u003e elem(x, 2)                        \n:hello\n```\n\nYou can also change the element of a tuple and returns a new tuple. The new tuple share the\nelements with the old tuple except the one that has been replaced.\n\n```exs\niex(38)\u003e x\n{1, \"2\", :hello, true, [1, 2]}\niex(39)\u003e put_elem(x, 3, :world)\n{1, \"2\", :hello, :world, [1, 2]}\niex(40)\u003e x\n{1, \"2\", :hello, true, [1, 2]}\n```\n\nYou can use the `tuple_size` function to get the size of the tuple.\n\n```exs\niex(42)\u003e x            \n{1, \"2\", :hello, true, [1, 2]}\niex(43)\u003e tuple_size(x)\n5\n```\n\n\n### Boolean operators\n\nSimiliar to Python, there is `and` and `or` for evaluating boolean values.\n```exs\niex(55)\u003e true and false        \nfalse\niex(56)\u003e false and true\nfalse\niex(57)\u003e true or false\ntrue\niex(58)\u003e true or raise(\"Error\")\ntrue\n```\n\nUnlike Python the left hand operator has to be a boolean.\n\n```exs\niex(62)\u003e true and 1      \n1\niex(63)\u003e 1 or true\n** (BadBooleanError) expected a boolean on left-side of \"or\", got: 1\n\niex(63)\u003e 1 and true\n** (BadBooleanError) expected a boolean on left-side of \"and\", got: 1\n\niex(63)\u003e true or 1\ntrue\niex(64)\u003e true and 3\n3\n```\n\nBut there are the traditional `||`, `\u0026\u0026` and `!` operators which can be\nevaulated using any data typles. 0 is not considered to be false.\n\n```exs\niex(86)\u003e nil \u0026\u0026 1 \nnil\niex(87)\u003e nil \u0026\u0026 2\nnil\niex(88)\u003e true and 2          \n2\niex(89)\u003e true and 3\n3\niex(90)\u003e 0 || 5\n0\niex(91)\u003e false || 5\n5\niex(92)\u003e false || 0\n0\niex(93)\u003e false \u0026\u0026 true\nfalse\niex(94)\u003e 0 \u0026\u0026 true    \ntrue\niex(95)\u003e 0 \u0026\u0026 nil \nnil\niex(96)\u003e nil \u0026\u0026 1\nnil\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackerkid%2Flearn-elixir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhackerkid%2Flearn-elixir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackerkid%2Flearn-elixir/lists"}