本文整理汇总了C#中IFn.invoke方法的典型用法代码示例。如果您正苦于以下问题:C# IFn.invoke方法的具体用法?C# IFn.invoke怎么用?C# IFn.invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFn
的用法示例。
在下文中一共展示了IFn.invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: reduce
public object reduce(IFn f, object start)
{
object ret = f.invoke(start, _array[_off]);
for (int x = _off + 1; x < _end; x++)
ret = f.invoke(ret, _array[x]);
return ret;
}
示例2: reduce
public object reduce(IFn f, object start)
{
object ret = f.invoke(start, _array[_off]);
if (RT.isReduced(ret))
return ret;
for (int x = _off + 1; x < _end; x++)
{
ret = f.invoke(ret, _array[x]);
if (RT.isReduced(ret))
return ((IDeref)ret).deref();
}
return ret;
}
示例3: swap
public object swap(IFn f)
{
for (; ; )
{
object v = deref();
object newv = f.invoke(v);
Validate(newv);
if (_state.CompareAndSet(v, newv))
{
NotifyWatches(v,newv);
return newv;
}
}
}
示例4: reduce
public object reduce(IFn f)
{
Object init;
if (_cnt > 0)
init = ArrayFor(0)[0];
else
return f.invoke();
int step = 0;
for (int i = 0; i < _cnt; i += step)
{
Object[] array = ArrayFor(i);
for (int j = (i == 0) ? 1 : 0; j < array.Length; ++j)
{
init = f.invoke(init, array[j]);
if (RT.isReduced(init))
return ((IDeref)init).deref();
}
step = array.Length;
}
return init;
}
示例5: KvReduce
public static object KvReduce(object[] array, IFn f, object init)
{
for (int i = 0; i < array.Length; i += 2)
{
if (array[i] != null)
init = f.invoke(init, array[i], array[i + 1]);
else
{
INode node = (INode)array[i + 1];
if (node != null)
init = node.KVReduce(f, init);
}
if (RT.isReduced(init))
return ((IDeref)init).deref();
}
return init;
}
示例6: Validate
/// <summary>
/// Invoke an <see cref="IFn">IFn</see> on a value to validate it.
/// </summary>
/// <param name="vf">The <see cref="IFn">IFn</see> to invoke.</param>
/// <param name="val">The value to validate.</param>
/// <remarks>Uneventful return marks a successful validation.
/// To indicate a failed validation, the validation function should return <value>false</value> or throw an exception.
/// <para>This appears in multiple places. Should find it a common home?</para></remarks>
protected internal static void Validate(IFn vf, object val)
{
if (vf == null)
return;
bool ret = false;
try
{
ret = RT.booleanCast(vf.invoke(val));
}
catch (Exception e)
{
throw new InvalidOperationException("Invalid reference state", e);
}
if ( ! ret )
throw new InvalidOperationException("Invalid reference state");
}
示例7: reduce
public object reduce(IFn rf)
{
Object ff = first();
Object ret = ff;
Object v = _f.invoke(ff);
while (true)
{
ret = rf.invoke(ret, v);
if (RT.isReduced(ret))
return ((IDeref)ret).deref();
v = _f.invoke(v);
}
}
示例8: reduce
/// <summary>
/// Reduce the collection using a function.
/// </summary>
/// <param name="f">The function to apply.</param>
/// <param name="start">An initial value to get started.</param>
/// <returns>The reduced value</returns>
public object reduce(IFn f, object start)
{
object ret = f.invoke(start, first());
for (ISeq s = next(); s != null; s = s.next())
ret = f.invoke(ret, s.first());
return ret;
}
示例9: reduce
/// <summary>
/// Reduce the collection using a function.
/// </summary>
/// <param name="f">The function to apply.</param>
/// <param name="start">An initial value to get started.</param>
/// <returns>The reduced value</returns>
public object reduce(IFn f, object start)
{
object ret = start;
for (int x = _i; x >= 0; x--)
ret = f.invoke(ret, _v.nth(x));
return ret;
}
示例10: swap
/// <summary>
/// Compute and set a new value. Spin loop for coordination.
/// </summary>
/// <param name="f">The function to apply to current state and additional arguments.</param>
/// <param name="arg1">First additional argument.</param>
/// <param name="arg2">Second additional argument.</param>
/// <returns>The new value.</returns>
/// <remarks>Lowercase name for core.clj compatability.</remarks>
public object swap(IFn f, Object arg1, Object arg2)
{
for (; ; )
{
object v = deref();
object newv = f.invoke(v, arg1, arg2);
Validate(newv);
if (_state.CompareAndSet(v, newv))
{
if (v != newv)
notifyWatches();
return newv;
}
}
}
示例11: runInTransaction
public static object runInTransaction(IFn fn)
{
// TODO: This can be called on something more general than an IFn.
// We can could define a delegate for this, probably use ThreadStartDelegate.
// Should still have a version that takes IFn.
LockingTransaction t = _transaction;
if (t == null)
_transaction = t = new LockingTransaction();
if (t._info != null)
return fn.invoke();
return t.Run(fn);
}
示例12: fold
public object fold(long n, IFn combinef, IFn reducef, IFn fjinvoke, IFn fjtask, IFn fjfork, IFn fjjoin)
{
// JVM: we are ignoring n for now
Func<object> top = new Func<object>(() =>
{
object ret = combinef.invoke();
if (_root != null)
ret = combinef.invoke(ret, _root.Fold(combinef, reducef, fjtask, fjfork, fjjoin));
return _hasNull
? combinef.invoke(ret, reducef.invoke(combinef.invoke(), null, _nullValue))
: ret;
});
return fjinvoke.invoke(top);
}
示例13: FoldTasks
static object FoldTasks(List<Func<object>> tasks, IFn combinef, IFn fjtask, IFn fjfork, IFn fjjoin)
{
if (tasks.Count == 0)
return combinef.invoke();
if (tasks.Count == 1 )
return tasks[0].Invoke();
int half = tasks.Count / 2;
List<Func<object>> t1 = tasks.GetRange(0, half);
List<Func<object>> t2 = tasks.GetRange(half, tasks.Count - half);
object forked = fjfork.invoke(fjtask.invoke(new Func<object>(() => { return FoldTasks(t2, combinef, fjtask, fjfork, fjjoin); })));
return combinef.invoke(FoldTasks(t1, combinef, fjtask, fjfork, fjjoin), fjjoin.invoke(forked));
}
示例14: Fold
public object Fold(IFn combinef, IFn reducef, IFn fjtask, IFn fjfork, IFn fjjoin)
{
return NodeSeq.KvReduce(_array, reducef, combinef.invoke());
}
示例15: reduce
public object reduce(IFn f)
{
ISeq s = Current();
Object ret = s.first();
while (true)
{
s = s.next();
if (s == null)
s = _all;
ret = f.invoke(ret, s.first());
if (RT.isReduced(ret))
return ((IDeref)ret).deref();
}
}