Exemplo n.º 1
0
 internal static __NopeList iterator_to_list(dynamic iterator)
 {
     var sentinel = new object();
     var result = new __NopeList();
     dynamic element;
     while ((element = Builtins.next(iterator, sentinel)) != sentinel)
     {
         result.append(element);
     }
     return result;
 }
Exemplo n.º 2
0
    public dynamic __getitem__(dynamic key)
    {
        if (key is __Nope.Builtins.Slice)
        {
            // TODO: exception on step of 0
            // TODO: implement this in nope
            var result = new __NopeList();
            var step = System.Object.ReferenceEquals(key.step, __NopeNone.Value)
                ? 1 : key.step.__Value;

            if (step < 0)
            {
                var start = System.Object.ReferenceEquals(key.start, __NopeNone.Value)
                    ? _values.Count - 1
                    : key.start.__Value;
                var stop = System.Object.ReferenceEquals(key.stop, __NopeNone.Value)
                    ? -1 : key.stop.__Value;

                for (var i = start; i > stop; i += step) {
                    result.append(_values[i]);
                }
            }
            else
            {
                var start = System.Object.ReferenceEquals(key.start, __NopeNone.Value)
                    ? 0 : key.start.__Value;
                var stop = System.Object.ReferenceEquals(key.stop, __NopeNone.Value)
                    ? _values.Count : key.stop.__Value;

                for (var i = start; i < stop; i += step) {
                    result.append(_values[i]);
                }
            }
            return result;
        }
        else
        {
            var index = key.__Value;
            return index < 0 ? _values[_values.Count + index] : _values[index];
        }
    }