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
| <?php | |
| if ($activityReport[$employeeId][$month] > $salesGoal) { | |
| //some code here | |
| } |
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
| <?php | |
| if ($data[$i][$j] > $x) { | |
| //some code here | |
| } |
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
| "filename.json".createFileParser() |
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
| fun String.createFileParser() = | |
| when (this.substringAfterLast('.')) { | |
| "xml" -> XmlFileParser() | |
| "json" -> JsonFileParser() | |
| else -> throw Exception("I don't know how to deal with $this.") | |
| } |
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
| infix fun FileParser.Companion.fromFile(filename: String) = | |
| this.createFromFileName(filename) |
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
| val parser = FileParser fromFile "filename.json" |
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
| fun FileParser.Companion.fromFile(filename: String) = | |
| this.createFromFileName(filename) |
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
| FileParser.createFromFile("filename.json") |
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
| interface FileParser { | |
| companion object { | |
| fun createFromFileName(fileName: String) = | |
| when (fileName.substringAfterLast('.')) { | |
| "xml" -> XmlFileParser() | |
| "json" -> JsonFileParser() | |
| else -> throw Exception("I don't know how to deal with $fileName.") | |
| } | |
| } | |
| } |
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
| //Works… | |
| ObjectFileParserFactory.createFromFileName("filename.foo") | |
| //...and this still works | |
| val fileParser = ObjectFileParserFactory | |
| fileParser.createFromFileName("filename.json") |