Created
October 5, 2010 01:26
-
-
Save briantrice/610800 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define: #Particle &parents: {Mapping} &slots: {#keys -> {}. #values -> {}}. | |
p@(Particle traits) newSize: capacity | |
[ | |
p clone `>> [keys: (p keys newSize: capacity). values: (p values newSize: capacity). ] | |
]. | |
p@(Particle traits) newFrom: keys to: values | |
[ | |
p clone `>> [keys: (keys as: p keys). values: (values as: p values). ] | |
]. | |
p@(Particle traits) size [p keys size]. | |
p@(Particle traits) capacity [p size]. | |
p@(Particle traits) at: key | |
[ | |
p values at: (p keys indexOf: key ifAbsent: [^ (key keyNotFoundOn: m)]) | |
]. | |
p@(Particle traits) keyAtValue: value ifAbsent: block | |
[ | |
p keys at: (p values indexOf: value ifAbsent: [^ block do]) | |
]. | |
p@(Particle traits) isImmutable [True]. | |
p@(Particle traits) at: key put: value | |
[ | |
p error: 'immutable' | |
"p values at: (p keys indexOf: key ifAbsent: [^ Nil]) put: value" | |
]. | |
p@(Particle traits) removeKey: key ifAbsent: block | |
[ | |
p error: 'immutable' | |
"| index | | |
index: (p keys indexOf: key ifAbsent: [^ (key keyNotFoundOn: m)]). | |
p keys at: index put: Nil. | |
p values at: index put: Nil." | |
]. | |
p@(Particle traits) keysAndValuesDo: block | |
[ | |
p keys with: p values do: block | |
]. | |
p@(Particle traits) keysDo: block | |
[p keys do: block]. | |
p@(Particle traits) valuesDo: block | |
[p values do: block]. | |
p@(Particle traits) allSatisfy: block | |
[ | |
p values allSatisfy: block | |
]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment