Added curry for nerdy point-freedom

This commit is contained in:
Brandon Dyck 2024-09-09 15:18:27 -06:00
parent 2759894ed8
commit 4d3f576a67

View File

@ -14,7 +14,15 @@ func Todo(t *testing.T) {
t.Errorf("TODO") t.Errorf("TODO")
} }
func notP[T any](pred func(T) bool) func(T) bool { func curry[A, B, C any](f func(A, B) C) func(A) func(B) C {
return func(a A) func(B) C {
return func(b B) C {
return f(a, b)
}
}
}
func not[T any](pred func(T) bool) func(T) bool {
return func(x T) bool { return !pred(x) } return func(x T) bool { return !pred(x) }
} }
@ -39,7 +47,7 @@ func TestSlice(t *testing.T) {
t.Run("fails with wrong contents", rapid.MakeCheck(func(t *rapid.T) { t.Run("fails with wrong contents", rapid.MakeCheck(func(t *rapid.T) {
s := rapid.SliceOfN(rapid.Byte(), 1, -1).Draw(t, "s") s := rapid.SliceOfN(rapid.Byte(), 1, -1).Draw(t, "s")
input := rapid.SliceOfN(rapid.Byte(), len(s), -1). input := rapid.SliceOfN(rapid.Byte(), len(s), -1).
Filter(notP(hasPrefix(s))).Draw(t, "input") Filter(not(curry(bytes.HasPrefix)(s))).Draw(t, "input")
assertParseFails(t, input, gigaparsec.Slice(s)) assertParseFails(t, input, gigaparsec.Slice(s))
})) }))
t.Run("fails at end of input", rapid.MakeCheck(func(t *rapid.T) { t.Run("fails at end of input", rapid.MakeCheck(func(t *rapid.T) {