public static Value Group(INSGenerator generator, Arguments arguments) { var count = arguments[0].Int; if (count > 0) { var iterator = new NSIterator(generator); var array = new Array(); iterator.Reset(); var value = iterator.Next(); for (var i = 0; i < MAX_ARRAY && !value.IsNil; i += count) { var subArray = new Array(); for (var j = 0; j < count && !value.IsNil; j++) { subArray.Add(value); value = iterator.Next(); } array.Add(value); value = iterator.Next(); } return(array); } using (var assistant = new ParameterAssistant(arguments)) { var block = assistant.Block(); if (block == null) { return(ToArray(generator)); } var hash = new AutoHash <string, List <Value> > { Default = DefaultType.Lambda, DefaultLambda = k => new List <Value>(), AutoAddDefault = true }; assistant.IteratorParameter(); var iterator = new NSIterator(generator); iterator.Reset(); foreach (var item in iterator) { assistant.SetIteratorParameter(item); var key = block.Evaluate().Text; hash[key].Add(item); } var array = new Array(); foreach (var item in hash) { array[item.Key] = new Array(item.Value); } return(array); } }
public static Value First(INSGenerator generator, Arguments arguments) { var iterator = new NSIterator(generator); iterator.Reset(); var next = iterator.Next(); return(next.IsNil ? new None() : new Some(next)); }
public void Reset() { index = 0; var value = generatorSource.Evaluate().PossibleGenerator(); var innerValue = value.Must().HaveValue().Force("Inner comprehension", () => "Source must be a generator"); iterator = new NSIterator(innerValue); iterator.Reset(); more = true; }
public void Reset() { index = 0; var value = generatorSource.Evaluate().PossibleGenerator(); Assert(value.IsSome, "Inner comprehension", "Source must be a generator"); iterator = new NSIterator(value.Value); iterator.Reset(); more = true; }
public static Value FoldL(INSGenerator generator, Arguments arguments) { var iterator = new NSIterator(generator); using var assistant = new ParameterAssistant(arguments); var block = assistant.Block(); if (block == null) { return(NilValue); } iterator.Reset(); assistant.TwoValueParameters(); var initialFromArguments = arguments[0]; var initialValue = initialFromArguments.IsEmpty ? iterator.Next() : initialFromArguments; if (initialValue.IsNil) { return(initialValue); } var secondValue = iterator.Next(); if (secondValue.IsNil) { return(initialValue); } assistant.SetParameterValues(initialValue, secondValue); var value = block.Evaluate(); var signal = Signal(); if (signal == Breaking) { return(value); } switch (signal) { case ReturningNull: return(null); case Continuing: return(value); } var next = iterator.Next(); if (next.IsNil) { return(value); } for (var i = 0; i < MAX_LOOP; i++) { assistant.SetParameterValues(value, next); value = block.Evaluate(); signal = Signal(); if (signal == Breaking) { break; } switch (signal) { case ReturningNull: return(null); case Continuing: continue; } next = iterator.Next(); if (next.IsNil) { return(value); } } return(value); }