Last active
November 7, 2022 15:32
-
-
Save naixx/9d94c1498c4d45ffda3a to your computer and use it in GitHub Desktop.
Revisions
-
naixx revised this gist
Jan 16, 2018 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ class Ternary<T>(private val expr: Boolean, private val then: T) { infix operator fun div(elze: T): T = if (expr) then else elze } infix operator fun <T> Boolean.rem(a: T): Ternary<T> = Ternary(this, a) -
naixx revised this gist
Oct 27, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ Kotlin is very expressive language, but like Scala it lacks of ternary operator. ```kotlin val result = if (myExpression) 1 else 2 ``` Compared to a classical Java or C++ variant ```java int result = myExpression ? 1 : 2 ``` -
naixx revised this gist
Oct 27, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ Kotlin is very expressive language, but like Scala it lacks of ternary operator. ```kotlin val result = if (myExpression) 1 else 2 ``` Compared to classical Java or C++ ```java int result = myExpression ? 1 : 2 ``` -
naixx revised this gist
Nov 28, 2014 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,4 +12,9 @@ Unlike Scala, Kotlin allows only fixed names for operators, so we cant fully rep ```kotlin val result = myExpression % 1 / 2 ``` If you want to use complex boolean expression, you can wrap it in braces ```kotlin val result = (a == null && b > 5) % 1 / 2 ``` The impcat I see here is temporaty object creation, probably `inline` can't help. -
naixx revised this gist
Nov 27, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,3 +12,4 @@ Unlike Scala, Kotlin allows only fixed names for operators, so we cant fully rep ```kotlin val result = myExpression % 1 / 2 ``` The impcat I see here is temporaty object creation, probably `inline` can't help. -
naixx revised this gist
Nov 27, 2014 . 2 changed files with 5 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ class Ternary<T>(val expr: Boolean, val then: T) { public fun div(elze: T): T = if (expr) then else elze } public fun <T> Boolean.mod(a: T): Ternary<T> = Ternary(this, a) -
naixx revised this gist
Nov 27, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Motivation Kotlin is very expressive language, but like Scala it lacks of ternary operator. Currently language provided alternative `if` looks a bit verbose. ```kotlin -
naixx revised this gist
Nov 27, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,6 @@ Copared to classical Java or C++ int result = myExpression ? 1 : 2 ``` Unlike Scala, Kotlin allows only fixed names for operators, so we cant fully reproduce classic syntax, but we can have something similar ```kotlin val result = myExpression % 1 / 2 ``` -
naixx created this gist
Nov 27, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ * Motivation * Kotlin is very expressive language, but like Scala it lacks of ternary operator. Currently language provided alternative `if` looks a bit verbose. ```kotlin val result = if (myExpression) 1 else 2 ``` Copared to classical Java or C++ ```java int result = myExpression ? 1 : 2 ``` Unlike Scala, Kotlin allows only fixed names for operators, so we cant fully reproduce classic syntax, but we can have something similar '''kotlin val result = myExpression % 1 / 2 ``` 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ class Elvis<T>(val expr: Boolean, val then: T) { public fun div(elze: T): T = if (expr) then else elze } public fun <T> Boolean.mod(a: T): Elvis<T> = Elvis(this, a)