<commit_before>package org.kantega.niagara.json

import org.kantega.niagara.data.*


data class JsonEndec<A>(val encoder:JsonEncoder<A>, val decoder: JsonDecoder<A>){

    fun <B> xmap(f:(A)->B,g:(B)->A):JsonEndec<B> = JsonEndec(
      encoder.comap(g),
      decoder.map(f)
    )

}

data class EndecBuilder<OBJ,C,REST>(val encoder:JsonObjectBuilder<OBJ,REST>, val decoder: JsonDecoder<C>)

fun <OBJ,FIRST,REST,TAIL:HList> EndecBuilder<OBJ,(FIRST)->REST,HCons<FIRST,TAIL>>
  .field(name:String,endec:JsonEndec<FIRST>):EndecBuilder<OBJ,REST,TAIL> =
  EndecBuilder(encoder.field(name,endec.encoder),decoder.field(name,endec.decoder))

fun <A> endec( encoder:JsonEncoder<A>,  decoder: JsonDecoder<A>) : JsonEndec<A> =
  JsonEndec(encoder,decoder)


val endecString = JsonEndec(encodeString, decodeString)
val endecInt = JsonEndec(encodeInt, decodeInt)
val endecLong = JsonEndec(encodeLong, decodeLong)
val endecDouble = JsonEndec(encodeDouble, decodeDouble)
val endecBool = JsonEndec(encodeBool, decodeBool)
fun <A> endecArray(elemEndec:JsonEndec<A>) = JsonEndec(encodeArray(elemEndec.encoder), decodeArray(elemEndec.decoder))


fun <A, B, C, D, E, F, G, H, I, J,T> endec(constructor: (A, B, C, D, E, F, G, H, I,J) -> T,destructor:(T)->HList10<A,B,C,D,E,F,G,H,I,J>) =
  EndecBuilder(encode(destructor),decode(constructor.curried()))

fun <A, B, C, D, E, F, G, H, I, T> endec(constructor: (A, B, C, D, E, F, G, H, I) -> T,destructor:(T)->HList9<A,B,C,D,E,F,G,H,I>) =
  EndecBuilder(encode(destructor),decode(constructor.curried()))

fun <A, B, C, D, E, F, G, H, T> endec(constructor: (A, B, C, D, E, F, G, H) -> T,destructor:(T)->HList8<A,B,C,D,E,F,G,H>) =<commit_msg>builder.build<commit_after>package org.kantega.niagara.json

import org.kantega.niagara.data.*


data class JsonEndec<A>(val encoder:JsonEncoder<A>, val decoder: JsonDecoder<A>){

    fun <B> xmap(f:(A)->B,g:(B)->A):JsonEndec<B> = JsonEndec(
      encoder.comap(g),
      decoder.map(f)
    )

}

data class EndecBuilder<OBJ,C,REST>(val encoder:JsonObjectBuilder<OBJ,REST>, val decoder: JsonDecoder<C>)

fun <A> EndecBuilder<A,A,*>.build() =
  JsonEndec(this.encoder,this.decoder)

fun <OBJ,FIRST,REST,TAIL:HList> EndecBuilder<OBJ,(FIRST)->REST,HCons<FIRST,TAIL>>
  .field(name:String,endec:JsonEndec<FIRST>):EndecBuilder<OBJ,REST,TAIL> =
  EndecBuilder(encoder.field(name,endec.encoder),decoder.field(name,endec.decoder))

fun <A> endec( encoder:JsonEncoder<A>,  decoder: JsonDecoder<A>) : JsonEndec<A> =
  JsonEndec(encoder,decoder)


val endecString = JsonEndec(encodeString, decodeString)
val endecInt = JsonEndec(encodeInt, decodeInt)
val endecLong = JsonEndec(encodeLong, decodeLong)
val endecDouble = JsonEndec(encodeDouble, decodeDouble)
val endecBool = JsonEndec(encodeBool, decodeBool)
fun <A> endecArray(elemEndec:JsonEndec<A>) = JsonEndec(encodeArray(elemEndec.encoder), decodeArray(elemEndec.decoder))


fun <A, B, C, D, E, F, G, H, I, J,T> endec(constructor: (A, B, C, D, E, F, G, H, I,J) -> T,destructor:(T)->HList10<A,B,C,D,E,F,G,H,I,J>) =
  EndecBuilder(encode(destructor),decode(constructor.curried()))

fun <A, B, C, D, E, F, G, H, I, T> endec(constructor: (A, B, C, D, E, F, G, H, I) -> T,destructor:(T)->HList9<A,B,C,D,E,F,G,H,I>) =
  EndecBuilder(encode(destructor),decode(constructor.curried()))

fun <A, B, C, D, E, F, G, H, T> endec(constructor: (A, B, C, D, E, F, G, H) -> T,destructor:(T)->HList8<A,B,C,D,E,F,G,H>) =
{'fraction_non_alphanumeric': 0.1892605633802817, 'fraction_numerical': 0.002347417840375587, 'mean_word_length': 6.626398210290827, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 73, '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': '5451776', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1392, 'n_words': 260}