Releases: arainko/chanterelle
chanterelle 0.1.3
chanterelle 0.1.3
This release features a milestone feature - deep merging of named tuples. Take a quick peek at the examples from the docs:
import chanterelle.*
val tup = (field1 = 1, field2 = (level1Field1 = 3, level1Field2 = (level2Field = 4)))
val mergee = (field2 = (level1Field3 = 5, level1Field2 = (anotherField = 6)))
val transformed = tup.transform(_.merge(mergee))
// evaluates to:
// (field1 = 1, field2 = (level1Field1 = 3, level1Field2 = (level2Field = 4, anotherField = 6), level1Field3 = 5))...or if you want to be more precise in applying your merges you can try the .regional modifier:
val tup = (field1 = 1, field2 = (level1Field1 = 3, level1Field2 = (level2Field = 4)))
val mergee = (level1Field2 = (anotherField = 6))
val transformed = tup.transform(_.merge(mergee).regional(_.field2))
// evaluates to:
// (field1 = 1, field2 = (level1Field1 = 3, level1Field2 = (level2Field = 4, anotherField = 6)))The rules of merging are as follows:
- named tuples are merged by field name,
- fields from the named tuple we merge with (the mergee) take precedence,
- nested named tuples (that don't come from modifications) and other merged values are recursed,
- other values get completely overwritten using the value from the mergee.
At this time, there are some limitations on what you can do with a merged value in the same .transform block that I hope to address in the future (i.e. currently it's not possible to use .put on a merged value, things like that), in the meantime users can always chain multiple .transforms to achieve whatever they were going for.
What's Changed
- Fix typo in README.md for accessing Map keys by @ritschwumm in #48
- Update sbt-scalajs, scalajs-library_2.13, ... to 1.20.2 by @scala-steward in #49
- Update sbt, scripted-plugin to 1.12.0 by @scala-steward in #50
- Update scalafmt-core to 3.10.4 by @scala-steward in #51
- Update scalafmt-core to 3.10.6 by @scala-steward in #57
- Update sbt, scripted-plugin to 1.12.2 by @scala-steward in #58
- Update munit to 1.2.2 by @scala-steward in #55
- Update auxlib, clib, javalib, nativelib, ... to 0.5.10 by @scala-steward in #53
- Update scalafmt-core to 3.10.7 by @scala-steward in #60
- [Issue #7] Deep merging by @arainko in #59
- Update scala3-library, ... to 3.8.1 by @scala-steward in #52
- use
.runtimeCheckedinstead of unchecked by @arainko in #63
New Contributors
- @ritschwumm made their first contribution in #48
Full Changelog: v0.1.2...v0.1.3
chanterelle 0.1.2
chanterelle 0.1.2
This release adds a new .rename modifier that allows for ad-hoc-ish field name transformations:
val tup = (anotherField = (field1 = 123, field2 = 123))
val transformed = tup.transform(_.rename(_.replace("field", "property").toUpperCase))(ANOTHERFIELD = (PROPERTY1 = 123, PROPERTY2 = 123))The blast radius of the renaming function can be further controlled with '.local' and '.regional':
val tup = (optField = Some((field = (lowerDown = 1))))
// '.local' renames the toplevel fields
val transformedLocal = tup.transform(_.rename(_.toUpperCase).local(_.optField.element))
// '.regional' makes it so that all the of fields underneath the path are transformed
val transformedRegional = tup.transform(_.rename(_.toUpperCase).regional(_.optField.element))val transformedLocal = (optField = Some((FIELD = (lowerDown = 1))))
val transformedRegional = (optField = Some((FIELD = (LOWERDOWN = 1))))There's also a number of predefined case transformations inside the FieldName companion object:
val camel = (
repoInfo = (
fullName = "octocat/hello-world",
createdAt = "2011-01-26T19:01:12Z",
)
)
val snake = (
repo_info = (
full_name = "octocat/hello-world",
created_at = "2011-01-26T19:01:12Z",
)
)
val kebab = (
`repo-info` = (
`full-name` = "octocat/hello-world",
`created-at` = "2011-01-26T19:01:12Z",
)
)
val camelToSnake = camel.transform(_.rename(FieldName.camelCase.toSnakeCase))
val camelToKebab = camel.transform(_.rename(FieldName.camelCase.toKebabCase))
val snakeToCamel = snake.transform(_.rename(FieldName.snakeCase.toCamelCase))
val kebabToCamel = kebab.transform(_.rename(FieldName.kebabCase.toCamelCase))val camelToSnake = (repo_info = (full_name = "octocat/hello-world", created_at = "2011-01-26T19:01:12Z"))
val camelToKebab = (repo-info = (full-name = "octocat/hello-world", created-at = "2011-01-26T19:01:12Z"))
val snakeToCamel = (repoInfo = (fullName = "octocat/hello-world", createdAt = "2011-01-26T19:01:12Z"))
val kebabToCamel = (repoInfo = (fullName = "octocat/hello-world", createdAt = "2011-01-26T19:01:12Z"))Users can also define their own bundles of transformations by combaning various operations on FieldNames in a transparent inline def:
transparent inline def renamedAndUppercased(inline fieldName: FieldName) =
fieldName.rename("someName", "someOtherName").toUpperCase
val tup = (someName = 1)
val transformed = tup.transform(_.rename(renamedAndUppercased))(SOMEOTHERNAME = 1)What's Changed
- Update README.md by @arainko in #19
- Update sbt, scripted-plugin to 1.11.6 by @scala-steward in #21
- Update scala3-library, ... to 3.7.3 by @scala-steward in #22
- Update sbt-scalajs, scalajs-library_2.13, ... to 1.20.1 by @scala-steward in #20
- Update munit to 1.2.0 by @scala-steward in #25
- Update scalafmt-core to 3.9.10 by @scala-steward in #24
- internalize 'removed' in
OfFieldby @arainko in #26 - Update sbt-typelevel-ci-release to 0.8.1 by @scala-steward in #27
- Update sbt, scripted-plugin to 1.11.7 by @scala-steward in #28
- Update sbt-typelevel-ci-release to 0.8.2 by @scala-steward in #30
- Update sbt-scalafmt to 2.5.6 by @scala-steward in #36
- Update auxlib, clib, javalib, nativelib, ... to 0.5.9 by @scala-steward in #31
- Update sbt-scalafix to 0.14.4 by @scala-steward in #29
- Update munit to 1.2.1 by @scala-steward in #32
- Update sbt-mdoc to 2.8.0 by @scala-steward in #33
- Update scala3-library, ... to 3.7.4 by @scala-steward in #37
- Update sbt-typelevel-ci-release to 0.8.3 by @scala-steward in #38
- Update scalafmt-core to 3.10.2 by @scala-steward in #39
- Update sbt-mdoc to 2.8.1 by @scala-steward in #40
- Update sbt-scalafix to 0.14.5 by @scala-steward in #41
- Update sbt-typelevel-ci-release to 0.8.4 by @scala-steward in #42
- Update sbt-mdoc to 2.8.2 by @scala-steward in #43
- Update scalafmt-core to 3.10.3 by @scala-steward in #44
- [Issue #5] field renaming by @arainko in #45
- add renaming docs by @arainko in #46
Full Changelog: v0.1.1...v0.1.2
chanterelle 0.1.1
chanterelle 0.1.1
This release brings support for Scala JS and Scala Native (thanks @plokhotnyuk!) along with a new feature - Either traversals:
val tup = (left = Left(1), right = Right("2"))
val transformed = tup.transform(
_.update(_.left.leftElement)(_ + 1),
_.update(_.right.rightElement)(_ + "-SUFFIXED")
)
// evaluates to this:
(left = Left(2), right = Right("2-SUFFIXED"))and a bugfix for selecting tuple elements with .apply(N) rather than solely relying on ._N accessors (which only go up to 22!)
What's Changed
- Version is 0.1.0 by @arainko in #9
- Update scala3-library to 3.7.2 by @scala-steward in #10
- Update scalafmt-core to 3.9.9 by @scala-steward in #11
- Update sbt, scripted-plugin to 1.11.4 by @scala-steward in #12
- [Issue #4] Fix .apply(N) selectors on tuples by @arainko in #13
- Add Scala.js and ScalaNative support by @plokhotnyuk in #15
- Update sbt, scripted-plugin to 1.11.5 by @scala-steward in #16
- Clean up the build by @arainko in #17
- [Issue #6] add support for Either travelsals by @arainko in #18
New Contributors
- @plokhotnyuk made their first contribution in #15
Full Changelog: v0.1.0...v0.1.1
chanterelle 0.1.0
chanterelle 0.1.0
chanterelle is a library for seamless named tuple interactions - think deep modifications, field removals, additions and lens-like ops. You know, the works.
Installation
libraryDependencies += "io.github.arainko" %% "chanterelle" % "0.1.0"Documentation
The entry point of chanterelle is a single import:
import chanterelle.*which brings in the .transform extension method defined on named tuples:
val input = (toplevelField = (nestedField = 1, fieldToUpdate = 2, optionalField = Some((anEvenMoreOptionalField = 3))))
val transformed = input.transform(
_.update(_.toplevelField.fieldToUpdate)(_ + 1), // note the value of toplevelField.fieldToUpdate in the output
_.remove(_.toplevelField.nestedField), // toplevelField.nestedField gets removed from the output value
_.put(_.toplevelField.optionalField.element)((newField = 4)) // the element of an Option or a collection can be accessed with `.element`
)...which, in turn, evaluates to:
(toplevelField = (fieldToUpdate = 3, optionalField = Some((anEvenMoreOptionalField = 3, newField = 4))))Head on over to the README if you want to see more!
What's Changed
New Contributors
Full Changelog: v0.0.1...v0.1.0
chanterelle 0.0.1
chanterelle 0.0.1
This is the very first release of chanterelle - this version has all of the MVP features that were initially planned i.e:
Support for:
✔️ named tuples
✔️ tuples
✔️ options
✔️ collections
Modifiers:
✔️ single-element .put
✔️ single-element .compute
✔️ update
✔️ remove (both named and positional tuples)
Other:
✔️ sane errors
✔️ optimized interpreter - turn non-modified branches into Leaves that just take the source value
What's Changed
- Update sbt, scripted-plugin to 1.11.3 by @scala-steward in #1
- Update scalafmt-core to 3.9.8 by @scala-steward in #2
New Contributors
- @scala-steward made their first contribution in #1
Full Changelog: https://github.com/arainko/chanterelle/commits/v0.0.1