summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorEric N. Vander Weele <ericvw@gmail.com>2023-12-24 09:21:22 -0500
committerGitHub <noreply@github.com>2023-12-24 15:21:22 +0100
commit6fee2240cd327fbe65548eaed9ca21355a1a24b5 (patch)
tree72f4f817be1e70030f370350bc1a3af85ce2e70a /lib
parentc0acf3ce286f92d41e6b280ba9a1b729019bae12 (diff)
downloadNim-6fee2240cd327fbe65548eaed9ca21355a1a24b5.tar.gz
Add `toSinglyLinkedRing` and `toDoublyLinkedRing` to `std/lists` (#22952)
Allow for conversion from `openArray`s, similar to `toSinglyLinkedList`
and `toDoublyLinkedList`.
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/collections/lists.nim22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/pure/collections/lists.nim b/lib/pure/collections/lists.nim
index b9d5c48eb..9b89fe9f8 100644
--- a/lib/pure/collections/lists.nim
+++ b/lib/pure/collections/lists.nim
@@ -983,6 +983,17 @@ func toSinglyLinkedList*[T](elems: openArray[T]): SinglyLinkedList[T] {.since: (
   for elem in elems.items:
     result.add(elem)
 
+func toSinglyLinkedRing*[T](elems: openArray[T]): SinglyLinkedRing[T] =
+  ## Creates a new `SinglyLinkedRing` from the members of `elems`.
+  runnableExamples:
+    from std/sequtils import toSeq
+    let a = [1, 2, 3, 4, 5].toSinglyLinkedRing
+    assert a.toSeq == [1, 2, 3, 4, 5]
+
+  result = initSinglyLinkedRing[T]()
+  for elem in elems.items:
+    result.add(elem)
+
 func toDoublyLinkedList*[T](elems: openArray[T]): DoublyLinkedList[T] {.since: (1, 5, 1).} =
   ## Creates a new `DoublyLinkedList` from the members of `elems`.
   runnableExamples:
@@ -993,3 +1004,14 @@ func toDoublyLinkedList*[T](elems: openArray[T]): DoublyLinkedList[T] {.since: (
   result = initDoublyLinkedList[T]()
   for elem in elems.items:
     result.add(elem)
+
+func toDoublyLinkedRing*[T](elems: openArray[T]): DoublyLinkedRing[T] =
+  ## Creates a new `DoublyLinkedRing` from the members of `elems`.
+  runnableExamples:
+    from std/sequtils import toSeq
+    let a = [1, 2, 3, 4, 5].toDoublyLinkedRing
+    assert a.toSeq == [1, 2, 3, 4, 5]
+
+  result = initDoublyLinkedRing[T]()
+  for elem in elems.items:
+    result.add(elem)