두 가지 유형의 목록을 정렬하고 싶습니다. 그렇게하려면 먼저 Wrapper
유형을 작성하십시오. 따라서 mappend
유형을 사용할 수 있습니다.다른 유형의 목록 정렬
- 여기에
Wrapper
유형이 있습니까? 내가 델타 키를 기준으로 정렬하려는 경우 - 은 내가 실제 정렬을 수행 할 방법에 대한 명확하지 않다 (즉,
fooDelta
및barDelta
)
코드 :
import Data.List (sortBy)
import Data.Monoid
import Data.Ord (comparing)
data Foo = Foo
{ fooLabel :: String
, fooDelta :: Int
} deriving (Show, Eq)
data Bar = Bar
{ barLabel :: String
, barDelta :: Int
, barAnother :: String
} deriving (Show, Eq)
data Wrapper = WFoo Foo | WBar Bar
deriving (Show, Eq)
sortTest :: [Wrapper]
sortTest =
listFoo <> listBar
where
listFoo = [WFoo $ Foo "label1" 0, WFoo $ Foo "label2" 2]
listBar = [WBar $ Bar "label1" 1 "another1"]
요소에 대해 원하는 순서는 무엇입니까? – dkasak
오 죄송합니다. 질문을 정렬 요구 사항으로 업데이트했습니다. – amitaibu