Std

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

Repeat.cs (3224B)


      1 using Std.Clone;
      2 using Std.Convert;
      3 using Std.Maybe;
      4 using Std.Ops;
      5 using Std.Result;
      6 using System;
      7 using System.Runtime.InteropServices;
      8 #region Namespaces
      9 namespace Std.Iter {
     10     #region Types
     11     [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 0)]
     12     public struct Repeat<T>: IClone<Repeat<T>>, IDoubleEndedIterator<T>, IFusedIterator<T>, IInto<Repeat<T>> where T: notnull, IClone<T> {
     13 
     14         #region Type-level Constructors
     15         #endregion
     16 
     17         #region Instance Constructors
     18         public Repeat() => throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");
     19         internal Repeat(T val) => _val = val;
     20         #endregion
     21 
     22         #region Type-level Fields
     23         #endregion
     24 
     25         #region Instance Fields
     26         [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Since we do not know if T is a non-readonly struct, we do not make it readonly here. Recall there is a performance hit if one calls a member of a readonly field of non-readonly struct type since the compiler must make a copy each time.")]
     27         T _val;
     28         #endregion
     29 
     30         #region Type-level Properties
     31         #endregion
     32 
     33         #region Instance Properties
     34         #endregion
     35 
     36         #region Type-level Functions
     37         #endregion
     38 
     39         #region Instance Functions
     40         public Result<Unit, ulong> AdvanceBackBy(ulong n) => IDoubleEndedIterator<T>.AdvanceBackByDefault(ref this, n);
     41         public Result<Unit, ulong> AdvanceBy(ulong n) => IIterator<T>.AdvanceByDefault(ref this, n);
     42         public Repeat<T> Clone() => new(_val.Clone());
     43         public ulong Count() => IIterator<T>.CountDefault(ref this);
     44         public override readonly bool Equals(object? _) => false;
     45         public TInit Fold<TInit>(TInit init, Fn<TInit, T, TInit> f) where TInit: notnull => IIterator<T>.FoldDefault(ref this, init, f);
     46         public override readonly int GetHashCode() => 0;
     47         public readonly Repeat<T> Into() => this;
     48         public Maybe<T> Last() => IIterator<T>.LastDefault(ref this);
     49         public Maybe<T> Next() => new(_val.Clone());
     50         public Maybe<T> NextBack() => new(_val.Clone());
     51         public TInit RFold<TInit>(TInit init, Fn<TInit, T, TInit> f) where TInit: notnull => IDoubleEndedIterator<T>.RFoldDefault(ref this, init, f);
     52         public readonly Prod<ulong, Maybe<ulong>> SizeHint() => new(ulong.MaxValue, Maybe<ulong>.None());
     53         public override readonly string ToString() => string.Empty;
     54         public Result<TInit, TErr> TryFold<TInit, TErr>(TInit init, Fn<TInit, T, Result<TInit, TErr>> f) where TInit: notnull where TErr: notnull => IIterator<T>.TryFoldDefault(ref this, init, f);
     55         readonly Result<Repeat<T>, Bottom> ITryInto<Repeat<T>, Bottom>.TryInto() => new(this);
     56         public Result<TInit, TErr> TryRFold<TInit, TErr>(TInit init, Fn<TInit, T, Result<TInit, TErr>> f) where TInit: notnull where TErr: notnull => IDoubleEndedIterator<T>.TryRFoldDefault(ref this, init, f);
     57         #endregion
     58 
     59         #region Operators
     60         #endregion
     61 
     62         #region Types
     63         #endregion
     64     }
     65     #endregion
     66 
     67     #region Namespaces
     68     #endregion
     69 }
     70 #endregion