I think it is useful in the case where you have multiple things you need to target and handle differently, but you do not want to crawl the tree multiple times. In these cases you might utilize match, but using compile allows you to reuse the same pattern. We do cache patterns, but using compile will skip even having to retrieve the object from the cache and just reuse the existing pattern. The next Soup Sieve release will reduce overhead a little more when using a pre-compiled pattern.
Just some basic flow in which this would be used. Hopefully, that makes sense.
```
sel1 = soup.css.compile('some selector')
sel2 = soup.css.compile('some other selector')
# Iterate tags only
for el in soup.select('*'):
# Do something different for different matches
if el.match(sel1):
# Do something
elif el.match(sel2):
# Do something else
```
I think it is useful in the case where you have multiple things you need to target and handle differently, but you do not want to crawl the tree multiple times. In these cases you might utilize match, but using compile allows you to reuse the same pattern. We do cache patterns, but using compile will skip even having to retrieve the object from the cache and just reuse the existing pattern. The next Soup Sieve release will reduce overhead a little more when using a pre-compiled pattern.
Just some basic flow in which this would be used. Hopefully, that makes sense.
``` compile( 'some selector') compile( 'some other selector')
sel1 = soup.css.
sel2 = soup.css.
# Iterate tags only
for el in soup.select('*'):
# Do something different for different matches
if el.match(sel1):
# Do something
elif el.match(sel2):
# Do something else
```