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