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
val password = Password.of("Some34Really434Hard21Password!").orThrow() //Throw on violation just for demonstration | |
val haha = password.copy(value = "gotcha") |
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
data class Password private constructor(val value: String) { | |
companion object { | |
fun of(value: String): Either<List<Violation>, Password> { | |
val violations = buildList { | |
if (value.isTooShort()) { add(Violation.PasswordTooShort(MIN_LENGTH)) } | |
if (value.containsNoNumbers()) { add(Violation.PasswordContainsNoNumbers) } | |
} | |
return if (violations.isEmpty()) Password(value).right() else violations.left() | |
} | |
} |
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
data class Password private constructor(val value: String) { | |
companion object { | |
fun of(value: String): Password { | |
return when { | |
value.isTooShort() -> throw PasswordTooShortException() | |
value.containsNoNumbers() -> throw PasswordContainsNoNumbersException() | |
else -> Password(value) | |
} | |
} | |
} |
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
data class Password private constructor(val value: String) { | |
companion object { | |
fun of(value: String): Either<Violation, Password> { | |
return when { | |
value.isTooShort() -> Violation.PasswordTooShort(MIN_LENGTH).left() | |
value.containsNoNumbers() -> Violation.PasswordContainsNoNumbers.left() | |
else -> Password(value).right() | |
} | |
} | |
} |
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
data class Password private constructor(val value: String) { | |
companion object { | |
fun of(value: String): Password? { | |
return if (value.isAGoodPassword()) Password(value) else null | |
} | |
} | |
} |
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
from Stack import Stack | |
def is_operand(token): | |
""" | |
checks if token consists completely of digits or letters | |
:return: true if token is either all digit or all letters (case insensitive), false otherwise | |
""" | |
return token.isalpha() or token.isdigit() |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<module classpath="CMake" type="CPP_MODULE" version="4" /> |
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
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
int factorial(int n) { | |
int fact = 1; | |
for (int i = 1; i <= n; ++i) |
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
def bubble_sort(tuples): | |
for iteration in range(len(tuples) - 1, 0, -1): | |
for i in range(iteration): | |
if tuples[i][1] > tuples[i + 1][1]: | |
temp = tuples[i] | |
tuples[i] = tuples[i + 1] | |
tuples[i + 1] = temp | |
return tuples |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<module classpath="CMake" type="CPP_MODULE" version="4" /> |