Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
6
Task/Filter/AppleScript/filter-1.applescript
Normal file
6
Task/Filter/AppleScript/filter-1.applescript
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
set array to {1, 2, 3, 4, 5, 6}
|
||||
set evens to {}
|
||||
repeat with i in array
|
||||
if (i mod 2 = 0) then set end of evens to i's contents
|
||||
end repeat
|
||||
return evens
|
||||
17
Task/Filter/AppleScript/filter-2.applescript
Normal file
17
Task/Filter/AppleScript/filter-2.applescript
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
to filter(inList, acceptor)
|
||||
set outList to {}
|
||||
repeat with anItem in inList
|
||||
if acceptor's accept(anItem) then
|
||||
set end of outList to contents of anItem
|
||||
end
|
||||
end
|
||||
return outList
|
||||
end
|
||||
|
||||
script isEven
|
||||
to accept(aNumber)
|
||||
aNumber mod 2 = 0
|
||||
end accept
|
||||
end script
|
||||
|
||||
filter({1,2,3,4,5,6}, isEven)
|
||||
43
Task/Filter/AppleScript/filter-3.applescript
Normal file
43
Task/Filter/AppleScript/filter-3.applescript
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
-------------------------- FILTER --------------------------
|
||||
|
||||
-- filter :: (a -> Bool) -> [a] -> [a]
|
||||
on filter(f, xs)
|
||||
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
|
||||
|
||||
|
||||
--------------------------- TEST ---------------------------
|
||||
on run
|
||||
filter(even, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
|
||||
|
||||
--> {0, 2, 4, 6, 8, 10}
|
||||
end run
|
||||
|
||||
|
||||
-------------------- GENERIC FUNCTIONS ---------------------
|
||||
|
||||
-- even :: Int -> Bool
|
||||
on even(x)
|
||||
0 = x mod 2
|
||||
end even
|
||||
|
||||
|
||||
-- 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