From 7b244d43c7c52dfab7fef2d77073705aeac604cc Mon Sep 17 00:00:00 2001 From: Rich Hickey Date: Fri, 9 Jun 2006 13:24:23 +0000 Subject: made ISequential --- src/cli/runtime/PersistentArray.cs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/cli/runtime') diff --git a/src/cli/runtime/PersistentArray.cs b/src/cli/runtime/PersistentArray.cs index f9684901..71002269 100644 --- a/src/cli/runtime/PersistentArray.cs +++ b/src/cli/runtime/PersistentArray.cs @@ -44,7 +44,7 @@ namespace org.clojure.runtime * Java implementation is lock-free */ -public class PersistentArray : IEnumerable{ +public class PersistentArray : IEnumerable, ISequential{ #region IEnumerable Members @@ -54,7 +54,14 @@ public class PersistentArray : IEnumerable{ } #endregion - + + public ISeq seq() + { + if (length() > 0) + return new Seq(this, 0); + return null; + } + internal class Master{ internal readonly Entry[] array; internal readonly Object defaultVal; @@ -111,6 +118,26 @@ internal class EntryLink : Entry } } +internal class Seq : ISeq{ + PersistentArray p; + int i; + + internal Seq(PersistentArray p, int i){ + this.p = p; + this.i = i; + } + + public Object first() { + return p.get(i); + } + + public ISeq rest() { + if(i+1 < p.length()) + return new Seq(p, i + 1); + return null; + } +} + internal class ValIter : IEnumerator { internal PersistentArray p; -- cgit v1.2.3-70-g09d2