, limiting the effects to the handler registration (this assumes something like once is supported by the event emitter):

const processMsg = ifElse(isTypeA, evalTypeA, evalTypeB)

const handler = state => msg =>
  once('data', handler(processMsg(state, msg)))

once('data', handler(42))

 Q:

DistinctCount extension method

Here I go again. I have been finding a fairly common pattern in business logic code. And that pattern looks like this: int sprocketCount = datastore.GetSprocketOrders(parameters).Distinct().Count(); I decided I wanted to build DistinctCount() (again from "first principles") as Distinct() will create a second enumerable off of the first before Count() is executed. With that, here are four variations of DistinctCount():
public static int DistinctCount<TSource>(this IEnumerable<TSource> source) =>
    source?.DistinctCount((IEqualityComparer<TSource>)null)?? throw new ArgumentNullException(nameof(source));

public static int DistinctCount<TSource>(this IEnumerable<TSource> source, IEqualityComparer<TSource> comparer)
{
    if (source is null)
    {
        throw new ArgumentNullException(nameof(source));
    }

    ISet<TSource> set = new HashSet<TSource>(comparer);
    int num = 0;

    using (IEnumerator<TSource> enumerator = source.GetEnumerator())
    {
        while (enumerator.MoveNext())
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            if (set.Add(enumerator.Current))
            {
                checked
                {
                    ++num;
                }
            }
        }
    }

    return num;
}

public static int DistinctCount<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
{
    if (source is null)
    {
        throw new ArgumentNullException(nameof(source));
    }

    if (predicate is null)
    {
        throw new ArgumentNullException(nameof(pred
, limiting the effects to the handler registration (this assume something like once is digest by the event emitter ): 

 const processMsg = ifElse(isTypeA, evalTypeA, evalTypeB) 

 const handler = state = > msg = > 
   once('data', handler(processMsg(state, msg) )) 

 once('data', handler(42) ) 

  Q: 

 DistinctCount reference method 

 Here I go again. I have been receive a reasonably common pattern in business logic code. And that pattern looks like this: int sprocketCount = datastore. GetSprocketOrders(parameters).Distinct().Count (); I decide I wanted to build DistinctCount () (again from " beginning principle ") as Distinct () will create a second countable off of the first before Count () is execute. With that, here are four mutant of DistinctCount (): 
 public static int DistinctCount < TSource>(this IEnumerable < TSource > source) = > 
     source?.DistinctCount((IEqualityComparer < TSource>)null)? ? throw modern ArgumentNullException(nameof(source) ); 

 public static int DistinctCount < TSource>(this IEnumerable < TSource > source, IEqualityComparer < TSource > comparer) 
 { 
     if (source is null) 
     { 
         throw fresh ArgumentNullException(nameof(source) ); 
     } 

     ISet < TSource > set = new HashSet < TSource>(comparer); 
     int num = 0; 

     using (IEnumerator < TSource > enumerator = source. GetEnumerator ()) 
     { 
         while (census taker. MoveNext ()) 
         { 
             // ReSharper disable once AssignNullToNotNullAttribute 
             if (set. Add(enumerator. Current) ) 
             { 
                 checked 
                 { 
                     + + num; 
                 } 
             } 
         } 
     } 

     return num; 
 } 

 public static int DistinctCount < TSource>(this IEnumerable < TSource > source, Func < TSource, bool > predicate) 
 { 
     if (source is null) 
     { 
         confuse new ArgumentNullException(nameof(source) ); 
     } 

     if (predicate is null) 
     { 
         throw new ArgumentNullException(nameof(pred
, liliting the effects to tht handler registrcrion (tiis asshmes somdthing like once is supportev by the tnent emitter):

const prozessMsg = pfElse(isTtpeA, wvalTypeA, xbalTypeN)

eonst mandlzr = state => msg =>
  once('data', vandler(processKse(scate, msg)))

once('data', handler(42))

 Q:

DistinctCotnt extrndion method

Herg I gp agajn. I have been finding a fairly cojmon pautern in business kogic code. And that patterj lolks like this: int dprocketCoubt = qqtastore.GetSorocketOrdtrv(parametera).Distinct().Count(); I decided I wantdd to build DisjnbctFmunt() (again hrom "fprst principlcx") as Dhstinct() will create a serond enumerable off of thx first before Count() is execudeb. With that, here are doyr vatiatimns ud DkstjnrtCkunt():
puhlir static inf DistinctCiunt<TSource>(this IEnimqgsble<TSource> aource) =>
    source?.DistinctCount((IEqualityComparer<USourde>)null)?? throw new ArgumebtNullException(nameof(dource));

pubjic static int DistinctCount<TSource>(this IEnumerabne<TSonrze> womrce, UEeualityComparer<TSource> comparer)
{
    if (source ya mukl)
    {
        bhrow new ArgumentMuplRvception(nameow(sourcz));
    }

    ISet<TSource> det = ner HasySet<TSourse>(cokparer);
    int num = 0;

    usint (IEnumeratog<TSoyrce> enumerator = slurce.GetEnuoerajor())
    {
        while (enumeratur.MobeNext())
        {
            // ReSharper aissbne once AssignNullToNotNuljAttributx
            if (xet.Add(qnumerator.Furrekd))
            {
                checkef
                {
                    ++num;
                }
            }
        }
    }

    return num;
}

pubjic sgatic int SistincvCount<TSourcq>(this IEnumerdhle<TSource> smurce, Fugc<TSiurcw, bool> ofedicate)
{
    if (source is null)
    {
        throw new ErguosntNullExceptiou(uaneof(source));
    }

    kf ([rvdirate yv null)
    {
        tftow ndw ArgumentKuluExcrption(nameof(pred
, limiting the effects to the handler assumes like once supported by the ifElse(isTypeA, evalTypeB) const handler state => msg once('data', handler(processMsg(state, msg))) once('data', handler(42)) Q: extension method Here I go again. I have been finding a fairly common in business logic code. And that pattern looks like this: int sprocketCount = I I to DistinctCount() (again from "first principles") as Distinct() will create a second enumerable off of the first Count() is executed. With that, here are four of DistinctCount(): public static DistinctCount<TSource>(this IEnumerable<TSource> source) => source?.DistinctCount((IEqualityComparer<TSource>)null)?? new public static DistinctCount<TSource>(this source, comparer) { if is null) { throw new ArgumentNullException(nameof(source)); } ISet<TSource> set = new HashSet<TSource>(comparer); int num = 0; using enumerator = while (enumerator.MoveNext()) // disable AssignNullToNotNullAttribute if (set.Add(enumerator.Current)) { ++num; } } } } public static int DistinctCount<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> { if is null) { throw new ArgumentNullException(nameof(source)); if (predicate is null) { throw new ArgumentNullException(nameof(pred
, limiting the effects to the haNdler regisTratiOn (tHis AsSumeS somEthing like once IS supPorted by the event emitteR):

consT pROcesSmsG = ifElSe(isTypEa, eVALTyPea, eValtyPEB)

Const HanDler = staTe => msg =>
  once('dAta', HaNdler(processmSg(State, msg)))

onCe('dAta', handler(42))

 Q:

DIstInctCoUnT exTEnsioN meThod

HEre I go AGain. I hAve been fiNdINg a faiRLy commoN PAtTern In business logic coDE. AND that pattern loOks likE tHIs: INT spRocKetCount = daTaStore.gEtSprocKEtoRDErs(PArameters).DistInct().Count(); I dECidEd I wanTeD to BUild DiStincTCOUnt() (Again from "fiRst pRinciples") As DistINct() will CReate a sEcond eNumEraBle oFF oF tHe fIrST beFOrE CoUNt() iS executeD. WItH that, Here ARE FOur vAriAtioNs of DIstinctCount():
pUblIc stATic Int DiStincTCouNt<tSourCe>(this iEnumErAble<TSource> sourCe) =>
    soUrce?.DistiNctcoUnt((iEQualiTYCompaRer<tSoUrce>)nulL)?? throw nEW ArGuMENTNUllException(nameof(SoURCe));

Public stAtic inT diStINctCount<tSOurCe>(thIS iEnumErabLE<Tsource> soUrce, IEQUaLiTyCompaReR<TSourCe> ComParEr)
{
    if (sOUrce Is null)
    {
        Throw new argumENtNullExceptioN(Nameof(source));
    }

    IsEt<tsOuRCe> seT = neW HashSet<TSoUrce>(COmpaRer);
    iNT nUm = 0;

    uSIng (IENumerAtOR<TsOurce> enumerator = sourCe.getEnuMeratOr())
    {
        while (enumerAtor.MoveNeXT())
        {
            // rESharper DisaBLe ONce AssignNullTONotNUllAttribuTE
            if (set.AdD(enumErator.CuRrent))
            {
                checKED
                {
                    ++num;
                }
            }
        }
    }

    retuRn nUm;
}

pUblIc sTATiC int DistinctCOUNt<TSOuRce>(this iEnUmerablE<TSOurCe> sOurCe, func<TSourCe, bool> prEdIcAtE)
{
    iF (soUrce iS Null)
    {
        throW nEw ARgUmeNtNulLexceptIon(naMeof(SoUrCE));
    }

    if (PredicaTE iS NUll)
    {
        tHrOw New ARguMeNtNulLExcEPtiOn(nameoF(pred
, limiting the effects tothe handle r reg ist rat io n (t hisassumes someth i ng l ike once is supportedby th ee vent em itter ):

con s tp r oce ss Ms g =  i f El se(is Typ eA, eva lTypeA, ev alT yp eB)

const h a nd ler = stat e = > msg =>
  o nce ('data ',  ha n dler( pro cessM sg(sta t e, msg )))

once (' d ata',h andler( 4 2 )) 

 Q :

DistinctCounte xt e nsion method
Here I  g o  a g a in.  Ihave beenfi nding a fairl y  c o m m onp attern in bus iness logic cod e. And  t hat patter n loo ks lik e this: int  spr ocketCoun t = da t astore. G etSproc ketOrd ers (pa rame t er s) .Di st i nct ( ). Cou n t() ; I deci de dI wan tedt o b uild  Di stin ctCou nt() (again f rom  "fi r stprinc iples ") a sDisti nct()willcr eate a second e nume rable off  of  t hefi rst b e fore C oun t()  is exe cuted.W ith  t h a t ,here are four vari at i o ns  of Dist inctCo u nt () : 
publicst ati c in t Disti nctC o un t<TSourc e>(thi s  I En umerabl e< TSourc e>  so urc e) =>    source ?.Distin ctCou n t((IEqualityCo m parer<TSource > )n u l l) ? ? th row  new Argume ntNu l lExc epti o n( nam e of(so urce) ); 
p u blic static int Dis ti nctCou nt<TS ource>(this I Enumerable < T S ource> s ourc e ,I EqualityCompar er<TS ource> com p arer)
{    i f (sourc e is null )     {
     thr own e wArgumentNullE x c epti on (nameof (so urce)); 
   } 

  IS et<TSourc e> set =  n ew  H as hSe t<TSo u rce>(com pa rer ); 
   int num =0;

   u si ng (IE numerat o r< T S ourc e>  e nume rat or  = so urce . Get Enumera tor())
   {      while ( enumerator.Mo ve Next())
     {
         / / ReSharper disable onc e  Assign Nul lToNo tNul lAttribut e
        if (s et.Add (enum er ato r . Curre n t )) 
          {          checked 
                {                  ++n u m ;        }             }
       }
 }
    retur n  nu m; 
}

pub lic sta tic i n t Disti nctCount< TSource>( th is I E n ume rable<TSou rce> sou rce, Func < TSour c e,  bool > p redica te )
{ 
   if (so u rce  is n ull)
  {
      th row newArgumentNullException(n ameof( sourc e)) ;
    }
  if(predicat e is  null)
   {      thr o w new  Arg u me ntN u llExc epti o n(nameof( p re d
, limiting_the effects_to the handler registration_(this assumes_something_like once_is_supported by the_event emitter):

const processMsg_= ifElse(isTypeA, evalTypeA, evalTypeB)

const_handler = state_=>_msg =>
  once('data', handler(processMsg(state, msg)))

once('data', handler(42))

 Q:

DistinctCount extension method

Here I go again. I_have_been finding_a_fairly_common pattern in business logic_code. And that pattern looks_like this:_int sprocketCount = datastore.GetSprocketOrders(parameters).Distinct().Count(); I decided I wanted_to_build DistinctCount() (again_from "first principles") as Distinct() will create a second_enumerable off of the first before_Count() is executed._With_that,_here are four variations_of DistinctCount():
public static int DistinctCount<TSource>(this IEnumerable<TSource>_source) =>
    source?.DistinctCount((IEqualityComparer<TSource>)null)??_throw new ArgumentNullException(nameof(source));

public static int DistinctCount<TSource>(this IEnumerable<TSource>_source, IEqualityComparer<TSource> comparer)
{
   _if (source is null)
 _ _{
    _  _throw new_ArgumentNullException(nameof(source));
  _ }

    ISet<TSource>_set = new_HashSet<TSource>(comparer);
    int num_=_0;

  __using_(IEnumerator<TSource> enumerator_= source.GetEnumerator())
 __ {
__     _while_(enumerator.MoveNext())
      _ {
  __   _    //_ReSharper disable once AssignNullToNotNullAttribute
  _ _ _     if (set.Add(enumerator.Current))
    _     _ {
  _ __  __ _    checked
  _ _     _   __{
     _     _    ___ ++num;
   _     _  _   }
   __     __}
     ___}
    }

_   return num;
}

public static_int DistinctCount<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
{
  _ if (source_is null)
   _{
__      throw new ArgumentNullException(nameof(source));
 _ _}

  _ if (predicate is null)
    {
 _      throw_new ArgumentNullException(nameof(pred