Skip to content

polyvariant/named-functions

Repository files navigation

named-functions

Scala 3 macros for converting multi-parameter functions into functions with named parameters or named-tuple arguments, preserving the original parameter names.

Installation

Available on Maven Central as org.polyvariant::named-functions.

In scala-cli:

//> using dep org.polyvariant::named-functions::<version>

In sbt:

libraryDependencies += "org.polyvariant" %% "named-functions" % "<version>"

In Mill:

ivy"org.polyvariant::named-functions:<version>"

Usage

import namedfunctions.syntax.*

def foo(entityId: Int, userId: String): Boolean = ???

// Wrap a function so that its parameters are named at the call site
val f = foo.named
f(entityId = 1, userId = "hello")

// Convert a function into a Function1 from a named tuple
val g = foo.namedTupled
g((entityId = 1, userId = "hello"))

NamedFunctions.of / NamedFunctions.apply / .named

Converts a multi-parameter function (a: A, b: B, ...) => R into a function with named parameters, preserving the original parameter names.

NamedFunctions.tupled / .namedFunctions

Like .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, ...)) => R.

About

Micro-library for working with functions with named parameters.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages