https://github.com/geirolz/fluent-copy
Scala 2 macros to have fluent copy on case classes
https://github.com/geirolz/fluent-copy
caseclass config configuration dsl fluent macros scala scala2 utils wrapper wrapper-api
Last synced: 3 months ago
JSON representation
Scala 2 macros to have fluent copy on case classes
- Host: GitHub
- URL: https://github.com/geirolz/fluent-copy
- Owner: geirolz
- License: apache-2.0
- Created: 2022-12-27T14:38:44.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-24T05:51:40.000Z (3 months ago)
- Last Synced: 2025-03-28T08:12:10.487Z (3 months ago)
- Topics: caseclass, config, configuration, dsl, fluent, macros, scala, scala2, utils, wrapper, wrapper-api
- Language: Scala
- Homepage:
- Size: 90.8 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# Fluent copy
[](https://github.com/geirolz/fluent-copy/actions)
[](https://codecov.io/gh/geirolz/fluent-copy)
[](https://www.codacy.com/gh/geirolz/fluent-copy/dashboard?utm_source=github.com&utm_medium=referral&utm_content=geirolz/fluent-copy&utm_campaign=Badge_Grade)
[](https://mvnrepository.com/artifact/com.github.geirolz/fluent-copy)
[](https://javadoc.io/doc/com.github.geirolz/fluent-copy_2.13)
[](https://scala-steward.org)
[](https://github.com/geirolz/fluent-copy/blob/master/LICENSE)Scala macros to have fluent copy on case classes
```sbt
libraryDependencies += "com.github.geirolz" %% "fluent-copy" % "0.0.1"
```- `copyWith` when `true` adds a method `with$FIELD_NAME(newvalue: $FIELD_TYPE): $CASE_CLASS`.
- `update` when `true` adds a method `update$FIELD_NAME(f: $FIELD_TYPE => $FIELD_TYPE): $CASE_CLASS`.
- `collection` when `true` adds methods:
- For `Option`
- `withSome$FIELD_NAME(f: $FIELD_COLLECTION_TYPE): $CASE_CLASS`
- `withNone$FIELD_NAME: $CASE_CLASS`
- For collections `Seq`, `List`, `Set`
- `withOne$FIELD_NAME(f: $FIELD_COLLECTION_TYPE): $CASE_CLASS`
- `withEmpty$FIELD_NAME: $CASE_CLASS````scala
import com.geirolz.macros.fluent.copy.FluentCopy@FluentCopy(copyWith = true, update = true, collection = true)
case class Foo(
value: Int,
option: Option[Double],
list: List[String],
set: Set[String],
seq: Seq[String]
)
```Generates
```scala
implicit class FooFluentConfigOps(i: Foo) {
def withValue(value: Int): Foo = ???def updateValue(f: Int => Int): Foo = ???
def withOption(option: Option[Double]): Foo = ???
def updateOption(f: Option[Double] => Option[Double]): Foo = ???
def withSomeOption(option: Double): Foo = ???
def withNoneOption: Foo = ???
def withList(list: List[String]): Foo = ???
def updateList(f: List[String] => List[String]): Foo = ???
def withOneList(list: String): Foo = ???
def withEmptyList: Foo = ???
def withSet(set: Set[String]): Foo = ???
def updateSet(f: Set[String] => Set[String]): Foo = ???
def withOneSet(set: String): Foo = ???
def withEmptySet: Foo = ???
def withSeq(seq: Seq[String]): Foo = ???
def updateSeq(f: Seq[String] => Seq[String]): Foo = ???
def withOneSeq(seq: String): Foo = ???
def withEmptySeq: Foo = ???
}
```