From eadfeb104c64e21ba19f4bc487b0d91c3c7a8d15 Mon Sep 17 00:00:00 2001 From: tarao Date: Mon, 6 Nov 2023 16:07:03 +0900 Subject: [PATCH] Make operators aliases. --- .../github/tarao/record4s/ArrayRecord.scala | 20 +++++++++++++------ .../com/github/tarao/record4s/Record.scala | 12 +++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/modules/core/src/main/scala/com/github/tarao/record4s/ArrayRecord.scala b/modules/core/src/main/scala/com/github/tarao/record4s/ArrayRecord.scala index a4b9493..5fd658b 100644 --- a/modules/core/src/main/scala/com/github/tarao/record4s/ArrayRecord.scala +++ b/modules/core/src/main/scala/com/github/tarao/record4s/ArrayRecord.scala @@ -196,7 +196,10 @@ object ArrayRecord extends ArrayRecord.Extensible[EmptyTuple] { * @return * an object to define new fields */ - def + : Extensible[R] = new Extensible.Appender(record) + def updated: Extensible[R] = new Extensible.Appender(record) + + /** Alias for `updated` */ + inline def + : Extensible[R] = updated /** Concatenate this record and another record. * @@ -218,19 +221,19 @@ object ArrayRecord extends ArrayRecord.Extensible[EmptyTuple] { * @return * a new record which has the both fields from this record and `other` */ - inline def ++[R2: RecordLike, RR <: ProductRecord]( + inline def concat[R2: RecordLike, RR <: ProductRecord]( other: R2, - )(using concat: Concat[R, R2]): concat.Out = + )(using c: Concat[R, R2]): c.Out = withPotentialTypingError { val vec = record .__fields .toVector .concat(summon[RecordLike[R2]].orderedIterableOf(other)) - inline erasedValue[concat.NeedDedup] match { + inline erasedValue[c.NeedDedup] match { case _: false => - newArrayRecord[concat.Out](vec) + newArrayRecord[c.Out](vec) case _ => - newArrayRecord[concat.Out]( + newArrayRecord[c.Out]( vec .deduped .iterator @@ -239,6 +242,11 @@ object ArrayRecord extends ArrayRecord.Extensible[EmptyTuple] { } } + /** Alias for `concat` */ + inline def ++[R2: RecordLike, RR <: ProductRecord]( + other: R2, + )(using c: Concat[R, R2]): c.Out = concat(other) + /** Give a type tag to this record. * * @example diff --git a/modules/core/src/main/scala/com/github/tarao/record4s/Record.scala b/modules/core/src/main/scala/com/github/tarao/record4s/Record.scala index 6ae7c1c..8ad40f6 100644 --- a/modules/core/src/main/scala/com/github/tarao/record4s/Record.scala +++ b/modules/core/src/main/scala/com/github/tarao/record4s/Record.scala @@ -85,7 +85,10 @@ object Record { * @return * an object to define new fields */ - def + : Extensible[R] = new Extensible(record) + def updated: Extensible[R] = new Extensible(record) + + /** Alias for `updated` */ + inline def + : Extensible[R] = updated /** Concatenate this record and another record. * @@ -107,7 +110,7 @@ object Record { * @return * a new record which has the both fields from this record and `other` */ - inline def ++[R2: RecordLike, RR <: %]( + inline def concat[R2: RecordLike, RR <: %]( other: R2, )(using Concat.Aux[R, R2, RR]): RR = withPotentialTypingError { newMapRecord[RR]( @@ -118,6 +121,11 @@ object Record { ) } + /** Alias for `concat` */ + inline def ++[R2: RecordLike, RR <: %]( + other: R2, + )(using Concat.Aux[R, R2, RR]): RR = concat(other) + /** Create a new record by selecting some fields of an existing record. * * @example