From 823ac48b0ed7862026ffc800cd8ae35d22bc506a Mon Sep 17 00:00:00 2001 From: Simon Ochsenreither Date: Mon, 18 Dec 2023 16:58:22 +0100 Subject: [PATCH] stdlib: add missing `Identity` blanket impl for `Option` and `Result` works on #88 --- dora/stdlib/primitives.dora | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dora/stdlib/primitives.dora b/dora/stdlib/primitives.dora index d72dd998..e96a0166 100644 --- a/dora/stdlib/primitives.dora +++ b/dora/stdlib/primitives.dora @@ -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; @@ -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() { @@ -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) }