Skip to content

Instantly share code, notes, and snippets.

@le0nidas
Created February 14, 2021 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save le0nidas/9f802e631a63a410be6c9ad602d28067 to your computer and use it in GitHub Desktop.
Save le0nidas/9f802e631a63a410be6c9ad602d28067 to your computer and use it in GitHub Desktop.
// somewhere in the code
task.closeIfUnclaimed(createdBefore = LocalDate.of(2021, 1, 14))
// task's better API
class Task(
initialStatus: Status,
private val createdAt: LocalDate
) {
var status: Status = initialStatus
private set
private val subscribers = mutableListOf<Subscriber>()
fun add(subscriber: Subscriber) {
subscribers.add(subscriber)
}
fun closeIfUnclaimed(createdBefore: LocalDate): Boolean {
if (status == Status.NotStarted && createdAt < createdBefore && subscribers.isEmpty()) {
status = Resolved
return true
}
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment