Order disjoint list items: Difference between revisions
→AppleScript :: Functional: Minor Tidying.
(→{{header|AppleScript}}: Added an idiomatic solution.) |
(→AppleScript :: Functional: Minor Tidying.) |
||
Line 97:
Accumulate a segmentation of M over a fold/reduce, and zip with N:
<lang AppleScript>
-- disjointOrder :: String -> String -> String
Line 105:
unwords(flatten(zip(segments(ms, ns), ns & "")))
end disjointOrder
-- segments :: [String] -> [String] -> [String]
Line 128 ⟶ 129:
on run
script order
Line 137 ⟶ 138:
end |λ|
end script
arrowTable(map(order, [¬
Line 157 ⟶ 159:
-- arrowTable :: [[String]] -> String
Line 194:
transpose(map(leftAligned, transpose(rows)))))
end arrowTable
-------------------- GENERIC FUNCTIONS -------------------
-- concatMap :: (a -> [b]) -> [a] -> [b]
Line 205 ⟶ 208:
foldl(append, {}, map(f, xs))
end concatMap
-- deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]
Line 219 ⟶ 223:
end if
end deleteBy
-- deleteFirst :: a -> [a] -> [a]
Line 230 ⟶ 235:
deleteBy(Eq, x, xs)
end deleteFirst
-- flatten :: Tree a -> [a]
Line 239 ⟶ 245:
end if
end flatten
-- foldl :: (a -> b -> a) -> a -> [b] -> a
Line 251 ⟶ 258:
end tell
end foldl
-- intercalate :: Text -> [Text] -> Text
Line 259 ⟶ 267:
return strJoined
end intercalate
-- justifyLeft :: Int -> Char -> Text -> Text
Line 268 ⟶ 277:
end if
end justifyLeft
-- map :: (a -> b) -> [a] -> [b]
Line 280 ⟶ 290:
end tell
end map
-- maximumBy :: (a -> a -> Ordering) -> [a] -> a
Line 296 ⟶ 307:
foldl(max, missing value, xs)
end maximumBy
-- minimum :: [a] -> a
Line 311 ⟶ 323:
foldl(min, missing value, xs)
end minimum
-- Lift 2nd class handler function into 1st class script wrapper
Line 323 ⟶ 336:
end if
end mReturn
-- Egyptian multiplication - progressively doubling a list, appending
Line 341 ⟶ 355:
return out & dbl
end replicate
-- transpose :: [[a]] -> [[a]]
Line 358 ⟶ 373:
map(column, item 1 of xss)
end transpose
-- uncons :: [a] -> Maybe (a, [a])
Line 367 ⟶ 383:
end if
end uncons
-- unwords :: [String] -> String
Line 378 ⟶ 395:
words of s
end |words|
-- zip :: [a] -> [b] -> [(a, b)]
Line 398 ⟶ 416:
A B B A -> B A -> B A B A </pre>
----
===Idiomatic===
|