diff options
author | Marvin Borner | 2024-10-27 18:45:21 +0100 |
---|---|---|
committer | Marvin Borner | 2024-10-27 18:45:21 +0100 |
commit | fe1fe57f358472561041cde12a48d28b8bd247a9 (patch) | |
tree | 53162ad90b27ff93ba8abe17c08c1a92d7b6faf1 /std/Set/Number.bruijn | |
parent | c6e39268be197a4eaccc0187271764a646017715 (diff) |
Improvements in maps, sets, and parsing
Diffstat (limited to 'std/Set/Number.bruijn')
-rw-r--r-- | std/Set/Number.bruijn | 22 |
1 files changed, 22 insertions, 0 deletions
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]]) |