---
id: 218
title: TypeComparison FilterFunction Implementation
slug: typecomparison-filterfunction-implementation
date: '2008-08-28T22:11:06Z'
modified: '2008-08-28T22:11:06Z'
status: publish
type: post
author: pmoelgaard
categories:
  - ActionScript 3.0
  - Adobe Flex
tags: []
excerpt: null
canonicalPath: /posts/typecomparison-filterfunction-implementation
featuredImage: null
commentCount: 0
wordCount: 172
readingTimeMinutes: 1
hasMedia: false
hasVideos: false
url: >-
  https://forwardthinking.pemo.me/posts/typecomparison-filterfunction-implementation
---
When applying a filterFunction to a collection the code can get a little slightly messy. Finding that I many times want to filter a collection containing objects of different types by the type of object and in order to reduce the mess, I have created a small class which encapsulates this filterfunction. I wish Function was not declared Final… all the cool things what would be made possible then :-)

Anyways… while we are waiting for true reflection to find its way into our midst, here is a small implementation resembling a helper class that does the job nicely.

[Download source here](http://petermolgaard.com/projects/TypeCompareFunction.zip)

```jscript
/**
* Copyright(c) 2008 HelloGroup A/S, some rights reserved.
* Your reuse is governed by the Creative Commons Attribution 3.0 Denmark License
**/
package com.hello.collections
{
    public class TypeCompareFunction
    {
        public var type:Class;

        public function TypeCompareFunction( type:Class )
        {
            super();

            this.type = type;
        }

        public function getFunction() : Function
        {
            return compare;
        }

        private function compare( item:Object ) : Boolean
        {
            return item is type;
        }
    }
}
```
