<commit_before>package com.natpryce.krouton.example

import com.natpryce.hamkrest.assertion.assertThat
import com.natpryce.hamkrest.equalTo
import com.natpryce.hamkrest.isEmptyString
import com.natpryce.hamkrest.present
import com.natpryce.krouton.*
import com.natpryce.krouton.simple.by
import com.natpryce.krouton.simple.otherwise
import com.natpryce.krouton.simple.routeOn
import org.junit.AfterClass
import org.junit.BeforeClass
import org.junit.Test
import java.io.FileNotFoundException
import java.net.HttpURLConnection.HTTP_NOT_FOUND
import java.time.DateTimeException
import java.time.LocalDate
import java.time.LocalDate.now

// An application-specific mapping between parsed URL elements and typed data
object _LocalDate : Projection3<Int,Int,Int,LocalDate> {
    override fun fromParts(t1: Int, t2: Int, t3: Int) =
            try { LocalDate.of(t1, t2, t3) } catch (e: DateTimeException) { null }

    override fun toParts(u: LocalDate) =
            u.year to u.monthValue to u.dayOfMonth
}

// Route components
val year = int
val month = int
val day = int
val date = year/month/day asA _LocalDate

// Application routes
val reverse = "reverse" / string
val reversed = "reversed" / string
val negate = "negate" / int
val negative = "negative" / int
val weekday = "weekday" / date
val weekdayToday = root / "weekday" / "today"


// The server that uses the routes
fun exampleServer(port: Int = 0) = HttpServer(port) { exchange ->
    routeOn(exchange.requestURI.rawPath,
            root by {
                exchange.sendString("Hello, World.")
            },

            negate by { i ->
                exchange.sendString((-i).toString())
            },

            negative by { i ->
                // Note - reverse routing from integer to URL path
                exchange.sendRedirect(negate.path(i))
            },

            reverse by { s ->
                exchange.sendString(s.reversed())
            },

            reversed by { s ->
                exchange.sendRedirect(reversed.path(s))
            },
<commit_msg>Fix example<commit_after>package com.natpryce.krouton.example

import com.natpryce.hamkrest.assertion.assertThat
import com.natpryce.hamkrest.equalTo
import com.natpryce.hamkrest.isEmptyString
import com.natpryce.hamkrest.present
import com.natpryce.krouton.*
import com.natpryce.krouton.simple.by
import com.natpryce.krouton.simple.otherwise
import com.natpryce.krouton.simple.routeOn
import org.junit.AfterClass
import org.junit.BeforeClass
import org.junit.Test
import java.io.FileNotFoundException
import java.net.HttpURLConnection.HTTP_NOT_FOUND
import java.time.DateTimeException
import java.time.LocalDate
import java.time.LocalDate.now

// An application-specific mapping between parsed URL elements and typed data
object _LocalDate : Projection3<Int,Int,Int,LocalDate> {
    override fun fromParts(t1: Int, t2: Int, t3: Int) =
            try { LocalDate.of(t1, t2, t3) } catch (e: DateTimeException) { null }

    override fun toParts(u: LocalDate) =
            u.year to u.monthValue to u.dayOfMonth
}

// Route components
val year = int
val month = int
val day = int
val date = year/month/day asA _LocalDate

// Application routes
val reverse = "reverse" / string
val reversed = "reversed" / string
val negate = "negate" / int
val negative = "negative" / int
val weekday = "weekday" / date
val weekdayToday = root / "weekday" / "today"


// The server that uses the routes
fun exampleServer(port: Int = 0) = HttpServer(port) { exchange ->
    routeOn(exchange.requestURI.rawPath,
            root by {
                exchange.sendString("Hello, World.")
            },

            negate by { i ->
                exchange.sendString((-i).toString())
            },

            negative by { i ->
                // Note - reverse routing from integer to URL path
                exchange.sendRedirect(negate.path(i))
            },

            reverse by { s ->
                exchange.sendString(s.reversed())
            },

            reversed by { s ->
                exchange.sendRedirect(reverse.path(s))
            },

{'fraction_non_alphanumeric': 0.0995850622406639, 'fraction_numerical': 0.003905296558457408, 'mean_word_length': 2.6459074733096086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '1565219', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1222, 'n_words': 313}