Strip control codes and extended characters from a string: Difference between revisions

→‎{{header|Haskell}}: Added an equivalent variant, rewriting liftA2 as f <$> x <*> y, updating output
(→‎{{header|Haskell}}: Reduced the expression in terms of a liftA2 composition over two other functions.)
(→‎{{header|Haskell}}: Added an equivalent variant, rewriting liftA2 as f <$> x <*> y, updating output)
Line 878:
<lang Haskell>import Control.Applicative (liftA2)
 
strip, strip2 :: String -> String
strip = filter (liftA2 (&&) (> 31) (< 126) . fromEnum)
 
-- or
strip2 = filter (((&&) <$> (> 31) <*> (< 126)) . fromEnum)
 
main :: IO ()
main =
main = print $ strip "alphabetic 字母 with some less parochial parts"</lang>
(putStrLn . unlines) $
main = print[strip, $strip2] strip<*> ["alphabetic 字母 with some less parochial parts"]</lang>
{{Out}}
<pre>"alphabetic with some less parochial parts"</pre>
alphabetic with some less parochial parts</pre>
 
=={{header|Icon}} and {{header|Unicon}}==
9,659

edits