Jump to content

Sort a list of object identifiers: Difference between revisions

→‎{{header|Haskell}}: (slightly simpler expression for the main function)
(→‎Task: promoted draft task to task.)
(→‎{{header|Haskell}}: (slightly simpler expression for the main function))
Line 172:
<lang haskell>import Data.Text (pack, split, unpack)
import Data.List (sort, intercalate)
 
-- SORTING OBJECT IDENTIFIERS ------------------------------------------------
oidSort :: [String] -> [String]
oidSort =
(intercalate "." <$>) .
((show <$>) <$>) . sort . (((readInt <$>) <$>) . (splitString '.') <$>)
 
-- GENERIC FUNCTIONS ---------------------------------------------------------
splitString :: Char -> String -> [String]
splitString c s = unpack <$> split (c ==) (pack s)
 
readInt :: String -> Int
readInt xs = read xs :: Int
 
-- TEST ----------------------------------------------------------------------
main :: IO ()
Line 216:
oidSort =
(intercalate "." <$>) .
((show <$>) <$>) . sort . (((readInt <$>) <$>) . (splitOn ".") <$>)</lang>
 
=={{header|J}}==
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.