<commit_before># This file implements the following set operators:
#   (.)  set multiplication (ASCII)
#   ⊍    set multiplication

proto sub infix:<(.)>(|) is pure {*}
multi sub infix:<(.)>()               { bag()    }
multi sub infix:<(.)>(Setty:D $a)     { $a.Baggy }
multi sub infix:<(.)>(Baggy:D $a)     { $a       }  # also Mixy
multi sub infix:<(.)>(Any $a)         { $a.Bag   }

multi sub infix:<(.)>(Setty:D $a, Setty:D $b) {
    nqp::if(
      (my $elems := $a.Bag.RAW-HASH) && nqp::elems($elems),
      nqp::create($a.WHAT.Baggy).SET-SELF(
        Rakudo::QuantHash.MULTIPLY-SET-TO-BAG($elems,$b.RAW-HASH),
      ),
      $a.Baggy
    )
}

multi sub infix:<(.)>(Mixy:D $a, Mixy:D $b) {
    nqp::if(
      (my $elems := Rakudo::QuantHash.BAGGY-CLONE-RAW($a.RAW-HASH))
        && nqp::elems($elems),
      nqp::stmts(
        Rakudo::QuantHash.MULTIPLY-MIX-TO-MIX($elems,$b.RAW-HASH),
        nqp::create($a.WHAT).SET-SELF($elems)
      ),
      $a
    )
}

multi sub infix:<(.)>(Mixy:D $a, Baggy:D $b) { infix:<(.)>($a, $b.Mix) }
multi sub infix:<(.)>(Mixy:D $a, Any $b)     { infix:<(.)>($a, $b.Mix) }
multi sub infix:<(.)>(Setty:D $a, Mixy:D $b) { infix:<(.)>($a.Mixy, $b) }
multi sub infix:<(.)>(Baggy:D $a, Mixy:D $b) { infix:<(.)>($a.Mixy, $b) }
multi sub infix:<(.)>(Any $a, Mixy:D $b)     { infix:<(.)>($a.Mix, $b) }
multi sub infix:<(.)>(Baggy:D $a, Baggy:D $b) {
    nqp::if(
      (my $elems := Rakudo::QuantHash.BAGGY-CLONE-RAW($a.RAW-HASH))
        && nqp::elems($elems),
      nqp::create($a.WHAT).SET-SELF(
        Rakudo::QuantHash.MULTIPLY-BAG-TO-BAG($elems,$b.RAW-HASH),
      ),
      $a
    )
}

multi sub infix:<(.)>(Any $, Failure:D $b) { $b.throw }
multi sub infix:<(.)>(Failure:D $a, Any $) { $a.throw }

# Note that we cannot create a Setty|Baggy:D,Any candidate because that will
# result in an ambiguous dispatch, so we need to hack a check for Setty|Baggy
# in here.
multi sub infix:<(.)>(Any $a, Any $b) {
    infix:<(.)>(
      nqp::isconcrete($a)
        ?? nqp::istype($a,Setty)
          ?? $a.Baggy
          !! nqp::istype($a,Baggy) ?? $a !! $a.Bag
        !! $a.Bag,
      $b.Bag
    )
}

multi sub infix:<(.)>(**@p) {
    my $result = @p.shift;
    $result = $result (.) @p.shift while @p;
    $result
}

# U+228D MULTISET MULTIPLICATION
my constant &infix:<⊍> := &infix:<(.)>;

# vim: ft=perl6 expandtab sw=4<commit_msg>Fewer scalar containers for (.)<commit_after># This file implements the following set operators:
#   (.)  set multiplication (ASCII)
#   ⊍    set multiplication

proto sub infix:<(.)>(|) is pure {*}
multi sub infix:<(.)>()               { bag()   }
multi sub infix:<(.)>(Setty:D \a)     { a.Baggy }
multi sub infix:<(.)>(Baggy:D \a)     { a       }  # also Mixy
multi sub infix:<(.)>(Any \a)         { a.Bag   }

multi sub infix:<(.)>(Setty:D \a, Setty:D \b) {
    nqp::if(
      (my $elems := a.Bag.RAW-HASH) && nqp::elems($elems),
      nqp::create(a.WHAT.Baggy).SET-SELF(
        Rakudo::QuantHash.MULTIPLY-SET-TO-BAG($elems,b.RAW-HASH),
      ),
      a.Baggy
    )
}

multi sub infix:<(.)>(Mixy:D \a, Mixy:D \b) {
    nqp::if(
      (my $elems := Rakudo::QuantHash.BAGGY-CLONE-RAW(a.RAW-HASH))
        && nqp::elems($elems),
      nqp::stmts(
        Rakudo::QuantHash.MULTIPLY-MIX-TO-MIX($elems,b.RAW-HASH),
        nqp::create(a.WHAT).SET-SELF($elems)
      ),
      a
    )
}

multi sub infix:<(.)>(Mixy:D  \a, Baggy:D \b) { infix:<(.)>(a, b.Mix) }
multi sub infix:<(.)>(Mixy:D  \a, Any     \b) { infix:<(.)>(a, b.Mix) }
multi sub infix:<(.)>(Setty:D \a, Mixy:D  \b) { infix:<(.)>(a.Mixy, b) }
multi sub infix:<(.)>(Baggy:D \a, Mixy:D  \b) { infix:<(.)>(a.Mixy, b) }
multi sub infix:<(.)>(Any     \a, Mixy:D  \b) { infix:<(.)>(a.Mix, b) }
multi sub infix:<(.)>(Baggy:D \a, Baggy:D \b) {
    nqp::if(
      (my $elems := Rakudo::QuantHash.BAGGY-CLONE-RAW(a.RAW-HASH))
        && nqp::elems($elems),
      nqp::create(a.WHAT).SET-SELF(
        Rakudo::QuantHash.MULTIPLY-BAG-TO-BAG($elems,b.RAW-HASH),
      ),
      a
    )
}

multi sub infix:<(.)>(Any $, Failure:D \b) { b.throw }
multi sub infix:<(.)>(Failure:D \a, Any $) { a.throw }

# Note that we cannot create a Setty|Baggy:D,Any candidate because that will
# result in an ambiguous dispatch, so we need to hack a check for Setty|Baggy
# in here.
multi sub infix:<(.)>(Any \a, Any \b) {
    infix:<(.)>(
      nqp::isconcrete(a)
        ?? nqp::istype(a,Setty)
          ?? a.Baggy
          !! nqp::istype(a,Baggy) ?? a !! a.Bag
        !! a.Bag,
      b.Bag
    )
}

multi sub infix:<(.)>(**@p) {
    my $result = @p.shift;
    $result = $result (.) @p.shift while @p;
    $result
}

# U+228D MULTISET MULTIPLICATION
my constant &infix:<⊍> := &infix:<(.)>;

# vim: ft=perl6 expandtab sw=4
{'fraction_non_alphanumeric': 0.23342512179622962, 'fraction_numerical': 0.0021181952976064393, 'mean_word_length': 2.6576297443841983, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, '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': '4089362', 'n_tokens_mistral': 2151, 'n_tokens_neox': 2099, 'n_words': 405}