From fe1fe57f358472561041cde12a48d28b8bd247a9 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 27 Oct 2024 18:45:21 +0100 Subject: Improvements in maps, sets, and parsing --- std/Set/Number.bruijn | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 std/Set/Number.bruijn (limited to 'std/Set/Number.bruijn') diff --git a/std/Set/Number.bruijn b/std/Set/Number.bruijn new file mode 100644 index 0000000..220e2dc --- /dev/null +++ b/std/Set/Number.bruijn @@ -0,0 +1,22 @@ +# MIT License, Copyright (c) 2024 Marvin Borner + +:input std/Set + +:import std/Number T + +# adds a number of a set +add T.add ⧗ Number → NumberSet → NumberSet + +# returns true if a number is in a set +has? T.has? ⧗ Number → NumberSet → Boolean + +:test (has? (+5) (add (+5) empty)) ([[1]]) +:test (has? (+5) empty) ([[0]]) + +# converts a list to a set +list→set T.list→set ⧗ (List Number) → NumberSet + +:test (has? (+0) (list→set ((+5) : ((+3) : ((+2) : ((+1) : {}(+0))))))) ([[1]]) +:test (has? (+5) (list→set ((+5) : ((+3) : ((+2) : ((+1) : {}(+0))))))) ([[1]]) +:test (has? (+6) (list→set ((+5) : ((+3) : ((+2) : ((+1) : {}(+0))))))) ([[0]]) +:test (has? (+7) (list→set ((+5) : ((+7) : {}(+1))))) ([[1]]) -- cgit v1.2.3