-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix lenses generation for data classes with secondary constructors (#…
- Loading branch information
1 parent
795f8ae
commit 2604a46
Showing
10 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
modules/meta/arrow-meta/models/src/main/java/arrow/ap/objects/iso/IsoSecondaryConstructor.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package arrow.ap.objects.iso | ||
|
||
import arrow.optics.OpticsTarget | ||
import arrow.optics.optics | ||
|
||
@optics([OpticsTarget.ISO]) | ||
data class IsoSecondaryConstructor(val fieldNumber: Int, val fieldString: String) { | ||
constructor(number: Int): this(number, number.toString()) | ||
companion object | ||
} |
10 changes: 10 additions & 0 deletions
10
...es/meta/arrow-meta/models/src/main/java/arrow/ap/objects/lens/LensSecondaryConstructor.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package arrow.ap.objects.lens | ||
|
||
import arrow.optics.OpticsTarget | ||
import arrow.optics.optics | ||
|
||
@optics([OpticsTarget.LENS]) | ||
data class LensSecondaryConstructor(val field: String) { | ||
constructor(number: Int): this(number.toString()) | ||
companion object | ||
} |
10 changes: 10 additions & 0 deletions
10
...arrow-meta/models/src/main/java/arrow/ap/objects/optional/OptionalSecondaryConstructor.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package arrow.ap.objects.optional | ||
|
||
import arrow.optics.OpticsTarget | ||
import arrow.optics.optics | ||
|
||
@optics([OpticsTarget.OPTIONAL]) | ||
data class OptionalSecondaryConstructor(val field: String?) { | ||
constructor(number: Int?): this(number?.toString()) | ||
companion object | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
8 changes: 8 additions & 0 deletions
8
modules/meta/arrow-meta/src/test/resources/arrow/ap/objects/iso/IsoSecondaryConstructor.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package `arrow`.`ap`.`objects`.`iso` | ||
|
||
|
||
|
||
inline val `arrow`.`ap`.`objects`.`iso`.`IsoSecondaryConstructor`.Companion.iso: arrow.optics.Iso<`arrow`.`ap`.`objects`.`iso`.`IsoSecondaryConstructor`, arrow.core.Tuple2<`kotlin`.`Int`, `kotlin`.`String`>> inline get()= arrow.optics.Iso( | ||
get = { isoSecondaryConstructor: `arrow`.`ap`.`objects`.`iso`.`IsoSecondaryConstructor` -> arrow.core.Tuple2(isoSecondaryConstructor.`fieldNumber`, isoSecondaryConstructor.`fieldString`) }, | ||
reverseGet = { tuple: arrow.core.Tuple2<`kotlin`.`Int`, `kotlin`.`String`> -> `arrow`.`ap`.`objects`.`iso`.`IsoSecondaryConstructor`(tuple.a, tuple.b) } | ||
) |
8 changes: 8 additions & 0 deletions
8
modules/meta/arrow-meta/src/test/resources/arrow/ap/objects/lens/LensSecondaryConstructor.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package `arrow`.`ap`.`objects`.`lens` | ||
|
||
|
||
|
||
inline val `arrow`.`ap`.`objects`.`lens`.`LensSecondaryConstructor`.Companion.field: arrow.optics.Lens<`arrow`.`ap`.`objects`.`lens`.`LensSecondaryConstructor`, `kotlin`.`String`> inline get()= arrow.optics.Lens( | ||
get = { lensSecondaryConstructor: `arrow`.`ap`.`objects`.`lens`.`LensSecondaryConstructor` -> lensSecondaryConstructor.`field` }, | ||
set = { lensSecondaryConstructor: `arrow`.`ap`.`objects`.`lens`.`LensSecondaryConstructor`, value: `kotlin`.`String` -> lensSecondaryConstructor.copy(`field` = value) } | ||
) |
10 changes: 10 additions & 0 deletions
10
...a/arrow-meta/src/test/resources/arrow/ap/objects/optional/OptionalSecondaryConstructor.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package `arrow`.`ap`.`objects`.`optional` | ||
|
||
import arrow.core.left | ||
import arrow.core.right | ||
import arrow.core.toOption | ||
|
||
inline val `arrow`.`ap`.`objects`.`optional`.`OptionalSecondaryConstructor`.Companion.field: arrow.optics.Optional<`arrow`.`ap`.`objects`.`optional`.`OptionalSecondaryConstructor`, `kotlin`.`String`> inline get()= arrow.optics.Optional( | ||
getOrModify = { optionalSecondaryConstructor: `arrow`.`ap`.`objects`.`optional`.`OptionalSecondaryConstructor` -> optionalSecondaryConstructor.`field`?.right() ?: optionalSecondaryConstructor.left() }, | ||
set = { optionalSecondaryConstructor: `arrow`.`ap`.`objects`.`optional`.`OptionalSecondaryConstructor`, value: `kotlin`.`String` -> optionalSecondaryConstructor.copy(`field` = value) } | ||
) |