-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{- | | ||
Copyright: (c) 2021 Kowainik | ||
SPDX-License-Identifier: MPL-2.0 | ||
Maintainer: Kowainik <xrom.xkov@gmail.com> | ||
Stability: Stable | ||
Portability: Portable | ||
Useful combinators to work with the data structures from @containers@ package | ||
and 'Slist' together. | ||
@since x.x.x.x | ||
-} | ||
module Slist.Containers | ||
( -- * Map | ||
mapToVals | ||
, mapToKeys | ||
, mapToPairs | ||
|
||
-- * Set | ||
, setToSlist | ||
) where | ||
|
||
import Data.Map.Strict (Map) | ||
import Data.Set (Set) | ||
|
||
import Slist.Size (Size (..)) | ||
import Slist.Type (Slist (..)) | ||
|
||
import qualified Data.Map.Strict as Map | ||
import qualified Data.Set as Set | ||
|
||
|
||
{- | @O(n)@. | ||
Returns a 'Slist' of all values of the map in the ascending order of their keys. | ||
@since x.x.x.x | ||
-} | ||
mapToVals :: Map k v -> Slist v | ||
mapToVals m = Slist | ||
{ sList = Map.elems m | ||
, sSize = Size $ Map.size m | ||
} | ||
{-# INLINE mapToVals #-} | ||
|
||
{- | @O(n)@. | ||
Returns a 'Slist' of all keys of the map in the ascending order. | ||
@since x.x.x.x | ||
-} | ||
mapToKeys :: Map k v -> Slist k | ||
mapToKeys m = Slist | ||
{ sList = Map.keys m | ||
, sSize = Size $ Map.size m | ||
} | ||
{-# INLINE mapToKeys #-} | ||
|
||
{- | @O(n)@. | ||
Returns a 'Slist' of all key-value pairs of the map in the ascending order of their keys. | ||
@since x.x.x.x | ||
-} | ||
mapToPairs :: Map k v -> Slist (k, v) | ||
mapToPairs m = Slist | ||
{ sList = Map.toAscList m | ||
, sSize = Size $ Map.size m | ||
} | ||
{-# INLINE mapToPairs #-} | ||
|
||
{- | @O(n)@. | ||
Returns a 'Slist' of all elements of the set in the ascending order. | ||
@since x.x.x.x | ||
-} | ||
setToSlist :: Set a -> Slist a | ||
setToSlist s = Slist | ||
{ sList = Set.elems s | ||
, sSize = Size $ Set.size s | ||
} | ||
{-# INLINE setToSlist #-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters