2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
30
Task/Filter/AppleScript/filter-3.applescript
Normal file
30
Task/Filter/AppleScript/filter-3.applescript
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
-- 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
|
||||
end filter
|
||||
|
||||
|
||||
-- Ordinary AppleScript predicate function, rather than a script object
|
||||
|
||||
-- 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}
|
||||
|
||||
filter(isEven, lstRange)
|
||||
Loading…
Add table
Add a link
Reference in a new issue