Std

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

FlatMap.cs (2405B)


      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 FlatMap<T, TIter, T2, TIter2>: IFusedIterator<T2>, IInto<FlatMap<T, TIter, T2, TIter2>> where T: notnull where TIter: notnull, IIterator<T> where T2: notnull where TIter2: notnull, IIterator<T2> {
     12 
     13         #region Type-level Constructors
     14         #endregion
     15 
     16         #region Instance Constructors
     17         public FlatMap() => throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");
     18         internal FlatMap(TIter iter, Fn<T, TIter2> f) => _iter = new(iter.Map(f));
     19         #endregion
     20 
     21         #region Type-level Fields
     22         #endregion
     23 
     24         #region Instance Fields
     25         FlatMapInternal<T2, TIter2, Map<T, TIter, TIter2>> _iter;
     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 Result<Unit, ulong> AdvanceBy(ulong n) => IIterator<T2>.AdvanceByDefault(ref this, n);
     39         public ulong Count() => IIterator<T2>.CountDefault(ref this);
     40         public TInit Fold<TInit>(TInit init, Fn<TInit, T2, TInit> f) where TInit: notnull => _iter.Fold(init, f);
     41         public override readonly bool Equals(object? _) => false;
     42         public override readonly int GetHashCode() => 0;
     43         public readonly FlatMap<T, TIter, T2, TIter2> Into() => this;
     44         public Maybe<T2> Last() => IIterator<T2>.LastDefault(ref this);
     45         public Maybe<T2> Next() => _iter.Next();
     46         public Prod<ulong, Maybe<ulong>> SizeHint() => _iter.SizeHint();
     47         public override readonly string ToString() => string.Empty;
     48         public Result<TInit, TErr> TryFold<TInit, TErr>(TInit init, Fn<TInit, T2, Result<TInit, TErr>> f) where TInit: notnull where TErr: notnull => _iter.TryFold(init, f);
     49         readonly Result<FlatMap<T, TIter, T2, TIter2>, Bottom> ITryInto<FlatMap<T, TIter, T2, TIter2>, Bottom>.TryInto() => new(this);
     50         #endregion
     51 
     52         #region Operators
     53         #endregion
     54 
     55         #region Types
     56         #endregion
     57     }
     58     #endregion
     59 
     60     #region Namespaces
     61     #endregion
     62 }
     63 #endregion