aboutsummaryrefslogtreecommitdiffhomepage
path: root/std/Set/NumberSet.bruijn
blob: 220e2dcec80b48f92ac89621018d564f57866998 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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]])