diff options
author | Rich Hickey <richhickey@gmail.com> | 2006-10-09 18:49:42 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2006-10-09 18:49:42 +0000 |
commit | 5019080db104c1857d36948871901b4803b3e4b6 (patch) | |
tree | 3cca0985fef3acf7827f1324bb0ac775b201b150 /src/cli/runtime | |
parent | bb50ab5256b62f29b48a03faca6bfaa116aff2ea (diff) |
added keys,vals seqs
Diffstat (limited to 'src/cli/runtime')
-rw-r--r-- | src/cli/runtime/APersistentMap.cs | 43 | ||||
-rw-r--r-- | src/cli/runtime/RT.cs | 10 |
2 files changed, 53 insertions, 0 deletions
diff --git a/src/cli/runtime/APersistentMap.cs b/src/cli/runtime/APersistentMap.cs index e107e857..e96cdad0 100644 --- a/src/cli/runtime/APersistentMap.cs +++ b/src/cli/runtime/APersistentMap.cs @@ -67,6 +67,49 @@ override public int GetHashCode() { abstract public IPersistentMap without(object key);
+ public class KeySeq : ASeq{
+ ISeq _seq;
+
+ static public KeySeq create(ISeq seq){
+ if(seq == null)
+ return null;
+ return new KeySeq(seq);
+ }
+
+ private KeySeq(ISeq seq) {
+ this._seq = seq;
+ }
+
+ public override Object first() {
+ return ((IMapEntry)_seq.first()).key();
+ }
+
+ public override ISeq rest() {
+ return create(_seq.rest());
+ }
+}
+
+public class ValSeq : ASeq{
+ ISeq _seq;
+
+ static public ValSeq create(ISeq seq){
+ if(seq == null)
+ return null;
+ return new ValSeq(seq);
+ }
+
+ private ValSeq(ISeq seq) {
+ this._seq = seq;
+ }
+
+ public override Object first() {
+ return ((IMapEntry)_seq.first()).val();
+ }
+
+ public override ISeq rest() {
+ return create(_seq.rest());
+ }
+}
#endregion
diff --git a/src/cli/runtime/RT.cs b/src/cli/runtime/RT.cs index ef30e8f2..059bdad6 100644 --- a/src/cli/runtime/RT.cs +++ b/src/cli/runtime/RT.cs @@ -105,6 +105,16 @@ static public ISeq seq(Object coll) { throw new ArgumentException("Don't know how to create ISeq from arg");
}
+static public ISeq keys(Object coll)
+ {
+ return APersistentMap.KeySeq.create(seq(coll));
+ }
+
+static public ISeq vals(Object coll)
+ {
+ return APersistentMap.ValSeq.create(seq(coll));
+ }
+
static public Object meta(Object x)
{
if (x == null)
|