public Map addList(List list, Func f) { modify(); if (f == null) { for (int i = 0; i < list.sz(); ++i) { add(list.get(i), list.get(i)); } } else if (f.@params().sz() == 1) { for (int i = 0; i < list.sz(); ++i) { add(f.call(list.get(i)), list.get(i)); } } else { for (int i = 0; i < list.sz(); ++i) { add(f.call(list.get(i), i), list.get(i)); } } return(this); }
public long binaryFind(Func f) { object[] values = this.m_values; int low = 0, high = m_size - 1; bool oneArg = f.arity() == 1; while (low <= high) { int probe = (low + high) >> 1; object val = values[probe]; object res = oneArg ? f.call(val) : f.call(val, Long.valueOf(probe)); long cmp = ((Long)res).longValue(); if (cmp > 0) { low = probe + 1; } else if (cmp < 0) { high = probe - 1; } else { return(probe); } } return(-(low + 1)); }
public void each(Func f) { long start = m_start; long end = m_end; if (start < end) { if (m_exclusive) { --end; } for (long i = start; i <= end; ++i) { f.call(i); } } else { if (m_exclusive) { ++end; } for (long i = start; i >= end; --i) { f.call(i); } } }
public void eachRange(Range r, Func f) { int s = r.start(m_size); int e = r.end(m_size); int n = e - s + 1; if (n < 0) { throw IndexErr.make(r).val; } if (f.arity() == 1) { for (int i = s; i <= e; ++i) { f.call(m_values[i]); } } else { for (int i = s; i <= e; ++i) { f.call(m_values[i], i); } } }
public string join(string sep, Func f) { int size = (int)this.size(); if (size == 0) { return(""); } StringBuilder s = new StringBuilder(32 + size * 32); IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; if (s.Length > 0) { s.Append(sep); } if (f == null) { s.Append(key).Append(": ").Append(val); } else { s.Append(f.call(val, key)); } } return(s.ToString()); }
public Map map(Func f) { Type r = f.returns(); if (r == Sys.VoidType) { r = Sys.ObjType.toNullable(); } Map acc = new Map(m_type.m_k, r); if (this.ordered()) { acc.ordered(true); } if (this.caseInsensitive()) { acc.caseInsensitive(true); } IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; acc.set(key, f.call(val, key)); } return(acc); }
public Map exclude(Func f) { Map acc = new Map(m_type); if (this.ordered()) { acc.ordered(true); } if (this.caseInsensitive()) { acc.caseInsensitive(true); } IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; if (f.call(val, key) == Boolean.False) { acc.set(key, val); } } return(acc); }
public void verifyErr(Type errType, Func f) { try { f.call(this); } catch (Err.Val e) { if (verbose) { System.Console.WriteLine(" verifyErr: " + e); } if (e.err().@typeof() == errType || errType == null) { verifyCount++; return; } fail(e.err().@typeof() + " thrown, expected " + errType); } catch (System.Exception e) { if (verbose) { System.Console.WriteLine(" verifyErr: " + e); } Err err = Fan.Sys.Err.make(e); if (err.@typeof() == errType || errType == null) { verifyCount++; return; } fail(e.GetType() + " thrown, expected " + errType); } fail("No err thrown, expected " + errType); }
public static void eachr(string self, Func f) { for (int i = self.Length - 1; i >= 0; --i) { f.call(self[i], i); } }
public string join(string sep, Func f) { if (m_size == 0) { return(""); } if (m_size == 1) { object v = m_values[0]; if (f != null) { return((string)f.call(v, 0)); } if (v == null) { return("null"); } return(toStr(v)); } StringBuilder s = new StringBuilder(32 + m_size * 32); for (int i = 0; i < m_size; i++) { if (i > 0) { s.Append(sep); } if (f == null) { if (m_values[i] == null) { s.Append("null"); } else { s.Append(m_values[i]); } } else { s.Append(f.call(m_values[i], i)); } } return(s.ToString()); }
public void eachr(Func f) { if (f.arity() == 1) { for (int i = m_size - 1; i >= 0; i--) { f.call(m_values[i]); } } else { for (int i = m_size - 1; i >= 0; i--) { f.call(m_values[i], i); } } }
////////////////////////////////////////////////////////////////////////// // Iterators ////////////////////////////////////////////////////////////////////////// public void each(Func f) { if (f.arity() == 1) { for (int i = 0; i < m_size; i++) { f.call(m_values[i]); } } else { for (int i = 0; i < m_size; i++) { f.call(m_values[i], i); } } }
public object reduce(object reduction, Func f) { for (int i = 0; i < m_size; i++) { reduction = f.call(reduction, m_values[i], i); } return(reduction); }
////////////////////////////////////////////////////////////////////////// // Closures ////////////////////////////////////////////////////////////////////////// public static void times(long self, Func f) { long val = self; for (long i = 0; i < val; i++) { f.call(i); } }
public static void each(string self, Func f) { int len = self.Length; for (int i = 0; i < len; i++) { f.call(self[i], i); } }
public virtual string readStrToken(Long max, Func f) { // max limit int maxChars = (max != null) ? max.intValue() : System.Int32.MaxValue; if (maxChars <= 0) { return(string.Empty); } // read first char, if at end of file bail int c = rChar(); if (c < 0) { return(null); } // loop reading chars until our closure returns false StringBuilder buf = new StringBuilder(); while (true) { // check for \n, \r\n, or \r bool terminate; if (f == null) { terminate = FanInt.isSpace(c); } else { terminate = ((Boolean)f.call(c)).booleanValue(); } if (terminate) { unreadChar(c); break; } // Append to working buffer buf.Append((char)c); if (buf.Length >= maxChars) { break; } // read next char c = rChar(); if (c < 0) { break; } } return(buf.ToString()); }
public static Deprecated make(Func func) { Deprecated self = new Deprecated(); if (func != null) { func.enterCtor(self); func.call(self); func.exitCtor(); } return self; }
public static Serializable make(Func func) { Serializable self = new Serializable(); if (func != null) { func.enterCtor(self); func.call(self); func.exitCtor(); } return self; }
public bool all(Func f) { for (int i = 0; i < m_size; i++) { if (f.call(m_values[i], i) == Boolean.False) { return(false); } } return(true); }
public object getOrAdd(object key, Func valFunc) { if (containsKey(key)) { return(get(key)); } object val = valFunc.call(key); add(key, val); return(val); }
public object find(Func f) { for (int i = 0; i < m_size; i++) { if (f.call(m_values[i], i) == Boolean.True) { return(m_values[i]); } } return(null); }
public static FacetMeta make(Func func) { FacetMeta self = new FacetMeta(); if (func != null) { func.enterCtor(self); func.call(self); func.exitCtor(); } return self; }
////////////////////////////////////////////////////////////////////////// // Iterators ////////////////////////////////////////////////////////////////////////// public void each(Func f) { IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; f.call(val, key); } }
public static FacetMeta make(Func func) { FacetMeta self = new FacetMeta(); if (func != null) { func.enterCtor(self); func.call(self); func.exitCtor(); } return(self); }
public static object with(object self, Func f) { if (self is FanObj) { return(((FanObj)self).with(f)); } else { f.call(self); return(self); } }
public static Serializable make(Func func) { Serializable self = new Serializable(); if (func != null) { func.enterCtor(self); func.call(self); func.exitCtor(); } return(self); }
public object eachrWhile(Func f) { for (int i = m_size - 1; i >= 0; i--) { object r = f.call(m_values[i], i); if (r != null) { return(r); } } return(null); }
public object reduce(object reduction, Func f) { IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; reduction = f.call(reduction, val, key); } return(reduction); }
public Long findIndex(Func f) { for (int i = 0; i < m_size; ++i) { long pos = i; if (f.call(m_values[i], pos) == Boolean.True) { return(Long.valueOf(pos)); } } return(null); }
public static Deprecated make(Func func) { Deprecated self = new Deprecated(); if (func != null) { func.enterCtor(self); func.call(self); func.exitCtor(); } return(self); }
public object eachWhile(Func f) { for (int i = 0; i < m_size; i++) { object r = f.call(m_values[i], i); if (r != null) { return(r); } } return(null); }
public List exclude(Func f) { List acc = new List(m_of, m_size); for (int i = 0; i < m_size; i++) { if (f.call(m_values[i], i) == Boolean.False) { acc.add(m_values[i]); } } return(acc); }
public static bool all(string self, Func f) { int len = self.Length; for (int i = 0; i < len; i++) { if (f.call(self[i], i) == Boolean.False) { return(false); } } return(true); }
public static void make_(ActorPool self, Func itBlock) { if (itBlock != null) { itBlock.enterCtor(self); itBlock.call(self); itBlock.exitCtor(); } if (self.m_maxThreads < 1) throw ArgErr.make("ActorPool.maxThreads must be >= 1, not " + self.m_maxThreads).val; self.m_threadPool = new ThreadPool((int)self.m_maxThreads); self.m_scheduler = new Scheduler(); }
public object reduce(object reduction, Func f) { IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; reduction = f.call(reduction, val, key); } return reduction; }
public object reduce(object reduction, Func f) { for (int i=0; i<m_size; i++) reduction = f.call(reduction, m_values[i], i); return reduction; }
public static bool any(string self, Func f) { int len = self.Length; for (int i=0; i<len ; i++) if (f.call(self[i], i) == Boolean.True) return true; return false; }
public string join(string sep, Func f) { if (m_size == 0) return ""; if (m_size == 1) { object v = m_values[0]; if (f != null) return (string)f.call(v, 0); if (v == null) return "null"; return toStr(v); } StringBuilder s = new StringBuilder(32+m_size*32); for (int i=0; i<m_size; i++) { if (i > 0) s.Append(sep); if (f == null) { if (m_values[i] == null) s.Append("null"); else s.Append(m_values[i]); } else { s.Append(f.call(m_values[i], i)); } } return s.ToString(); }
public List map(Func f) { Type r = f.returns(); if (r == Sys.VoidType) r = Sys.ObjType.toNullable(); List acc = new List(r, (int)size()); for (int i=0; i<m_size; i++) acc.add(f.call(m_values[i], i)); return acc; }
public List findAll(Func f) { List acc = new List(m_of, m_size); for (int i=0; i<m_size; i++) if (f.call(m_values[i], i) == Boolean.True) acc.add(m_values[i]); return acc; }
public Map findAll(Func f) { Map acc = new Map(m_type); if (this.ordered()) acc.ordered(true); if (this.caseInsensitive()) acc.caseInsensitive(true); IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; if (f.call(val, key) == Boolean.True) acc.set(key, val); } return acc; }
public object eachWhile(Func f) { for (int i=0; i<m_size; i++) { object r = f.call(m_values[i], i); if (r != null) return r; } return null; }
public object find(Func f) { for (int i=0; i<m_size; i++) if (f.call(m_values[i], i) == Boolean.True) return m_values[i]; return null; }
public object eachrWhile(Func f) { for (int i=m_size-1; i>=0; i--) { object r = f.call(m_values[i], i); if (r != null) return r; } return null; }
public void eachRange(Range r, Func f) { int s = r.start(m_size); int e = r.end(m_size); int n = e - s + 1; if (n < 0) throw IndexErr.make(r).val; if (f.arity() == 1) { for (int i=s; i<=e; ++i) f.call(m_values[i]); } else { for (int i=s; i<=e; ++i) f.call(m_values[i], i); } }
public bool any(Func f) { if (m_map.Count == 0) return false; IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; if (f.call(val, key) == Boolean.True) return true; } return false; }
public string join(string sep, Func f) { int size = (int)this.size(); if (size == 0) return ""; StringBuilder s = new StringBuilder(32+size*32); IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; if (s.Length > 0) s.Append(sep); if (f == null) s.Append(key).Append(": ").Append(val); else s.Append(f.call(val, key)); } return s.ToString(); }
public Long findIndex(Func f) { for (int i=0; i<m_size; ++i) { long pos = i; if (f.call(m_values[i], pos) == Boolean.True) return Long.valueOf(pos); } return null; }
public bool any(Func f) { for (int i=0; i<m_size; i++) if (f.call(m_values[i], i) == Boolean.True) return true; return false; }
public object eachWhile(Func f) { IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; object r = f.call(val, key); if (r != null) return r; } return null; }
public long binaryFind(Func f) { object[] values = this.m_values; int low = 0, high = m_size-1; bool oneArg = f.arity() == 1; while (low <= high) { int probe = (low + high) >> 1; object val = values[probe]; object res = oneArg ? f.call(val) : f.call(val, Long.valueOf(probe)); long cmp = ((Long)res).longValue(); if (cmp > 0) low = probe + 1; else if (cmp < 0) high = probe - 1; else return probe; } return -(low + 1); }
public object find(Func f) { IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; if (f.call(val, key) == Boolean.True) return val; } return null; }
////////////////////////////////////////////////////////////////////////// // Iterators ////////////////////////////////////////////////////////////////////////// public void each(Func f) { if (f.arity() == 1) { for (int i=0; i<m_size; i++) f.call(m_values[i]); } else { for (int i=0; i<m_size; i++) f.call(m_values[i], i); } }
public object getOrAdd(object key, Func valFunc) { if (containsKey(key)) return get(key); object val = valFunc.call(key); add(key, val); return val; }
public void eachr(Func f) { if (f.arity() == 1) { for (int i=m_size-1; i>=0; i--) f.call(m_values[i]); } else { for (int i=m_size-1; i>=0; i--) f.call(m_values[i], i); } }
public Map map(Func f) { Type r = f.returns(); if (r == Sys.VoidType) r = Sys.ObjType.toNullable(); Map acc = new Map(m_type.m_k, r); if (this.ordered()) acc.ordered(true); if (this.caseInsensitive()) acc.caseInsensitive(true); IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; acc.set(key, f.call(val, key)); } return acc; }
public static void each(string self, Func f) { int len = self.Length; for (int i=0; i<len ; i++) f.call(self[i], i); }
public Map setList(List list, Func f) { modify(); if (f == null) { for (int i=0; i<list.sz(); ++i) set(list.get(i), list.get(i)); } else if (f.@params().sz() == 1) { for (int i=0; i<list.sz(); ++i) set(f.call(list.get(i)), list.get(i)); } else { for (int i=0; i<list.sz(); ++i) set(f.call(list.get(i), i), list.get(i)); } return this; }
public static void eachr(string self, Func f) { for (int i=self.Length-1; i>=0; --i) f.call(self[i], i); }