Permutations: Difference between revisions
→{{header|AppleScript}}: Simplified closures, updated library functions
No edit summary |
(→{{header|AppleScript}}: Simplified closures, updated library functions) |
||
Line 442:
(Functional ES5 version)
<lang AppleScript>on run
permutations({"aardvarks", "eat", "ants"})
Line 451 ⟶ 450:
-- permutations :: [a] -> [[a]]
on permutations(xs)
script
on
end
end script
end
end script
if length of xs > 0 then
concatMap(
else
{{}}
end if
end permutations
Line 475:
-- concatMap :: (a -> [b]) -> [a] -> [b]
on concatMap(f, xs)
script
on
a & b
end
end script
foldl(
end concatMap
Line 508 ⟶ 509:
-- delete :: a -> [a] -> [a]
on |delete|(x, xs)
script
on
a = b
end
end script
deleteBy(
end |delete|
Line 520 ⟶ 521:
on deleteBy(fnEq, x, xs)
if length of xs > 0 then
set {h, t} to uncons(xs)
if
t
else
Line 546:
end uncons
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
else
property lambda : f▼
▲ property lambda : f
end script▼
end if
end mReturn
▲ end script
</lang>
|