From c6e39268be197a4eaccc0187271764a646017715 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 27 Oct 2024 01:00:38 +0200 Subject: Refactored comparisons and sets --- std/Set/StringSet.bruijn | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 std/Set/StringSet.bruijn (limited to 'std/Set/StringSet.bruijn') diff --git a/std/Set/StringSet.bruijn b/std/Set/StringSet.bruijn new file mode 100644 index 0000000..4bee345 --- /dev/null +++ b/std/Set/StringSet.bruijn @@ -0,0 +1,23 @@ +# MIT License, Copyright (c) 2024 Marvin Borner +# TODO: hash instead of comparing + +:input std/Set + +:import std/String S + +# adds a number of a set +add S.add ⧗ String → StringSet → StringSet + +# returns true if a number is in a set +has? S.has? ⧗ String → StringSet → Boolean + +:test (has? "abc" (add "abc" empty)) ([[1]]) +:test (has? "abc" empty) ([[0]]) + +# converts a list to a set +list→set S.list→set ⧗ (List String) → StringSet + +:test (has? "0" (list→set ("a" : ("b" : ("d" : ("c" : {}"0")))))) ([[1]]) +:test (has? "a" (list→set ("a" : ("b" : ("d" : ("c" : {}"0")))))) ([[1]]) +:test (has? "e" (list→set ("a" : ("b" : ("d" : ("c" : {}"0")))))) ([[0]]) +:test (has? "c" (list→set ("a" : ("c" : {}"b")))) ([[1]]) -- cgit v1.2.3