Kernighans large earthquake problem: Difference between revisions

m
→‎AppleScript :: Functional: Added `either` to return any Left message as a string.
m (→‎{{header|AppleScript}}: Quick refactor to handle a missing file and any blank lines.)
m (→‎AppleScript :: Functional: Added `either` to return any Left message as a string.)
Line 146:
on run
bindLReither(readFileLR(fp)identity, identity, ¬
reportbindLR(readFileLR(fp), magnitude))¬
report(fp, magnitude)))
end run
Line 158 ⟶ 159:
script
on |λ|(s)
|Right|(unlines({("Magnitudes above " & magnitude as string) & ¬
" in " & fp & ":", ""} & ¬
concatMap(aboveThreshold(threshold), paragraphs of s)))
end |λ|
end script
Line 215 ⟶ 216:
return acc
end concatMap
 
 
-- either :: (a -> c) -> (b -> c) -> Either a b -> c
on either(lf, rf, e)
if missing value is |Left| of e then
tell mReturn(rf) to |λ|(|Right| of e)
else
tell mReturn(lf) to |λ|(|Left| of e)
end if
end either
 
 
-- identity :: a -> a
on identity(x)
-- The argument unchanged.
x
end identity
 
 
9,655

edits