ctor

A tiny macro library for Scala that lets your generic code gain access to constructors.

License

License

Categories

Categories

Net
GroupId

GroupId

net.zygfryd
ArtifactId

ArtifactId

ctor_2.13
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

ctor
A tiny macro library for Scala that lets your generic code gain access to constructors.
Project URL

Project URL

https://github.com/zygfryd/scala-zygf-ctor
Project Organization

Project Organization

zygfryd's projects
Source Code Management

Source Code Management

https://github.com/zygfryd/scala-zygf-ctor

Download ctor_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/net.zygfryd/ctor_2.13/ -->
<dependency>
    <groupId>net.zygfryd</groupId>
    <artifactId>ctor_2.13</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/net.zygfryd/ctor_2.13/
implementation 'net.zygfryd:ctor_2.13:0.1.1'
// https://jarcasting.com/artifacts/net.zygfryd/ctor_2.13/
implementation ("net.zygfryd:ctor_2.13:0.1.1")
'net.zygfryd:ctor_2.13:jar:0.1.1'
<dependency org="net.zygfryd" name="ctor_2.13" rev="0.1.1">
  <artifact name="ctor_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.zygfryd', module='ctor_2.13', version='0.1.1')
)
libraryDependencies += "net.zygfryd" % "ctor_2.13" % "0.1.1"
[net.zygfryd/ctor_2.13 "0.1.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.5
org.scala-lang : scala-reflect jar 2.13.5

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.13 jar 3.0.9

Project Modules

There are no modules declared in this project.

zygf.ctor

This is a tiny macro library for Scala that lets your generic code gain access to constructors for your type arguments.

Supported Scala versions: 2.11, 2.12, 2.13.

Usage

Artifact
"net.zygfryd" %% "ctor" % "0.1.1"
Import
import zygf.ctor.Ctor

Obtaining a function that calls the constructor matching the given signature. You can access the function via the member make of the returned object.

def foo[T](implicit ctor: Ctor[String => T]) = ctor.make("foo")

A companion object’s apply method qualifies as a constructor too:

trait Foo

object Foo {
  def apply(s: String) = ???
}

val ctor = Ctor.get[String => Foo]

Multiple parameter lists are supported as curried functions:

class Foo(val i: Int)(val s: String)

val ctor = Ctor.get[Int => String => Foo]

ctor.make(42)("foo")
Note
Implicit parameter lists need to be converted to regular parameter lists, as there’s no other way to represent them in a function signature.
class Foo(val i: Int)(implicit val s: String)

Ctor.get[Int => String => Foo] // works
Ctor.get[Int => Foo] // doesn't work

If you omitted the implicit parameter list, the compiler would look for implicit parameters at the constructor function’s creation site and not the call site.

class Foo(val i: Int)(implicit val s: String)

val ctor = {
  implicit val s: String = "foo"
  Ctor.get[Int => Foo] // works
}

{
  implicit val s: String = "bar" // ignored
  ctor.make(42) == Foo(42)("foo")
}

Versions

Version
0.1.1