{"id":49969581,"url":"https://github.com/polyvariant/named-functions","last_synced_at":"2026-05-18T07:17:33.210Z","repository":{"id":350570419,"uuid":"1207428256","full_name":"polyvariant/named-functions","owner":"polyvariant","description":"Micro-library for working with functions with named parameters.","archived":false,"fork":false,"pushed_at":"2026-04-23T18:07:45.000Z","size":68,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-23T20:10:07.142Z","etag":null,"topics":["macros","scala","scala3"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polyvariant.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-10T23:48:41.000Z","updated_at":"2026-04-23T18:07:32.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/polyvariant/named-functions","commit_stats":null,"previous_names":["polyvariant/named-tupled"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/polyvariant/named-functions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyvariant%2Fnamed-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyvariant%2Fnamed-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyvariant%2Fnamed-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyvariant%2Fnamed-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polyvariant","download_url":"https://codeload.github.com/polyvariant/named-functions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyvariant%2Fnamed-functions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33168931,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T05:43:36.989Z","status":"ssl_error","status_checked_at":"2026-05-18T05:43:19.133Z","response_time":71,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["macros","scala","scala3"],"created_at":"2026-05-18T07:17:29.427Z","updated_at":"2026-05-18T07:17:33.202Z","avatar_url":"https://github.com/polyvariant.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# named-functions\n\nScala 3 macros for converting multi-parameter functions into functions with named parameters or named-tuple arguments, preserving the original parameter names.\n\n## Quick overview\n\n```scala\nimport namedfunctions.syntax.*\n\ndef greet(name: String, age: Int): String = s\"$name is $age\"\n\n// namedTuple(...) — build a named tuple from local names\nval age = 30\nval name = \"Alice\"\nval nt = namedTuple(name, age)\n\n// .named — named parameters at call site\nval f = greet.named\nf(name = \"Alice\", age = 30) // \"Alice is 30\"\n\n// .namedTupled — function from named tuple\nval g = greet.namedTupled\ng((name = \"Alice\", age = 30)) // \"Alice is 30\"\n\n// .namedUntupled — reverse of tupling\nval h: ((name: String, age: Int)) =\u003e String = t =\u003e s\"${t.name} is ${t.age}\"\nh.namedUntupled(name = \"Alice\", age = 30) // \"Alice is 30\"\n\n// .nameChecked — compile-time name validation, order-independent\nval age = 30\nval name = \"Alice\"\ngreet.nameChecked(age, name) // \"Alice is 30\" — reordered automatically\n// greet.nameChecked(age, x) // compile error: unexpected: x; missing: name\n\n// .applyProduct — apply from case class fields by name\ncase class Person(age: Int, name: String, email: String)\ngreet.applyProduct(Person(30, \"Alice\", \"a@b.com\")) // \"Alice is 30\" — extra fields ignored\n```\n\n## Installation\n\nAvailable on Maven Central as `org.polyvariant::named-functions`.\n\nIn scala-cli:\n\n```scala\n//\u003e using dep org.polyvariant::named-functions::\u003cversion\u003e\n```\n\nIn sbt:\n\n```scala\nlibraryDependencies += \"org.polyvariant\" %% \"named-functions\" % \"\u003cversion\u003e\"\n```\n\nIn Mill:\n\n```scala\nivy\"org.polyvariant::named-functions:\u003cversion\u003e\"\n```\n\n## Usage\n\n```scala\nimport namedfunctions.syntax.*\n\ndef foo(entityId: Int, userId: String): Boolean = ???\n\nval entityId = 1\nval userId = \"hello\"\nval params = namedTuple(entityId, userId)\n\n// Wrap a function so that its parameters are named at the call site\nval f = foo.named\nf(entityId = 1, userId = \"hello\")\n\n// Convert a function into a Function1 from a named tuple\nval g = foo.namedTupled\ng((entityId = 1, userId = \"hello\"))\n\n// Convert a Function1 from a named tuple back into a named-parameter function\nval h: ((entityId: Int, userId: String)) =\u003e Boolean = ???\nval f2 = h.namedUntupled\nf2(entityId = 1, userId = \"hello\")\n```\n\n### Multiple parameter lists\n\nMethods with multiple parameter lists are supported — the result is a curried function with named parameters at each level:\n\n```scala\ndef bar(entityId: Int)(userId: String): Boolean = ???\n\nval f = bar.named\nf(entityId = 1)(userId = \"hello\")\n\nval g = bar.namedTupled\ng((entityId = 1))((userId = \"hello\"))\n```\n\n### `NamedFunctions.of` / `NamedFunctions.apply` / `.named`\n\nConverts a multi-parameter function `(a: A, b: B, ...) =\u003e R` into a function with named parameters, preserving the original parameter names.\n\n### `NamedFunctions.tupled` / `.namedTupled`\n\nLike `.tupled` but the resulting tuple type carries the parameter names from the original method. Converts a multi-parameter function into a `Function1` from a named tuple: `((a: A, b: B, ...)) =\u003e R`.\n\n### `syntax.namedTuple`\n\nBuilds a named tuple directly from variable references or field accesses by using the final name segment as the label:\n\n```scala\nimport namedfunctions.syntax.*\n\nval a = 42\nval b = \"hello\"\n\nnamedTuple(a, b) // (a = 42, b = \"hello\")\n```\n\n### `NamedFunctions.untupled` / `.namedUntupled`\n\nThe reverse of `tupled`. Converts a `Function1` from a named tuple into a multi-parameter function with named parameters.\n\n### `.nameChecked`\n\nCompile-time check that argument variable names exactly match the function's parameter names. Arguments are matched by name and automatically reordered, so order doesn't matter — only that the names are correct:\n\n```scala\ndef foo(a: Int, b: String): String = s\"$a-$b\"\n\nval a = 42\nval b = \"hello\"\n\nfoo.nameChecked(a, b)    // compiles — \"42-hello\"\nfoo.nameChecked(b, a)    // also compiles — reordered to \"42-hello\"\nfoo.nameChecked(b, x)    // compile error: unexpected: x; missing: a\nfoo.nameChecked(\"hello\") // compile error: requires variable references or field accesses\n```\n\nArguments can be plain variable references or field accesses (e.g. `obj.field`). The last segment of the access is used as the name. Multiple parameter lists are supported — all arguments are passed flat:\n\n```scala\ndef bar(entityId: Int)(userId: String): Boolean = ???\n\nval entityId = 1\nval userId = \"hello\"\nbar.nameChecked(entityId, userId)\n```\n\nField accesses work too — the field name is what matters:\n\n```scala\ncase class Source(a: Int, b: String)\nval src = Source(42, \"hello\")\nfoo.nameChecked(src.a, src.b) // compiles — \"42-hello\"\n```\n\n### `.applyProduct`\n\nApplies a function using fields from a case class, matched by name (not position). The case class may have extra fields, but all function parameters must be present:\n\n```scala\ndef foo(a: Int, b: String): String = s\"$a-$b\"\n\ncase class Params(b: String, a: Int)\nfoo.applyProduct(Params(\"hello\", 42)) // \"42-hello\" — fields matched by name\n\ncase class Extended(a: Int, b: String, extra: Boolean)\nfoo.applyProduct(Extended(1, \"hi\", true)) // works — extra fields ignored\n```\n\nMultiple parameter lists are supported:\n\n```scala\ndef bar(entityId: Int)(userId: String): Boolean = ???\n\ncase class Params(entityId: Int, userId: String)\nbar.applyProduct(Params(1, \"hello\"))\n```\n\n## Chaining\n\nFeatures can be composed — the output of one transformation is a valid input for another:\n\n```scala\ndef foo(a: Int, b: String): String = s\"$a-$b\"\n\ncase class Params(b: String, a: Int)\nfoo.named.applyProduct(Params(\"hello\", 42)) // \"42-hello\"\n\nval a = 42\nval b = \"hello\"\nfoo.named.nameChecked(a, b) // \"42-hello\"\n\n// Round-trip through tupling and back\nfoo.namedTupled.namedUntupled.applyProduct(Params(\"hello\", 42)) // \"42-hello\"\n```\n\n## Limitations\n\nAll features require the macro to extract parameter names from the call site's AST. This works with method references (`obj.method`), eta-expanded methods, and case class constructors (`Foo.apply`), but **not with function values stored in a `val`**:\n\n```scala\nval f = (a: Int, b: String) =\u003e s\"$a-$b\"\nf.named          // compile error: Could not extract parameter names\nf.nameChecked(a, b) // same\nf.applyProduct(p)   // same\n```\n\nThe parameter names exist in the lambda at the definition site, but are erased by the time the `val` reference reaches the macro.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolyvariant%2Fnamed-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolyvariant%2Fnamed-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolyvariant%2Fnamed-functions/lists"}