annotate samples/hashset.tp @ 338:1458c069c715

Added "value" method to option value and option none. It behaves similarly to value:none, except the none case just propagates the none value and the value case wraps the result in an option value
author Michael Pavone <pavone@retrodev.com>
date Sat, 04 Apr 2015 11:54:46 -0700
parents cbc92ee13f35
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
80
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #{
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2 main <- {
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3 inset <- #["foo" "bar" "foobar" 1 2 3]
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 notin <- #["baz" "qux" "bazqux" 4 5 6]
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
5 myset <- sets hash
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 foreach: inset :idx el {
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
7 myset add: el
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 }
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9 foreach: inset :idx el {
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10 if: (myset contains?: el) {
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11 print: "set contains " . el . "\n"
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 } else: {
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
13 print: "set doesn't contain " . el . "\n"
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14 }
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
15 }
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16 foreach: notin :idx el {
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 if: (myset contains?: el) {
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
18 print: "set contains " . el . "\n"
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 } else: {
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
20 print: "set doesn't contain " . el . "\n"
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
21 }
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
22 }
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
23 }
cbc92ee13f35 Add hash set
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24 }