September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,30 +1,40 @@
|
|||
-- filter :: (a -> Bool) -> [a] -> [a]
|
||||
-- filter :: (a -> Int -> Bool) -> [a] -> [a]
|
||||
-- filter :: (a -> Int -> [a] -> Bool) -> [a] -> [a]
|
||||
on filter(f, xs)
|
||||
script mf
|
||||
property lambda : f
|
||||
end script
|
||||
|
||||
set lst to {}
|
||||
set lng to length of xs
|
||||
repeat with i from 1 to lng
|
||||
set v to item i of xs
|
||||
if mf's lambda(v, i, xs) then
|
||||
set end of lst to v
|
||||
end if
|
||||
end repeat
|
||||
return lst
|
||||
tell mReturn(f)
|
||||
set lst to {}
|
||||
set lng to length of xs
|
||||
repeat with i from 1 to lng
|
||||
set v to item i of xs
|
||||
if |λ|(v, i, xs) then set end of lst to v
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end filter
|
||||
|
||||
|
||||
-- Ordinary AppleScript predicate function, rather than a script object
|
||||
-- TEST -----------------------------------------------------------------------
|
||||
|
||||
-- isEven :: (a -> Bool)
|
||||
on isEven(x)
|
||||
x mod 2 = 0
|
||||
end isEven
|
||||
|
||||
set lstRange to {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
|
||||
on run
|
||||
|
||||
filter(isEven, lstRange)
|
||||
filter(isEven, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
|
||||
|
||||
-- {0, 2, 4, 6, 8, 10}
|
||||
end run
|
||||
|
||||
-- GENERIC FUNCTION -----------------------------------------------------------
|
||||
|
||||
-- Lift 2nd class handler function into 1st class script wrapper
|
||||
-- mReturn :: Handler -> Script
|
||||
on mReturn(f)
|
||||
if class of f is script then
|
||||
f
|
||||
else
|
||||
script
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue