def reduce(self, expr, init_val=0):
        """Applies the given reduction to this expression, which must resolve
        to an array, and returns the single value computed.

        The provided ``expr`` must include the :const:`VALUE` expression to
        properly define the reduction.

        Examples::

            import fiftyone as fo
            import fiftyone.zoo as foz
            from fiftyone import ViewField as F
            from fiftyone.core.expressions import VALUE

            #
            # Compute the number of keypoints in each sample of a dataset
            #

            dataset = fo.Dataset()
            dataset.add_sample(
                fo.Sample(
                    filepath="image.jpg",
                    keypoints=fo.Keypoints(
                        keypoints=[
                            fo.Keypoint(points=[(0, 0), (1, 1)]),
                            fo.Keypoint(points=[(0, 0), (1, 0), (1, 1), (0, 1)]),
                        ]
                    )
                )
            )

            view = dataset.set_field(
                "keypoints.count",
                F("$keypoints.keypoints").reduce(VALUE + F("points").length()),
            )

            print(view.first().keypoints.count)

            #
            # Generate a `list,of,labels` for the `predictions` of each sample
            #

            dataset = foz.load_zoo_dataset("quickstart")

            join_labels = F("detections").reduce(
                VALUE.concat(",", F("label")), init_val=""
            ).lstrip(",")

            view = dataset.set_field("predictions.labels", join_labels)

            print(view.first().predictions.labels)

        Args:
            expr: a :class:`ViewExpression` defining the reduction expression
                to apply. Must contain the :const:`VALUE` expression
            init_val (0): an initial value for the reduction

        Returns:
            a :class:`ViewExpression`
        """
        expr._freeze_prefix("$$this")
        return ViewExpression(
            {"$reduce": {"input": self, "initialValue": init_val, "in": expr}}
        )
Applies the given reduction to this expression, which must resolve
        to an array, and returns the single value computed.

        The provided ``expr`` must include the :const:`VALUE` expression to
        properly define the reduction.

        Examples::

            import fiftyone as fo
            import fiftyone.zoo as foz
            from fiftyone import ViewField as F
            from fiftyone.core.expressions import VALUE

            #
            # Compute the number of keypoints in each sample of a dataset
            #

            dataset = fo.Dataset()
            dataset.add_sample(
                fo.Sample(
                    filepath="image.jpg",
                    keypoints=fo.Keypoints(
                        keypoints=[
                            fo.Keypoint(points=[(0, 0), (1, 1)]),
                            fo.Keypoint(points=[(0, 0), (1, 0), (1, 1), (0, 1)]),
                        ]
                    )
                )
            )

            view = dataset.set_field(
                "keypoints.count",
                F("$keypoints.keypoints").reduce(VALUE + F("points").length()),
            )

            print(view.first().keypoints.count)

            #
            # Generate a `list,of,labels` for the `predictions` of each sample
            #

            dataset = foz.load_zoo_dataset("quickstart")

            join_labels = F("detections").reduce(
                VALUE.concat(",", F("label")), init_val=""
            ).lstrip(",")

            view = dataset.set_field("predictions.labels", join_labels)

            print(view.first().predictions.labels)

        Args:
            expr: a :class:`ViewExpression` defining the reduction expression
                to apply. Must contain the :const:`VALUE` expression
            init_val (0): an initial value for the reduction

        Returns:
            a :class:`ViewExpression`
        
fiftyone/core/expressions.py