List comprehensions: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: addec/changed some comments and whitespace, changed indentation of some output.)
(→‎{{header|AppleScript}}: Updated concatMap)
Line 228: Line 228:
-- (>>=) :: Monad m => m a -> (a -> m b) -> m b
-- (>>=) :: Monad m => m a -> (a -> m b) -> m b
on |>>=|(xs, f)
on |>>=|(xs, f)
concat(map(f, xs))
concatMap(f, xs)
end |>>=|
end |>>=|


-- concat :: [[a]] -> [a] | [String] -> String
-- concatMap :: (a -> [b]) -> [a] -> [b]
on concat(xs)
on concatMap(f, xs)
script append
set acc to {}
on |λ|(a, b)
tell mReturn(f)
a & b
repeat with x in xs
end |λ|
set acc to acc & |λ|(contents of x)
end script
end repeat
end tell
return acc
if length of xs > 0 and class of (item 1 of xs) is string then
end concatMap
set empty to ""
else
set empty to {}
end if
foldl(append, empty, xs)
end concat


-- enumFromTo :: Int -> Int -> [Int]
-- enumFromTo :: Int -> Int -> [Int]