assert icon indicating copy to clipboard operation
assert copied to clipboard

Add SeqContains and NotSeqContains functions

Open glesica opened this issue 10 months ago • 0 comments

Given that we have iter.Seq[T] now, along with things like maps.Keys, which returns an iter.Seq[T], it might be nice to have a SeqContains function in this library since it would have fairly broad applicability and allow some niche things that Testify supports (like Contains with a map) without polluting the API with niche functions.

For example,

assert.SeqContains(t, maps.Keys(myMap), 0, "foo")

is a fairly elegant way to say "has key", without having a highly specialized HasKey function.

I added the maxChecked parameter because a sequence can be infinite, so in some cases it might be useful to set an upper bound. I wouldn't anticipate this being set to anything other than zero very often, so I'm not married to the idea. Implementing a Take(n) function is pretty easy, so maybe people who need that functionality could just do it that way.

I haven't added the negated version or tests because I wasn't sure if this is a desirable addition. Happy to finish it if so.

glesica avatar Feb 15 '25 19:02 glesica