Skip to content

Conversation

glesica
Copy link

@glesica glesica commented Feb 15, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant