<commit_before><?php

namespace Md\Phunkie\Cats;

/**
 * Lens<A,B>
 */
class Lens
{
    private $g;
    private $s;

    /**
     * @param callable<A, B> $g
     * @param callable<(A,B), A> $s
     */
    public function __construct(callable $g, callable $s)
    {
        $this->g = $g;
        $this->s = $s;
    }

    /**
     * @param A $a
     * @return B
     */
    public function get($a)
    {
        return call_user_func($this->g, $a);
    }

    /**
     * @param B $b
     * @param A $a
     * @return A
     */
    public function set($b, $a)
    {
        return call_user_func_array($this->s, [$b, $a]);
    }

    /**
     * @param callable<B,B> $f
     * @param A $a
     * @return A
     */
    public function mod(callable $f, $a)
    {
        return $this->set($f($this->get($a)), $a);
    }

    public function andThen(Lens $l): Lens
    {
        return new Lens(
            function($a) use ($l) { return $l->get($this->get($a)); },
            function($c, $a) use ($l) { return $this->mod(function($b) use ($l, $c) { return $l->set($c, $b); }, $a); }
        );
    }

    public function compose(Lens $that): Lens
    {
        return $that->andThen($this);
    }
}<commit_msg>Remove phpdocs from lens as it is messing up with the IDE<commit_after><?php

namespace Md\Phunkie\Cats;

class Lens
{
    private $g;
    private $s;

    public function __construct(callable $g, callable $s)
    {
        $this->g = $g;
        $this->s = $s;
    }

    public function get($a)
    {
        return call_user_func($this->g, $a);
    }

    public function set($b, $a)
    {
        return call_user_func_array($this->s, [$b, $a]);
    }

    public function mod(callable $f, $a)
    {
        return $this->set($f($this->get($a)), $a);
    }

    public function andThen(Lens $l): Lens
    {
        return new Lens(
            function($a) use ($l) { return $l->get($this->get($a)); },
            function($c, $a) use ($l) { return $this->mod(function($b) use ($l, $c) { return $l->set($c, $b); }, $a); }
        );
    }

    public function compose(Lens $that): Lens
    {
        return $that->andThen($this);
    }
}
{'fraction_non_alphanumeric': 0.1887494188749419, 'fraction_numerical': 0.0, 'mean_word_length': 1.9439124487004105, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, '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': '5873142', 'n_tokens_mistral': 814, 'n_tokens_neox': 794, 'n_words': 189}