Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Support companion object factory method

オープン
#64 コメント 5 件 リアクション 0 件 担当者 1 名 GitHub で見る

@backuitist がすでに取り組んでいます。

2015年9月8日 から。

評価

この issue はまだ評価されていません。

説明

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
主要言語
Scala
スター
1.3k
フォーク
77
平均マージ
9分
マージ済み PR(30日)
4

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

softwaremill/macwire のほかの issue

softwaremill/macwire の issue をすべて見る

似ている issue

Scala の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。