<commit_before>#ifndef _71e78c5d_ea88_4df2_977c_1a40712c3291
#define _71e78c5d_ea88_4df2_977c_1a40712c3291

namespace fn {

namespace fn_ {

template<typename F>
struct Invoke
{
    F f;
    template<typename ...Args>
    auto operator()(Args... args) -> decltype(f(args...)) { return f(args...); }
};

template<typename V>
struct InvokeHelper
{
    template<typename X>
    static auto inv(V v,X) -> V { return v; }
};

template<typename V>
struct InvokeHelper<Invoke<V>>
{
    template<typename X>
    static auto inv(Invoke<V> v,X x) -> decltype(v(x)) { return v(x); }
};

template<typename T1, typename T2>
struct ValuePair
{
    T1 first;
    T2 second;
};

struct DefaultTo {};

template<typename M, typename V>
auto match_helper(M const& m, ValuePair<DefaultTo,V> vp)
    -> decltype(InvokeHelper<V>::inv(vp.second,m.k))
{
    return InvokeHelper<V>::inv(vp.second,m.k);
}

template<typename M, typename K, typename V, typename ...Args>
auto match_helper(M const& m, ValuePair<K,V> vp, Args... args)
    -> decltype(InvokeHelper<V>::inv(vp.second,m.k))
{
    if(vp.first(m.k)){
        return InvokeHelper<V>::inv(vp.second,m.k);
    }
    else{
        return match_helper(m,args...);
    }
}

template<typename T>
struct Pick
{
    T const k;

	template<typename K, typename V, typename ...Args>
	auto operator()(ValuePair<K, V> vp, Args... args) const
        -> decltype(InvokeHelper<V>::inv(vp.second,k))
    {
        return match_helper(*this,vp,args...);
    }
};

template<typename P>
struct When { P const p; };

template<typename P, typename Then>
auto operator >>=(When<P> const w, Then const then) -> ValuePair<P,Then> const
{
    return ValuePair<P,Then>{w.p,then};
}

template<typename P, typename Then>
auto operator >>(When<P> const w, Then const then) -> ValuePair<P,Invoke<Then>> const
{
    return ValuePair<P,Invoke<Then>>{w.p,Invoke<Then>{then}};
}

// Specialization for expression nodes
template<typename L, typename R, typename Op> struct ENode;
template<typename P, typename L, typename R, typename Op>
auto operator >>=(When<P> const w, ENode<L,R,Op> const then)
    -> ValuePair<P,Invoke<ENode<L,R,Op>>> const
{
    return ValuePair<P,Invoke<ENode<L,R,Op>>>{w.p,Invoke<ENode<L,R,Op>>{then}};
}



} // namespace fn_

template<typename K>
auto pick(K t) -> fn_::Pick<K> const { return fn_::Pick<K>{t}; }

template<typename P>
auto when(P p) -> fn_::When<P> const { return fn_::When<P>{p}; }

static auto const default_to = when(fn_::DefaultTo());

} // namespace fn

#endif<commit_msg>pick: better names<commit_after>#ifndef _71e78c5d_ea88_4df2_977c_1a40712c3291
#define _71e78c5d_ea88_4df2_977c_1a40712c3291

namespace fn {

namespace fn_ {

template<typename F>
struct Invoke
{
    F f;
    template<typename ...Args>
    auto operator()(Args... args) -> decltype(f(args...)) { return f(args...); }
};

template<typename V>
struct InvokeHelper
{
    template<typename X>
    static auto inv(V v,X) -> V { return v; }
};

template<typename V>
struct InvokeHelper<Invoke<V>>
{
    template<typename X>
    static auto inv(Invoke<V> v,X x) -> decltype(v(x)) { return v(x); }
};

template<typename Predicate, typename Value>
struct Rule
{
    Predicate predicate;
    Value value;
};

struct DefaultTo {};

template<typename P, typename Value>
auto pick_helper(P const& p, Rule<DefaultTo,Value> rule)
    -> decltype(InvokeHelper<Value>::inv(rule.value,p.var))
{
    return InvokeHelper<Value>::inv(rule.value,p.var);
}

template<typename P, typename Predicate, typename Value, typename ...Args>
auto pick_helper(P const& p, Rule<Predicate,Value> rule, Args... args)
    -> decltype(InvokeHelper<Value>::inv(rule.value,p.var))
{
    if(rule.predicate(p.var)){
        return InvokeHelper<Value>::inv(rule.value,p.var);
    }
    else{
        return pick_helper(p,args...);
    }
}

template<typename Var>
struct Pick
{
    Var const var;

	template<typename Predicate, typename Value, typename ...Args>
	auto operator()(Rule<Predicate, Value> rule, Args... args) const
        -> decltype(InvokeHelper<Value>::inv(rule.value,var))
    {
        return pick_helper(*this,rule,args...);
    }
};

template<typename Predicate>
struct When { Predicate const predicate; };

template<typename Predicate, typename Then>
auto operator >>=(When<Predicate> const when, Then const then)
    -> Rule<Predicate,Then> const
{
    return Rule<Predicate,Then>{when.predicate,then};
}

template<typename Predicate, typename Then>
auto operator >>(When<Predicate> const when, Then const then)
    -> Rule<Predicate,Invoke<Then>> const
{
    return Rule<Predicate,Invoke<Then>>{when.predicate,Invoke<Then>{then}};
}

// Specialization for expression nodes
template<typename L, typename R, typename Op> struct ENode;
template<typename Predicate, typename L, typename R, typename Op>
auto operator >>=(When<Predicate> const when, ENode<L,R,Op> const then)
    -> Rule<Predicate,Invoke<ENode<L,R,Op>>> const
{
    return Rule<Predicate,Invoke<ENode<L,R,Op>>>{
        when.predicate,Invoke<ENode<L,R,Op>>{then}
    };
}



} // namespace fn_

template<typename Var>
auto pick(Var var) -> fn_::Pick<Var> const { return fn_::Pick<Var>{var}; }

template<typename Predicate>
auto when(Predicate p) -> fn_::When<Predicate> const { return fn_::When<Predicate>{p}; }

static auto const default_to = when(fn_::DefaultTo());

} // namespace fn

#endif
{'fraction_non_alphanumeric': 0.15524005230711752, 'fraction_numerical': 0.01718662432280964, 'mean_word_length': 4.391742195367573, 'pattern_counts': {'":': 0, '<': 107, '<?xml version=': 0, '>': 141, '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': '1252277', 'n_tokens_mistral': 1947, 'n_tokens_neox': 1874, 'n_words': 440}