<commit_before>package org.kantega.kson.codec;

import fj.F;
import org.kantega.kson.JsonResult;
import org.kantega.kson.json.JsonValue;

public interface JsonDecoder<A> extends F<JsonValue, JsonResult<A>> {

    default JsonResult<A> f(JsonValue v) {
        return decode(v);
    }

    JsonResult<A> decode(JsonValue v);

    default <B> JsonDecoder<B> map(F<A, B> f) {
        return v -> this.decode(v).map(f);
    }

    default JsonDecoder<A> ensure(F<A, Boolean> pred) {
        return ensure(pred, pred.toString());
    }

    default JsonDecoder<A> ensure(F<A, Boolean> pred, String msg) {
        return v -> this.decode(v).bind(decoded -> pred.f(decoded) ? JsonResult.success(decoded) : JsonResult.fail("The value " + decoded + " did not satisfy the constraint " + msg));
    }
}<commit_msg>Added bind for JsonDecoder, useful for conditional decoding.<commit_after>package org.kantega.kson.codec;

import fj.F;
import org.kantega.kson.JsonResult;
import org.kantega.kson.json.JsonValue;

public interface JsonDecoder<A> extends F<JsonValue, JsonResult<A>> {

    default JsonResult<A> f(JsonValue v) {
        return decode(v);
    }

    JsonResult<A> decode(JsonValue v);

    default <B> JsonDecoder<B> map(F<A, B> f) {
        return v -> this.decode(v).map(f);
    }

    default <B> JsonDecoder<B> bind(F<A,JsonDecoder<B>> f){
        return v->this.decode(v).bind(a->f.f(a).decode(v));
    }

    default JsonDecoder<A> ensure(F<A, Boolean> pred) {
        return ensure(pred, pred.toString());
    }

    default JsonDecoder<A> ensure(F<A, Boolean> pred, String msg) {
        return v -> this.decode(v).bind(decoded -> pred.f(decoded) ? JsonResult.success(decoded) : JsonResult.fail("The value " + decoded + " did not satisfy the constraint " + msg));
    }
}
{'fraction_non_alphanumeric': 0.14831460674157304, 'fraction_numerical': 0.0, 'mean_word_length': 3.4974747474747474, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 39, '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': '4039121', 'n_tokens_mistral': 619, 'n_tokens_neox': 602, 'n_words': 136}