String case: Difference between revisions

Content deleted Content added
Blue (talk | contribs)
Hout (talk | contribs)
m →‎{{header|AppleScript}}: Slight reordering, updated primitives
Line 334:
 
<lang applescript>use framework "Foundation"
use scripting additions
 
on run
map(testCase, {my toUpperCase, my toLowerCase, my toCapitalized})
end run
 
-- toUpperCase :: Text -> Text
Line 364 ⟶ 358:
 
 
-- TESTINGTEST
 
-- testCase :: Handler -> String
Line 371 ⟶ 365:
end testCase
 
on run
map(testCase, {my toUpperCase, my toLowerCase, my toCapitalized})
end run
 
-- GENERIC FUNCTIONS
 
-- GENERIC FUNCTIONS
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
set mf totell mReturn(f)
set lng to length of xs
set lst to {}
repeat with i from 1 to lng
set end of lst to mf's lambda(item i of xs, i, xs)
end repeat
return lst
end tell
end map
 
 
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then return f
script f
else
property lambda : f
end script
property lambda : f
end mReturn</lang>
end script
end if
end mReturn</lang>
</lang>