Sort a list of object identifiers: Difference between revisions

→‎{{header|Haskell}}: Tidied the Data.Text.split variant
(→‎{{header|Haskell}}: Added a variant using split :: (Char -> Bool) -> Text -> [Text])
(→‎{{header|Haskell}}: Tidied the Data.Text.split variant)
Line 174:
import Data.List (sort, intercalate)
 
oidsidSort :: [String] -> [String]
oidsidSort =
((intercalate "." <$>) . ((show <$>) <$>)) <$> sort $
[ "1.3.6.1.4.1.11.2.17.19.3.4.0.10"
((show <$>) <$>) . sort . ((readInt <$>) <$>) . (splitString '.' <$>)
, "1.3.6.1.4.1.11.2.17.5.2.0.79"
, "1.3.6.1.4.1.11.2.17.19.3.4.0.4"
, "1.3.6.1.4.1.11150.3.4.0.1"
, "1.3.6.1.4.1.11.2.17.19.3.4.0.1"
, "1.3.6.1.4.1.11150.3.4.0"
]
 
sortOIDsplitString :: [Char -> String] -> [String]
splitString c s = unpack <$> split (c ==) (pack s)
sortOID xs =
 
((intercalate "." <$>) . ((show <$>) <$>)) <$> sort $
readInt :: String -> Int
(((\x -> read x :: Int) <$>) . (unpack <$>) . split ('.' ==) . pack) <$> xs
readInt xs = read xs :: Int
 
main :: IO ()
main =
main = mapM_ putStrLn $ sortOID oids</lang>
idSort
[ "1.3.6.1.4.1.11.2.17.19.3.4.0.10"
, "1.3.6.1.4.1.11.2.17.5.2.0.79"
, "1.3.6.1.4.1.11.2.17.19.3.4.0.4"
, "1.3.6.1.4.1.11150.3.4.0.1"
, "1.3.6.1.4.1.11.2.17.19.3.4.0.1"
, "1.3.6.1.4.1.11150.3.4.0"
]</lang>
{{Out}}
<pre>1.3.6.1.4.1.11.2.17.5.2.0.79
9,659

edits