<commit_before>-module(orset_ext).

-export([intersect/2,
         map/2,
         union/2,
         product/2,
         filter/2]).

-spec union(orset:orset(), orset:orset()) -> orset:orset().
union(LValue, RValue) ->
    orset:merge(LValue, RValue).

-spec product(orset:orset(), orset:orset()) -> orset:orset().
product(LValue, RValue) ->
    FolderFun = fun({X, XCausality}, Acc) ->
            Acc ++ [{{X, Y}, causal_product(XCausality, YCausality)} || {Y, YCausality} <- RValue]
    end,
    lists:foldl(FolderFun, new(), LValue).

-spec intersect(orset:orset(), orset:orset()) -> orset:orset().
intersect(LValue, RValue) ->
    lists:foldl(intersect_folder(RValue), new(), LValue).

%% @private
intersect_folder(RValue) ->
    fun({X, XCausality}, Acc) ->
            Values = case lists:keyfind(X, 1, RValue) of
                         {_Y, YCausality} ->
                             [{X, causal_union(XCausality, YCausality)}];
                         false ->
                             []
                     end,
            Acc ++ Values
    end.

-spec map(fun(), orset:orset()) -> orset:orset().
map(Function, {orset, V}) ->
    FolderFun = fun({X, Causality}, {orset, Acc}) ->
                        {orset, Acc ++ [{Function(X), Causality}]}
                end,
    lists:foldl(FolderFun, new(), V).

-spec filter(fun((_) -> boolean()), orset:orset()) -> orset:orset().
filter(Function, V) ->
    FolderFun = fun({X, Causality}, Acc) ->
                        case Function(X) of
                            true ->
                                Acc ++ [{X, Causality}];
                            false ->
                                Acc
                        end
                end,
    lists:foldl(FolderFun, new(), V).

%% @private
new() -><commit_msg>Fix filter.<commit_after>-module(orset_ext).

-export([intersect/2,
         map/2,
         union/2,
         product/2,
         filter/2]).

-spec union(orset:orset(), orset:orset()) -> orset:orset().
union(LValue, RValue) ->
    orset:merge(LValue, RValue).

-spec product(orset:orset(), orset:orset()) -> orset:orset().
product(LValue, RValue) ->
    FolderFun = fun({X, XCausality}, Acc) ->
            Acc ++ [{{X, Y}, causal_product(XCausality, YCausality)} || {Y, YCausality} <- RValue]
    end,
    lists:foldl(FolderFun, new(), LValue).

-spec intersect(orset:orset(), orset:orset()) -> orset:orset().
intersect(LValue, RValue) ->
    lists:foldl(intersect_folder(RValue), new(), LValue).

%% @private
intersect_folder(RValue) ->
    fun({X, XCausality}, Acc) ->
            Values = case lists:keyfind(X, 1, RValue) of
                         {_Y, YCausality} ->
                             [{X, causal_union(XCausality, YCausality)}];
                         false ->
                             []
                     end,
            Acc ++ Values
    end.

-spec map(fun(), orset:orset()) -> orset:orset().
map(Function, {orset, V}) ->
    FolderFun = fun({X, Causality}, {orset, Acc}) ->
                        {orset, Acc ++ [{Function(X), Causality}]}
                end,
    lists:foldl(FolderFun, new(), V).

-spec filter(fun((_) -> boolean()), orset:orset()) -> orset:orset().
filter(Function, {orset, V}) ->
    FolderFun = fun({X, Causality}, {orset, Acc}) ->
                        case Function(X) of
                            true ->
                                {orset, Acc ++ [{X, Causality}]};
                            false ->
                                {orset, Acc}
                        end
                end,
    lists:foldl(FolderFun, new(), V).

%% @private
new() ->
{'fraction_non_alphanumeric': 0.17044198895027624, 'fraction_numerical': 0.0033149171270718232, 'mean_word_length': 1.688195991091314, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5065888', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1148, 'n_words': 231}