<commit_before><?php

abstract class Applicative extends Functor {

  // Minimal complete definition of an Applicative Functor.
  // All other functions are built in terms of `of`, `map`, and `ap`.

  /**
   * Lift a value into an Applicative.
   */
  abstract static public function of($x);

  /**
   * Sequential application.
   * @param Applicative $f An Applicative of a function from `A` to `B`
   * @return Applicative An Applicative of `B`
   */
  abstract public function ap(Applicative $f);

  // Utilities (note these are implemented in terms of abstract functions)

  /**
   * Sequence two actions, discarding the first one.
   * @param  Applicative $a
   * @param  Applicative $b
   * @return Applicative
   */
  static public function chooseR(Applicative $a, Applicative $b) {
    return Applicative::liftA2(function ($a, $b) {
      return $b;
    }, $a, $b);
  }

  /**
   * Sequence two actions, discarding the second one.
   * @param  Applicative $a
   * @param  Applicative $b
   * @return Applicative
   */
  static public function chooseL(Applicative $a, Applicative $b) {
    return Applicative::liftA2(array('Basics', 'constant'), $a, $b);
  }

  static public function liftA2(callable $f, Applicative $a, Applicative $b) {
    // Haskell implementation: `f <$> a <*> b`
    return $a->map(Basics::curry2($f))->ap($b);
  }

  static public function liftA3(callable $f, Applicative $a, Applicative $b, Applicative $c) {
    // Haskell implementation: `f <$> a <*> b <*> c`
    return $a->map(Basics::curry3($f))
             ->ap($b)
             ->ap($c);
  }
}<commit_msg>Make chooseL and chooseR methods.<commit_after><?php

abstract class Applicative extends Functor {

  // Minimal complete definition of an Applicative Functor.
  // All other functions are built in terms of `of`, `map`, and `ap`.

  /**
   * Lift a value into an Applicative.
   */
  abstract static public function of($x);

  /**
   * Sequential application.
   * @param Applicative $f An Applicative of a function from `A` to `B`
   * @return Applicative An Applicative of `B`
   */
  abstract public function ap(Applicative $f);

  // Utilities (note these are implemented in terms of abstract functions)

  /**
   * Sequence two actions, discarding the first one.
   * @param  Applicative $a
   * @param  Applicative $b
   * @return Applicative
   */
  public function chooseR(Applicative $b) {
    return Applicative::liftA2(function ($a, $b) {
      return $b;
    }, $this, $b);
  }

  /**
   * Sequence two actions, discarding the second one.
   * @param  Applicative $a
   * @param  Applicative $b
   * @return Applicative
   */
  public function chooseL(Applicative $b) {
    return Applicative::liftA2(array('Basics', 'constant'), $this, $b);
  }

  static public function liftA2(callable $f, Applicative $a, Applicative $b) {
    // Haskell implementation: `f <$> a <*> b`
    return $a->map(Basics::curry2($f))->ap($b);
  }

  static public function liftA3(callable $f, Applicative $a, Applicative $b, Applicative $c) {
    // Haskell implementation: `f <$> a <*> b <*> c`
    return $a->map(Basics::curry3($f))
             ->ap($b)
             ->ap($c);
  }
}
{'fraction_non_alphanumeric': 0.13785488958990536, 'fraction_numerical': 0.0037854889589905363, 'mean_word_length': 3.0653846153846156, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, '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': '2928831', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1017, 'n_words': 328}