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) |
||
concatMap(f, xs) |
|||
end |>>=| |
end |>>=| |
||
-- |
-- concatMap :: (a -> [b]) -> [a] -> [b] |
||
on |
on concatMap(f, xs) |
||
set acc to {} |
|||
tell mReturn(f) |
|||
repeat with x in xs |
|||
set acc to acc & |λ|(contents of x) |
|||
end |
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] |