User avatar
agatha v_lesbian v_trans @agatha@snkrgirl.cfd
1mo
agatha proceeding to create an extension method to make things more readable knowing no one will ever use it
1
0
3
0
User avatar
agatha v_lesbian v_trans @agatha@snkrgirl.cfd
1mo
i can't be the only person that finds list.Contains(x) to read backwards, usually I want to express "if x is in list"!
2
0
1
0
User avatar
pancakes nonbinary_cat @pancakes@meow.company
1mo
@agatha is this anything
var list = new List<int> {1, 2, 3};
if (1 | list)
{
    // it in there
}

public static class CollectionExtensions
{
    extension<T>(ICollection<T>)
    {
        public static bool operator |(T elem, ICollection<T> collection) => collection.Contains(elem);
    }
}
1
0
1
0
User avatar
pancakes nonbinary_cat @pancakes@meow.company
1mo
@agatha alternatively
extension<T>(ICollection<T>)
{
    public static bool operator >(T elem, ICollection<T> collection) => collection.Contains(elem);
    public static bool operator <(T elem, ICollection<T> collection) => !collection.Contains(elem);
}
1
0
1
0
User avatar
agatha v_lesbian v_trans @agatha@snkrgirl.cfd
1mo
@pancakes yes I just made an In extension method that does the same, a backwards Contains essentially
1
0
1
0
User avatar
pancakes nonbinary_cat @pancakes@meow.company
1mo
@agatha in this case c# forces you to define a < operator if you define > so that's an opportunity to do not contains ig
1
0
0
0

User avatar
agatha v_lesbian v_trans @agatha@snkrgirl.cfd
1mo
@pancakes ah sorry i didn't read it properly, i didn't want to do with operators i think this is too terse for C#. so it's a normal extension function,In<T>(this T item, IEnumerable<T> col)

also a params version for comma separated values, why not
2
0
1
0
User avatar
pancakes nonbinary_cat @pancakes@meow.company
1mo
@agatha honestly my solution is really cursed anyways, i just think custom operators being a thing is funny though a bit limited
0
0
1
0
User avatar
princess pancake butterfly_neofox_lesbian @natty@astolfo.social
1mo
@agatha @pancakes I feel like infix functions are a better solution than extension functions, namely because of global pollution
1
0
1
0
User avatar
agatha v_lesbian v_trans @agatha@snkrgirl.cfd
1mo
@natty @pancakes i can pollute global a little bit
1
0
2
0
User avatar
pancakes nonbinary_cat @pancakes@meow.company
1mo
@agatha @natty as a treat
0
0
2
0