Support companion object factory method
@backuitist is already working on this.
Since Sep 8, 2015.
Assessment
This issue has not been assessed yet.
Description
Sometimes you want to perform some validation before constructing an object. A good place for that is the method factory on the companion object:
class ParamsNeedValidation private(param1: Param1, param2: Param2)
object ParamsNeedValidation {
def apply(param1: Param1, param2: Param2) : ParamsNeedValidation = {
// validate param1 & param2
new ParamsNeedValidation(param1, param2)
}
}
When the primary constructor is found to be private, macwire could give the companion object a chance and IF it has a single apply method, try it.
So we would end up with this:
lazy val pnv = wire[ParamsNeedValidation]
Turned into
lazy val pnv = ParamsNeedValidation(param1, param2)
If the companion object has more than one apply method, a compilation error is returned:
ParamsNeedValidation constructor is private and its companion object has more than one apply method:
- apply(param1, param2)
- apply(param3)
If the companion object has no apply method, then we would fail with the usual:
ParamsNeedValidation constructor is private
- Dominant language
- Scala
- Stars
- 1.3k
- Forks
- 77
- Avg merge
- 9m
- Merged PRs (30d)
- 4
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from softwaremill/macwire
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
softwaremill/macwire#412 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
softwaremill/macwire#391 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
softwaremill/macwire#301 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
softwaremill/macwire#281 · 5 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
softwaremill/macwire#278 · 3 comments ·
All issues in softwaremill/macwire
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
ergoplatform/ergodocs#614 ·
-
area:ci enhancement requires-triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
apache/datafusion-comet#6078 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
bug delta-datalayout flink
Difficulty 2/5 1-3 hours Newbie friendliness 86/100