         } else {
             // No more argument: compute final value
             return try filter(boxes)
+        }
+    }
+}
+
+
+// -----------------------------------------------------------------------------
+// MARK: - Post-Rendering Filters
+
+/**
+Builds a filter that performs post rendering.
+
+`Rendering` is a type that wraps a rendered String, and its content type (HTML
+or Text). This filter turns a rendering in another one:
+
+    // twice filter renders its argument twice:
+    let twice = Filter { (rendering: Rendering, _) in
+        return Rendering(rendering.string + rendering.string, rendering.contentType)
+    }
+
+    let template = Template(string: "{{ twice(x) }}")!
+    template.registerInBaseContext("twice", Box(twice))
+
+    // Renders "foofoo", "123123"
+    template.render(Box(["x": "foo"]))!
+    template.render(Box(["x": 123]))!
+
+When this filter is executed, eventual HTML-escaping performed by the rendering
+engine has not happened yet: the rendering argument may contain raw text. This
+allows you to chain post-rendering filters without mangling HTML entities.
+*/
+public func Filter(filter: (Rendering) throws -> Rendering) -> FilterFunction {
+    return { (box: MustacheBox, partialApplication: Bool) in
+        guard !partialApplication else {
+            // This is a single-argument filter: we do not wait for another one.
+            throw NSError(domain: GRMustacheErrorDomain, code: GRMustacheErrorCodeRenderingError, userInfo: [NSLocalizedDescriptionKey: "Too many arguments"])
+        }
+        // Box a RenderFunction
+        return Box { (info: RenderingInfo) in
+            let rendering = try box.render(info: info)
+            return try filter(rendering)
+        }
+    }
+}
+
+
+// -----------------------------------------------------------------------------
+// MARK: - Custom Rendering Filters
+
+/**
+Builds a filter that takes a single argument and performs custom rendering.
+
+See the documentation of the `RenderFunction` type for a detailed discussion of
+the `RenderingInfo` and `Rendering` types.
+
+For an example of such a filter, see the documentation of
+`func Filter<T>(filter: (T?, RenderingInfo) throws -> Rendering) -> FilterFunction`.
+This example processes `T?` instead of `MustacheBox`, but the idea is the same.
+
+- parameter filter: a function `(MustacheBox, RenderingInfo) throws -> Rendering`
+- returns: a FilterFunction
+*/
+public func Filter(filter: (MustacheBox, RenderingInfo) throws -> Rendering) -> FilterFunction {
+    return Filter { (box: MustacheBox) in
+        // Box a RenderFunction
+        return Box { (info: RenderingInfo) in
+            return try filter(box, info)
+        }
+    }
+}
+
+/**
+Builds a filter that takes a single argument of type `T?` and performs custom
+rendering.
+
+For example:
+
+    // {{# pluralize(count) }}...{{/ }} renders the plural form of the section
+    // content if the `count` argument is greater than 1.
+    let pluralize = Filter { (count: Int?, info: RenderingInfo, _) in
+
+        // Pluralize the inner content of the section tag:
+        var string = info.tag.innerTemplateString
+        if count > 1 {
+            string += "s"  // naive pluralization
+        }
+
+        return Rendering(string)
+    }
+
+    let template = Template(string: "I have {{ cats.count }} {{# pluralize(cats.count) }}cat{{/ }}.")!
+    template.registerInBaseContext("pluralize", Box(pluralize))
+
+    // Renders "I have 3 cats."
+    let data = ["cats": ["Kitty", "Pussy", "Melba"]]
+    template.render(Box(data))!
+
+The argument is converted to `T` using the built-in `as?` operator before being
+given to the filter.
+
+If the template provides more than one argument, the filter returns an error of
+domain `GRMustacheErrorDomain` and code `GRMustacheErrorCodeRenderingError`.
+
+See the documentation of the `RenderFunction` type for a detailed discussion of
+the `RenderingInfo` and `Rendering` types.
+
+- parameter filter: a function `(T?, RenderingInfo) throws -> Rendering`
+- returns: a FilterFunction
+*/
+public func Filter<T>(filter: (T?, RenderingInfo) throws -> Rendering) -> FilterFunction {
+    return Filter { (t: T?) in
+        // Box a RenderFunction
+        return Box { (info: RenderingInfo) in
+            return try filter(t, info)
         }
     }
 }

    template.render(Box(["x": 1]))!

`Filter()` can take several types of functions, depending on the type of filter
you want to build. The example above processes `Int`. Other filters are:

- Filters that process values:

    - `(MustacheBox) throws -> MustacheBox`
    - `(T?) throws -> MustacheBox` (Generic)

- Filters that perform post-rendering:

    - `(Rendering) throws -> Rendering`

- Filters that perform custom rendering:

    - `(MustacheBox, RenderingInfo) throws -> Rendering`
    - `(T?, RenderingInfo) throws -> Rendering` (Generic)

- Filters that accept several arguments, built with `VariadicFilter()`:

    - `(boxes: [MustacheBox]) throws -> MustacheBox`
*/
public typealias FilterFunction = (box: MustacheBox, partialApplication: Bool) throws -> MustacheBox


// -----------------------------------------------------------------------------
// MARK: - Filters that process values

/**
Builds a filter that takes a single argument.

        return try filter(box.value as? T)
    }
}

/**
Returns a filter than accepts any number of arguments.
