<commit_before><?php

namespace Vector\Control;

use Vector\Core\FunctionCapsule;

use Vector\Data\Identity;
use Vector\Data\Constant;

use Vector\Control\FunctorInterface;

use Vector\Lib\Lambda;
use Vector\Lib\ArrayList;
use Vector\Lib\Object;

class Lens extends FunctionCapsule
{
    protected static function constant($a)
    {
        return Constant::Constant($a);
    }

    protected static function identity($a)
    {
        return Identity::Identity($a);
    }

    protected static function view($lens, $x)
    {
        $compose   = Lambda::Using('compose');
        $makeConst = self::Using('constant');
        $runConst  = Functor::Using('extract');

        $view = $compose(
            $runConst,
            $lens($makeConst)
        );

        return $view($x);
    }

    protected static function over($lens, $f, $x)
    {
        $compose   = Lambda::Using('compose');
        $makeIdent = self::Using('identity');
        $runIdent  = Functor::Using('extract');

        $setter = $compose($makeIdent, $f);

        $over = $compose(
            $runIdent,
            $lens($setter)
        );

        return $over($x);
    }

    protected static function set($lens, $v, $x)
    {
        $k    = Lambda::Using('k');
        $over = self::Using('over');

        return $over($lens, $k($v), $x);
    }

    protected static function indexLens($index)
    {
        $curry = FunctionCapsule::Using('curry');

        $indexLens = $curry(function($index, $f, $arr) {
            $fmap = Functor::Using('fmap');
            $set  = ArrayList::Using('set');

            return $fmap($set($index, $arr), $f($arr[$index]));
        });

        return $indexLens($index);
    }

    protected static function propLens($prop)
    {
        $curry = FunctionCapsule::Using('curry');

        $propLens = $curry(function($prop, $f, $obj) {
            $fmap = Functor::Using('fmap');
            $set  = Object::Using('set');

            return $fmap($set($prop, $obj), $f($obj->$prop));
        });

        return $propLens($prop);
    }
}
<commit_msg>Added typehint for object lens<commit_after><?php

namespace Vector\Control;

use Vector\Core\FunctionCapsule;

use Vector\Data\Identity;
use Vector\Data\Constant;

use Vector\Control\FunctorInterface;

use Vector\Lib\Lambda;
use Vector\Lib\ArrayList;
use Vector\Lib\Object;

class Lens extends FunctionCapsule
{
    protected static function constant($a)
    {
        return Constant::Constant($a);
    }

    protected static function identity($a)
    {
        return Identity::Identity($a);
    }

    protected static function view($lens, $x)
    {
        $compose   = Lambda::Using('compose');
        $makeConst = self::Using('constant');
        $runConst  = Functor::Using('extract');

        $view = $compose(
            $runConst,
            $lens($makeConst)
        );

        return $view($x);
    }

    protected static function over($lens, $f, $x)
    {
        $compose   = Lambda::Using('compose');
        $makeIdent = self::Using('identity');
        $runIdent  = Functor::Using('extract');

        $setter = $compose($makeIdent, $f);

        $over = $compose(
            $runIdent,
            $lens($setter)
        );

        return $over($x);
    }

    protected static function set($lens, $v, $x)
    {
        $k    = Lambda::Using('k');
        $over = self::Using('over');

        return $over($lens, $k($v), $x);
    }

    protected static function indexLens($index)
    {
        $curry = FunctionCapsule::Using('curry');

        $indexLens = $curry(function($index, $f, $arr) {
            $fmap = Functor::Using('fmap');
            $set  = ArrayList::Using('set');

            return $fmap($set($index, $arr), $f($arr[$index]));
        });

        return $indexLens($index);
    }

    protected static function propLens($prop)
    {
        $curry = FunctionCapsule::Using('curry');

        $propLens = $curry(function($prop, $f, \stdClass $obj) {
            $fmap = Functor::Using('fmap');
            $set  = Object::Using('set');

            return $fmap($set($prop, $obj), $f($obj->$prop));
        });

        return $propLens($prop);
    }
}

{'fraction_non_alphanumeric': 0.16479311169576658, 'fraction_numerical': 0.0, 'mean_word_length': 2.3059288537549407, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2841277', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1292, 'n_words': 255}