How do you filter matrix blocks by type? Is there a way to filter a matrix by block type, or get a count of how many items there are of a certain type? Can't find a syntax example.

I created a matrix with two blocks. In pseudo code, basically what I want to do is this:

{% set typeOneBlocks = theMatrix blocks where type == "typeOne" %}

{% if typeOneBlocks != null %}
    &lt;div class="divAWrapper"&gt;
        {% for block in typeOneBlocks %}
            &lt;div class="divA"&gt;{# do stuff #}&lt;/div&gt;
        {% endfor %}
    &lt;/div&gt;
{% endif %}


Same with typeTwo blocks. If there are no items of one type or the other, I don't want to create that container and have it sitting empty. 

If there is not a way to filter or get a count, I'd have to use for loops to increment vars for how many of each block type there are and then act based on those counts. Seems there should be a simpler way.
You can grab a specific block type in Matrix by doing this:

{% for block in entry.myMatrixField.type('typeOne') %}
    {{ block.text | markdown }}
{% endfor %}


If you wanted to know the number of blocks of a certain type, you can do:

{% set blocks = entry.myMatrixField.type('typeOne') %}
{{ blocks | length }}


If you want to search for multiple block types, you can do this:

{% set blocks = entry.myMatrixField.type('typeOne, typeTwo') %}


For your specific example, it would look like this:

{% set typeOneBlocks = entry.myMatrixField.type('typeOne') %}

{% if typeOneBlocks | length %}
    &lt;div class="divAWrapper"&gt;
        {% for block in typeOneBlocks %}
            &lt;div class="divA"&gt;{# do stuff #}&lt;/div&gt;
        {% endfor %}
    &lt;/div&gt;
{% endif %}