examples/lists.qk

Summary

Maintainability
Test Coverage
from console import {write}

forall a, b
fn map(f :: &a: b, list :: {a}): {b} :- match list with
    {}         :- {}
    {x, ...xs} :- f(x) : map(f, xs)
end

forall a
fn filter(f :: &a -> Bool, list :: {a}): {a} :- match list with
    {}         :- {},
    {x, ...xs} :- match f(x) with
        True  :- x : filter(f, xs),
        False :- filter(f, xs)
    end
end

fn double_me(n :: Number): Number :- n * 2
fn divisible_by(m :: Number, n :: Number): Bool :- n mod m = 0

effect main
    do 1 .. 300
    | map(double_me)
    | filter(divisible_by(5))
    | write
end