-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add resource modification functions (#26)
- Loading branch information
1 parent
e1177a5
commit 00885f2
Showing
17 changed files
with
255 additions
and
350 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
-- | This module everything related to the main library interface | ||
-- | ||
-- @since 0.1.0 | ||
|
||
module Seer ( | ||
Id, | ||
|
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,31 @@ | ||
-- | This module includes everything about general entity handling | ||
-- | ||
-- @since 0.1.0 | ||
|
||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
|
||
module Seer.Entity ( | ||
EntityRelation(..) | ||
) where | ||
|
||
-- | A relation between a single type `s` and its plural `p` | ||
-- | ||
-- @since 0.1.0 | ||
class EntityRelation s p where | ||
-- | Adds a single `s` to plural `p` | ||
-- | ||
-- @since 0.1.0 | ||
infixr 5 |+ | ||
(|+) | ||
:: p -- ^ The plural where the single entity should be added | ||
-> s -- ^ The single entity to be added | ||
-> p -- ^ The resulting plural | ||
|
||
-- | Removes a single `s` from plural `p` | ||
-- | ||
-- @since 0.1.0 | ||
infixr 5 |- | ||
(|-) | ||
:: p -- ^ The plural where the single entity should be removed | ||
-> s -- ^ The single entity to be removed | ||
-> p -- ^ The resulting plural |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
-- | This module includes everything related to git. | ||
-- | ||
-- @since 0.1.0 | ||
|
||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
|
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,104 @@ | ||
-- | This module includes everything about a 'Resource'. | ||
-- | ||
-- @since 0.1.0 | ||
|
||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
|
||
module Seer.Resource ( | ||
Resource, | ||
Resources, | ||
empty, | ||
name, | ||
newResource, | ||
toResources, | ||
) where | ||
|
||
import Data.Yaml (FromJSON, ToJSON) | ||
import GHC.Generics (Generic) | ||
import Seer (Id) | ||
import Seer.Entity (EntityRelation(..)) | ||
import qualified Data.Set as S (Set, delete, empty, insert, singleton) | ||
|
||
-- | The data representing multiple Resources | ||
-- | ||
-- @since 0.1.0 | ||
newtype Resources = Resources (S.Set Resource) | ||
deriving (Eq, Generic, Ord, Show) | ||
|
||
-- | The data representing a single Resource | ||
-- | ||
-- @since 0.1.0 | ||
newtype Resource = Resource { name :: Id -- ^ The name of the resource | ||
} deriving (Eq, Generic, Ord, Show) | ||
|
||
-- | Parses the 'Resource' from YAML/JSON | ||
-- | ||
-- @since 0.1.0 | ||
instance FromJSON Resource | ||
|
||
-- | Parses the 'Resources' from YAML/JSON | ||
-- | ||
-- @since 0.1.0 | ||
instance FromJSON Resources | ||
|
||
-- | Generates the YAML/JSON from an 'Resource' | ||
-- | ||
-- @since 0.1.0 | ||
instance ToJSON Resource | ||
|
||
-- | Generates the YAML/JSON from 'Resources' | ||
-- | ||
-- @since 0.1.0 | ||
instance ToJSON Resources | ||
|
||
-- | Entity relations between 'Resource' and 'Resources' | ||
-- | ||
-- @since 0.1.0 | ||
instance EntityRelation Resource Resources where | ||
-- | Removes a 'Resource' from 'Resources' | ||
-- | ||
-- @since 0.1.0 | ||
Resources xs |- x = Resources $ S.delete x xs | ||
|
||
-- | Adds a 'Resource' to 'Resources' | ||
-- | ||
-- @since 0.1.0 | ||
Resources xs |+ x = Resources $ S.insert x xs | ||
|
||
-- | The empty 'Resources' representation | ||
-- | ||
-- Examples: | ||
-- | ||
-- >>> empty | ||
-- Resources (fromList []) | ||
-- | ||
-- @since 0.1.0 | ||
empty :: Resources | ||
empty = Resources S.empty | ||
|
||
-- | Creates a new 'Resource' from a given name | ||
-- | ||
-- Examples: | ||
-- | ||
-- >>> newResource "Resourcename" | ||
-- Resource {name = "Resourcename"} | ||
-- | ||
-- @since 0.1.0 | ||
newResource | ||
:: Id -- ^ The resources name | ||
-> Resource -- ^ The resulting 'Resource' | ||
newResource a = Resource {name = a} | ||
|
||
-- | Converts a 'Resource' to 'Resources' | ||
-- | ||
-- Examples: | ||
-- | ||
-- >>> toResources $ newResource "Resource" | ||
-- Resources (fromList [Resource {name = "Resource"}]) | ||
-- | ||
-- @since 0.1.0 | ||
toResources | ||
:: Resource -- ^ The Resource to be added | ||
-> Resources -- ^ The Resources where the resource should be added | ||
toResources x = Resources $ S.singleton x |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.