Created
January 27, 2018 12:04
-
-
Save andrzejressel/f302bc67e11072b5fe2fbab77c244e49 to your computer and use it in GitHub Desktop.
[at]optics
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
/** | |
* Java, because kotlin doesn't allow fields for annotations | |
*/ | |
public @interface optics { | |
Type[] value() default {}; | |
public enum Type { | |
ISO, //data class | |
LENS, //data class | |
OPTIONAL, //data class | |
PRISM //sealed class | |
} | |
} |
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
//Generates prism | |
@optics sealed class NetworkResult { | |
data class Success(val content: String) : NetworkResult() | |
object Failure : NetworkResult() | |
} | |
//Error: Optional is not valid for sealed class | |
@optics(OPTIONAL) sealed class NetworkResult2 { | |
data class Success(val content: String) : NetworkResult2() | |
object Failure : NetworkResult2() | |
} | |
//Generates iso, lens and optional | |
@optics | |
data class Company(val name: String) | |
//Generates only iso | |
@optics(ISO) | |
data class Company2(val name: String) | |
//Error: Prism is not valid for data class | |
@optics(PRISM) | |
data class Company3(val name: String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment