Std

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

FromFn.cs (2147B)


      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 readonly struct FromFn<T>: IInto<FromFn<T>>, IIterator<T> where T: notnull {
     12 
     13         #region Type-level Constructors
     14         #endregion
     15 
     16         #region Instance Constructors
     17         public FromFn() => throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");
     18         internal FromFn(Fn<Maybe<T>> f) => _f = f;
     19         #endregion
     20 
     21         #region Type-level Fields
     22         #endregion
     23 
     24         #region Instance Fields
     25         readonly Fn<Maybe<T>> _f;
     26         #endregion
     27 
     28         #region Type-level Properties
     29         #endregion
     30 
     31         #region Instance Properties
     32         #endregion
     33 
     34         #region Type-level Functions
     35         #endregion
     36 
     37         #region Instance Functions
     38         public readonly Result<Unit, ulong> AdvanceBy(ulong n) => IIterator<T>.AdvanceByDefault(this, n);
     39         public readonly ulong Count() => IIterator<T>.CountDefault(this);
     40         public override readonly bool Equals(object? _) => false;
     41         public readonly TInit Fold<TInit>(TInit init, Fn<TInit, T, TInit> f) where TInit: notnull => IIterator<T>.FoldDefault(this, init, f);
     42         public override readonly int GetHashCode() => 0;
     43         public readonly FromFn<T> Into() => this;
     44         public readonly Maybe<T> Last() => IIterator<T>.LastDefault(this);
     45         public readonly Maybe<T> Next() => _f();
     46         public override readonly string ToString() => string.Empty;
     47         public readonly Result<TInit, TErr> TryFold<TInit, TErr>(TInit init, Fn<TInit, T, Result<TInit, TErr>> f) where TInit: notnull where TErr: notnull => IIterator<T>.TryFoldDefault(this, init, f);
     48         readonly Result<FromFn<T>, Bottom> ITryInto<FromFn<T>, Bottom>.TryInto() => new(this);
     49         #endregion
     50 
     51         #region Operators
     52         #endregion
     53 
     54         #region Types
     55         #endregion
     56     }
     57     #endregion
     58 
     59     #region Namespaces
     60     #endregion
     61 }
     62 #endregion