//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// UserRTX.NET satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Collections;
using System.Collections.Generic;

#if !WASM
namespace user_rtx { using u = user_rtx;
#else
namespace user_rtx.wasm { using u = user_rtx.wasm;
#endif

static partial class ops {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="ENotFound" />
public static int VerifyListIndexOf( int idx ) =>
   idx >= 0 ? idx : throw new ENotFound(
      "Value was not found among list elements." );

//==================================================================================================

[u.failure_as_minus_1]
public static int IndexOf( int val, List<int> values )
{
   for ( int i=0; i<values.Count; i++ )
      if ( val == values[i] )
         return i;
   return -1;
}
/// <exception cref="ENotFound" />
[u.strict_result]
public static int StrictIndexOf( int val, List<int> values ) =>
   VerifyArgListIndexOf( IndexOf( val, values ) );

//--------------------------------------------------------------------------------------------------

[u.failure_as_minus_1]
public static int IndexOf_O( object? val, IEnumerable values )
{
   var enumerator = values.GetEnumerator();
   for ( int idx=0; enumerator.MoveNext(); enumerator.MoveNext(),idx++ )
      if ( object.Equals( val, enumerator.Current ) )
         return idx;
   return -1;
}
/// <exception cref="ENotFound" />
[u.strict_result]
public static int StrictIndexOf_O( object? val, IEnumerable values ) =>
   VerifyArgListIndexOf( IndexOf_O( val, values ) );

//--------------------------------------------------------------------------------------------------

public static bool IsOneOf_O( object? val, IEnumerable values ) =>
   IndexOf_O( val, values ) >= 0;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // ops

} // user_rtx (.wasm)
