Skip to content

Commit

Permalink
Merge pull request #1015 from tom-anders/asSquareOr
Browse files Browse the repository at this point in the history
[Study] feat: add asSquareOrThrow() and asSquareOrNull() extensions
  • Loading branch information
veloce authored Sep 12, 2024
2 parents 7e48b15 + 82c6222 commit 4b1d624
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/src/model/common/chess.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,19 @@ extension ChessExtension on Pick {
}
}

Square asSquareOrThrow() {
return Square.parse(this.required().value as String)!;
}

Square? asSquareOrNull() {
if (value == null) return null;
try {
return asSquareOrThrow();
} catch (_) {
return null;
}
}

Variant asVariantOrThrow() {
final value = this.required().value;
if (value is Variant) {
Expand Down

0 comments on commit 4b1d624

Please sign in to comment.