Repository navigation
Add .hoist, interop typeclasses - #143
Merged
Merged
Conversation
…ying a fallible transformation)
…t.Passthrough as well smh)
…he end results (only when you explicitly USE those you'll get a wrapped result)
… type param on 'traverseCollection'
arainko
commented
Nov 11, 2026
arainko
commented
Nov 11, 2026
arainko
commented
Nov 11, 2026
arainko
commented
Nov 11, 2026
arainko
commented
Nov 11, 2026
arainko
commented
Nov 11, 2026
arainko
commented
Nov 11, 2026
arainko
commented
Nov 11, 2026
arainko
commented
Nov 11, 2026
arainko
commented
Nov 11, 2026
arainko
commented
Nov 11, 2026
arainko
commented
Nov 11, 2026
arainko
commented
Nov 11, 2026
arainko
commented
Nov 11, 2026
arainko
force-pushed
the
map-on-tuples
branch
from
November 11, 2026 20:13
58c8e04 to
af2b674
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
So, what's new?
.hoistAdds a new
.hoistmodifier which (taken straight from the docs):Hoist a single field up to the top of the transformation (based on the
Modethat's currently in scope).This will also hoist each fallible field that it encouters on the path to the selected field.
Example:
Note that this transformation can be further customized with
.localand.regional:.localhoists the currently selected set of fields (like in the example above, note thatnestedField1wasn't hoisted).regionalhoists ALL possible fields in a given region.An example with
.regional:Transformation
Mode[F]Modeis a capability that provides the ability to 'bubble up' nested wrapped values (i.e. ones wrapped in anF) up to the top, for example:Modescome in 3 flavors:Accumulating- the least powerful, able to model error accumulation but the the whole structure needs to be known from the get go (in other words, it can't hoist nested fallible fields likeF[F[Int]]),FailFast- the intermediate in terms of power - can't model error accumulation, but can hoist nested fallible fields,Parallel- the most powerful, a mix of bothAccumulatingandFailFast. It can model both error accumulation AND hoisting of nested fallible fields.Note that a
Modeis not really a typeclass since there isn't really a single instance for each F (for example, instances forEithercould come in all sorts of shapes - sometimes it's best to useFailFast, other timesAccumulating).Modesare usually provided at the callsite with their.applymethod that puts them in the implicit scope of a block of code (just like in the example above).Interop typeclasses
chanterelle.interop.Collection.IntoIteratorDefined as:
An interop typeclass representing types that can be converted into iterators.
Instances of
Collection.IntoIteratorare usually created withCollection.IntoIterator.from, for example:This typeclass requires its 2 type parameters to be fully-applied and that's because it abstracts over both 'classic' collection shapes (i.e. ones with a single elem type constructor - like List)
and Map-shaped ones (i.e. with a two elem type constructor - like HashMap).
Note that
chanterellewill only considerColl[_]andMap[_, _]shaped instances (like the two aforementioned examples) when looking for candidates during the expansion of its.transformmacro.An instance of
Collection.IntoIteratorandCollection.Builder(orCollection.Builder.Fallible) will allowchanterelleto consider a given type as a collection type which enables some additional combinators inside the.transformmacro, like the.eachoperator that 'cuts through' collection shapes when configuring transformations.chanterelle.interop.Collection.BuilderDefined as:
An interop typeclass that abstracts over collection builders where the collectiom being built can be empty, its fallible sibling
Collect.Builder.Fallibleallows forconstructing collections that are meant to be non-empty (eg. like
cats'NonEmptyList).Custom instances of
Collection.Builderare usually meant to be built usingCollection.Builder.fromas the starting point and then transforming it into our target type with.transform, for example:...or if we're operating on a custom Map:
An instance of
Collection.Builder(orCollection.Builder.Fallible) andCollection.IntoIteratorwill allowchanterelleto consider a given type as a collection type which enables some additional combinators inside the.transformmacro,like the
.eachoperator that 'cuts through' collection shapes when configuring transformations.This typeclass requires its 2 type parameters to be fully-applied and that's because it abstracts over both 'classic' collection shapes (i.e. ones with a single elem type constructor - like List)
and Map-shaped ones (i.e. with a two elem type constructor - like HashMap).
Note that
chanterellewill only considerColl[_]andMap[_, _]shaped instances when looking for candidates during the expansion of its.transformmacro.chanterelle.interop.Collection.Builder.FallibleDefined as:
An interop typeclass that abstracts over collection builders where the collection being built cannot be empty (or their construction is fallible in any other way).
Custom instances of
Collection.Builder.Fallibleare usually meant to be built usingCollection.Builder.fromas the starting point and then transforming it into our target type with.transformand finishing up with.fallible, for example:...or if we're operating on a custom Map:
This typeclass requires its 2 type parameters to be fully-applied and that's because it abstracts over both 'classic' collection shapes (i.e. ones with a single elem type constructor - like List)
and Map-shaped ones (i.e. with a two elem type constructor - like HashMap).
Note that
chanterellewill only considerColl[_]andMap[_, _]shaped instances when looking for candidates during the expansion of its.transformmacro.chanterelle.interop.MappableDefined as:
Mappableis an interop typeclass that allowschanterelleto cut through wrapper types (by allowing.elementcalls inside path selectors inside the.transformmacro). For example:Other stuff
So apart from all of the above there's also some deprecated and some new path selectors (.element has been deprecated on
Option[A] | Iterable[A]and replaces (respectively) with.someand.each.