From 86074a9e4c0833e35e54ba5c7d00e30cd3205437 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) }