Skip to content

Commit

Permalink
stdlib: add missing Identity blanket impl for Option and Result
Browse files Browse the repository at this point in the history
works on #88
  • Loading branch information
soc committed Dec 27, 2023
1 parent 593e35a commit 86074a9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion dora/stdlib/primitives.dora
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std.traits.{Default, Equals, Hash, Iterator, Zero};
use std.traits.{Default, Equals, Hash, Identity, Iterator, Zero};
use std.string.Stringable;
use std.fatalError;

Expand Down Expand Up @@ -510,6 +510,10 @@ impl[T] Option[Option[T]] {
... is None { None[T] };
}

impl[T: Identity] Identity for Option[T] {
@pub fun identicalTo(rhs: Option[T]): Bool = self === rhs;
}

impl[T: Equals] Equals for Option[T] {
@pub fun equals(rhs: Option[T]): Bool {
if self.isSome() {
Expand Down Expand Up @@ -626,6 +630,10 @@ impl[T, E] Result[T, E] {
... is Err(_) { None[T] };
}

impl[T: Identity, E] Identity for Result[T, E] {
@pub fun identicalTo(rhs: Result[T, E]): Bool = self === rhs;
}

impl[T: Equals, E] Result[T, E] {
@pub fun contains(rhs: T): Bool = if self
... is Ok(val) { val.equals(rhs) }
Expand Down

0 comments on commit 86074a9

Please sign in to comment.