You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Blocks can't ignore unused parameters — every position must be explicitly bound, even with |_| #354
A block passed where a function of one argument is expected must declare exactly that argument, even when the block never uses it — there is no way to write a zero-parameter block and have Kex treat it as "ignore whatever you're given." |_| (or a named-but-unused binding) is required everywhere, with no exceptions found so far.
Repro
Three different stdlib/application shapes, same failure:
[1, 2, 3].each do
IO.printLine("tick")
end
# error: `each` expects argument 2 to be A -> Void, but got () -> Void
3.times do
IO.printLine("hi")
end
# error: `times` expects argument 2 to be Integer -> Void, but got () -> Void
# Rodolfo (kexhq/rodolfo): a route handler ignoring the request context
get "/" do
"Hello from Kex!"
end
# error: `get` expects argument 2 to be Context -> Reply, but got () -> String
All three work fine with an explicit discard: .each do |_| ... end, .times do |_| ... end, get "/" do |_| ... end.
Why it matters
Integer#times is the clearest case: the index is routinely irrelevant ("do this 3 times") and every other block-taking API where the argument is commonly unused — an HTTP route that ignores the request, a timer tick, a retry callback — hits the same friction. I looked at working around this at the call-site library level (overloading a function to accept either A -> B or () -> B) rather than filing this; it didn't work cleanly either — the two overloads didn't resolve/unify the way I expected, so it doesn't look like something callers can reasonably paper over themselves.
Expected
A block with fewer parameters than the expected function type should be accepted, with the missing arguments simply discarded — the way |_| already behaves, just without requiring the explicit no-op parameter for every unused position.
Environment
kex 0.4.0-beta.3, 293a0b5 — locally built dev toolchain. Found while building kexhq/rodolfo's route handlers and documentation examples.
Activity
Document #22: blocks can't ignore unused parameters
Mark #20/#22 fixed, correct #21's scope
Migrate #22 like the stdlib did, add Plug.around