Std

Mainly a port of Rust's std.
git clone https://git.philomathiclife.com/repos/Std
Log | Files | Refs | README

Rev.cs (2778B)


      1 using Std.Convert;
      2 using Std.Maybe;
      3 using Std.Ops;
      4 using Std.Result;
      5 using System;
      6 using System.Runtime.InteropServices;
      7 #region Namespaces
      8 namespace Std.Iter {
      9     #region Types
     10     [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 0)]
     11     public struct Rev<T, TIter>: IDoubleEndedIterator<T>, IInto<Rev<T, TIter>> where T: notnull where TIter: notnull, IDoubleEndedIterator<T> {
     12 
     13         #region Type-level Constructors
     14         #endregion
     15 
     16         #region Instance Constructors
     17         public Rev() => throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");
     18         internal Rev(TIter iter) => _iter = iter;
     19         #endregion
     20 
     21         #region Type-level Fields
     22         #endregion
     23 
     24         #region Instance Fields
     25         [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Can't be readonly since we call mutable methods on it.")]
     26         TIter _iter;
     27         #endregion
     28 
     29         #region Type-level Properties
     30         #endregion
     31 
     32         #region Instance Properties
     33         #endregion
     34 
     35         #region Type-level Functions
     36         #endregion
     37 
     38         #region Instance Functions
     39         public Result<Unit, ulong> AdvanceBackBy(ulong n) => _iter.AdvanceBy(n);
     40         public Result<Unit, ulong> AdvanceBy(ulong n) => _iter.AdvanceBackBy(n);
     41         public ulong Count() => IIterator<T>.CountDefault(ref this);
     42         public TInit Fold<TInit>(TInit init, Fn<TInit, T, TInit> f) where TInit: notnull => _iter.RFold(init, f);
     43         public override readonly bool Equals(object? _) => false;
     44         public override readonly int GetHashCode() => 0;
     45         public readonly Rev<T, TIter> Into() => this;
     46         public Maybe<T> Last() => IIterator<T>.LastDefault(ref this);
     47         public Maybe<T> Next() => _iter.NextBack();
     48         public Maybe<T> NextBack() => _iter.Next();
     49         public TInit RFold<TInit>(TInit init, Fn<TInit, T, TInit> f) where TInit: notnull => _iter.Fold(init, f);
     50         public Prod<ulong, Maybe<ulong>> SizeHint() => _iter.SizeHint();
     51         public override readonly string ToString() => string.Empty;
     52         public Result<TInit, TErr> TryFold<TInit, TErr>(TInit init, Fn<TInit, T, Result<TInit, TErr>> f) where TInit: notnull where TErr: notnull => _iter.TryRFold(init, f);
     53         readonly Result<Rev<T, TIter>, Bottom> ITryInto<Rev<T, TIter>, Bottom>.TryInto() => new(this);
     54         public Result<TInit, TErr> TryRFold<TInit, TErr>(TInit init, Fn<TInit, T, Result<TInit, TErr>> f) where TInit: notnull where TErr: notnull => _iter.TryFold(init, f);
     55         #endregion
     56 
     57         #region Operators
     58         #endregion
     59 
     60         #region Types
     61         #endregion
     62     }
     63     #endregion
     64 
     65     #region Namespaces
     66     #endregion
     67 }
     68 #endregion