Find the missing permutation: Difference between revisions
m
→{{header|AppleScript}}: Tidying
m (→{{header|AppleScript}}: Tidying) |
|||
Line 213:
<lang AppleScript>use framework "Foundation" -- ( sort )
on run
concat(map(composeList({¬
--> "DBAC"
end run
-------------------- GENERIC FUNCTIONS -------------------
-- chars :: String -> [String]
Line 236:
characters of s
end chars
-- Ordering :: (-1 | 0 | 1)
Line 248 ⟶ 249:
end if
end compare
-- comparing :: (a -> b) -> (a -> a -> Ordering)
Line 258 ⟶ 260:
end comparing
--
on composeList(fs)
script
on |λ|(x)
script go
on |λ|(f, a)
mReturn(f)'s |λ|(a)
end |λ|
end script
foldr(go, x, fs)
foldr(result, x, fs)▼
end |λ|
end script
end
-- concat :: [[a]] -> [a]
-- concat :: [String] -> String
on concat(xs)
set lng to length of xs
if 0 < lng and string is class of (item 1 of xs) then
else
repeat with i from 1 to lng
set acc to acc & item i of xs
end repeat
acc
end concat
script▼
▲ on |λ|(a)
script▼
on |λ|(b)▼
|λ|(a, b) of mReturn(f)▼
end |λ|▼
▲ end |λ|
▲ end script
-- foldl :: (a -> b -> a) -> a -> [b] -> a
Line 297 ⟶ 303:
end tell
end foldl
-- foldr :: (b -> a -> a) -> a -> [b] -> a
Line 309 ⟶ 316:
end tell
end foldr
-- group :: Eq a => [a] -> [[a]]
Line 320 ⟶ 328:
groupBy(eq, xs)
end group
-- groupBy :: (a -> a -> Bool) -> [a] -> [[a]]
Line 352 ⟶ 361:
end if
end groupBy
-- head :: [a] -> a
Line 361 ⟶ 371:
end if
end head
-- intercalate :: Text -> [Text] -> Text
Line 369 ⟶ 380:
return strJoined
end intercalate
-- length :: [a] -> Int
Line 374 ⟶ 386:
length of xs
end |length|
-- map :: (a -> b) -> [a] -> [b]
Line 386 ⟶ 399:
end tell
end map
-- minimumBy :: (a -> a -> Ordering) -> [a] -> a
on minimumBy(f
▲ script
▲ return v
end
end minimumBy
-- Lift 2nd class handler function into 1st class script wrapper
Line 410 ⟶ 429:
end if
end mReturn
-- sort :: [a] -> [a]
Line 416 ⟶ 436:
sortedArrayUsingSelector:"compare:") as list
end sort
-- tail :: [a] -> [a]
Line 425 ⟶ 446:
end if
end tail
-- transpose :: [[a]] -> [[a]]
Line 442 ⟶ 464:
map(column, item 1 of xss)
end transpose
-- words :: String -> [String]
|