Convert seconds to compound duration: Difference between revisions
Content added Content deleted
m (Added Quackery.) |
m (→{{header|AppleScript}}: Tidied.) |
||
Line 294: | Line 294: | ||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |
||
<lang AppleScript> |
|||
<lang AppleScript>-- LOCAL NAMES FOR COMPOUND DURATIONS ---------------------------------------- |
|||
-------------------- COMPOUND DURATIONS ------------------ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
-- weekParts Int -> [Int] |
-- weekParts Int -> [Int] |
||
Line 312: | Line 301: | ||
unitParts(intSeconds, [missing value, 7, 24, 60, 60]) |
unitParts(intSeconds, [missing value, 7, 24, 60, 60]) |
||
end weekParts |
end weekParts |
||
-- localCompoundDuration :: Int -> String |
-- localCompoundDuration :: Int -> String |
||
Line 333: | Line 323: | ||
end localCompoundDuration |
end localCompoundDuration |
||
------------------ INTEGER DECOMPOSITION ----------------- |
|||
-- unitParts :: Int -> [maybe Int] -> [Int] |
-- unitParts :: Int -> [maybe Int] -> [Int] |
||
Line 357: | Line 347: | ||
{remaining:intTotal, parts:[]}, unitList) |
{remaining:intTotal, parts:[]}, unitList) |
||
end unitParts |
end unitParts |
||
⚫ | |||
on run |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end run |
|||
-------------------- GENERIC FUNCTIONS ------------------- |
|||
-- foldr :: ( |
-- foldr :: (a -> b -> b) -> b -> [a] -> b |
||
on foldr(f, startValue, xs) |
on foldr(f, startValue, xs) |
||
tell mReturn(f) |
tell mReturn(f) |
||
Line 373: | Line 375: | ||
end foldr |
end foldr |
||
-- intercalate :: Text -> [Text] -> Text |
|||
-- intercalate :: String -> [String] -> String |
|||
⚫ | |||
⚫ | |||
set |
set {dlm, my text item delimiters} to ¬ |
||
{my text item delimiters, delim} |
|||
set s to xs as text |
|||
set my text item delimiters to dlm |
set my text item delimiters to dlm |
||
s |
|||
return strJoined |
|||
end intercalate |
end intercalate |
||
-- map :: (a -> b) -> [a] -> [b] |
-- map :: (a -> b) -> [a] -> [b] |
||
on map(f, xs) |
on map(f, xs) |
||
-- The list obtained by applying f |
|||
-- to each element of xs. |
|||
tell mReturn(f) |
tell mReturn(f) |
||
set lng to length of xs |
set lng to length of xs |
||
Line 392: | Line 399: | ||
end tell |
end tell |
||
end map |
end map |
||
-- min :: Ord a => a -> a -> a |
-- min :: Ord a => a -> a -> a |
||
Line 402: | Line 410: | ||
end min |
end min |
||
-- Lift 2nd class handler function into 1st class script wrapper |
|||
-- mReturn :: |
-- mReturn :: First-class m => (a -> b) -> m (a -> b) |
||
on mReturn(f) |
on mReturn(f) |
||
-- 2nd class handler function lifted into 1st class script wrapper. |
|||
if script is class of f then |
|||
f |
f |
||
else |
else |
||
Line 413: | Line 422: | ||
end if |
end if |
||
end mReturn |
end mReturn |
||
-- unlines :: [String] -> String |
-- unlines :: [String] -> String |
||
on unlines(xs) |
on unlines(xs) |
||
-- A single string formed by the intercalation |
|||
⚫ | |||
-- of a list of strings with the newline character. |
|||
⚫ | |||
{my text item delimiters, linefeed} |
|||
set s to xs as text |
|||
set my text item delimiters to dlm |
|||
s |
|||
end unlines |
end unlines |
||
-- zip :: [a] -> [b] -> [(a, b)] |
-- zip :: [a] -> [b] -> [(a, b)] |
||
on zip(xs, ys) |
on zip(xs, ys) |
||
-- A list of step-wise pairs drawn from xs and ys |
|||
-- up to the length of the shorter of those lists. |
|||
set lng to min(length of xs, length of ys) |
set lng to min(length of xs, length of ys) |
||
set |
set zs to {} |
||
repeat with i from 1 to lng |
repeat with i from 1 to lng |
||
set end of |
set end of zs to {item i of xs, item i of ys} |
||
end repeat |
end repeat |
||
return |
return zs |
||
end zip</lang> |
end zip</lang> |
||
{{Out}} |
{{Out}} |