Convert seconds to compound duration: Difference between revisions

m
m (Added Quackery.)
Line 294:
=={{header|AppleScript}}==
 
<lang AppleScript>
<lang AppleScript>-- LOCAL NAMES FOR COMPOUND DURATIONS ----------------------------------------
-------------------- COMPOUND DURATIONS ------------------
 
script angloNames
on |λ|(n)
(n as string) & " -> " & ¬
localCompoundDuration(["wk", "d", "hr", "min", "sec"], n)
end |λ|
end script
 
unlines(map(angloNames, [7259, 86400, 6000000]))
 
 
-- DURATION STRINGS ----------------------------------------------------------
 
-- weekParts Int -> [Int]
Line 312 ⟶ 301:
unitParts(intSeconds, [missing value, 7, 24, 60, 60])
end weekParts
 
 
-- localCompoundDuration :: Int -> String
Line 333 ⟶ 323:
end localCompoundDuration
 
-- INTEGER DECOMPOSITION ------------------------------------ INTEGER DECOMPOSITION -----------------
 
-- unitParts :: Int -> [maybe Int] -> [Int]
Line 357 ⟶ 347:
{remaining:intTotal, parts:[]}, unitList)
end unitParts
 
-- DURATION STRINGS --------------------------------- TEST -------------------------
on run
script angloNames
on |λ|(n)
(n as string) & " -> " & ¬
localCompoundDuration(["wk", "d", "hr", "min", "sec"], n)
end |λ|
end script
unlines(map(angloNames, [7259, 86400, 6000000]))
end run
 
 
-- GENERIC FUNCTIONS -------------------------------------- GENERIC FUNCTIONS -------------------
 
-- foldr :: (ba -> ab -> ab) -> ab -> [ba] -> ab
on foldr(f, startValue, xs)
tell mReturn(f)
Line 373 ⟶ 375:
end foldr
 
 
-- intercalate :: Text -> [Text] -> Text
on-- intercalate(strText, lstText):: String -> [String] -> String
on intercalate(linefeeddelim, xs)
set {dlm, my text item delimiters} to {my text item delimiters, strText}
set strJoined{dlm, tomy lstTexttext asitem textdelimiters} to ¬
{my text item delimiters, delim}
set s to xs as text
set my text item delimiters to dlm
s
return strJoined
end intercalate
 
 
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
-- The list obtained by applying f
-- to each element of xs.
tell mReturn(f)
set lng to length of xs
Line 392 ⟶ 399:
end tell
end map
 
 
-- min :: Ord a => a -> a -> a
Line 402 ⟶ 410:
end min
 
 
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: HandlerFirst-class m => (a -> b) -> m (a -> Scriptb)
on mReturn(f)
if-- 2nd class ofhandler ffunction islifted into 1st class script thenwrapper.
if script is class of f then
f
else
Line 413 ⟶ 422:
end if
end mReturn
 
 
-- unlines :: [String] -> String
on unlines(xs)
-- A single string formed by the intercalation
intercalate(linefeed, xs)
-- of a list of strings with the newline character.
set {dlm, my text item delimiters} to {my text item delimiters, strText}¬
{my text item delimiters, linefeed}
set s to xs as text
set my text item delimiters to dlm
s
end unlines
 
 
-- zip :: [a] -> [b] -> [(a, b)]
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 lstzs to {}
repeat with i from 1 to lng
set end of lstzs to {item i of xs, item i of ys}
end repeat
return lstzs
end zip</lang>
{{Out}}
9,655

edits