-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Unit instances * Void instances, docs * Add Maybe instances
- Loading branch information
Showing
11 changed files
with
163 additions
and
49 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,84 @@ | ||
## Module Data.Foreign.Generic.EnumEncoding | ||
|
||
#### `GenericEnumOptions` | ||
|
||
``` purescript | ||
type GenericEnumOptions = { constructorTagTransform :: String -> String } | ||
``` | ||
|
||
#### `defaultGenericEnumOptions` | ||
|
||
``` purescript | ||
defaultGenericEnumOptions :: GenericEnumOptions | ||
``` | ||
|
||
#### `genericDecodeEnum` | ||
|
||
``` purescript | ||
genericDecodeEnum :: forall a rep. Generic a rep => GenericDecodeEnum rep => GenericEnumOptions -> Foreign -> F a | ||
``` | ||
|
||
A generic function to be used with "Enums", or sum types with only no-argument constructors. This is used for decoding from strings to one of the constructors, combined with the `constructorTagTransform` property of `SumEncoding`. | ||
|
||
#### `genericEncodeEnum` | ||
|
||
``` purescript | ||
genericEncodeEnum :: forall a rep. Generic a rep => GenericEncodeEnum rep => GenericEnumOptions -> a -> Foreign | ||
``` | ||
|
||
A generic function to be used with "Enums", or sum types with only no-argument constructors. This is used for encoding to strings from one of the constructors, combined with the `constructorTagTransform` property of `SumEncoding`. | ||
|
||
For example: | ||
|
||
```purescript | ||
data Fruit = Apple | Banana | Frikandel | ||
derive instance geFruit :: Generic Fruit _ | ||
instance eFruit :: Encode Fruit where | ||
encode = genericEncodeEnum defaultGenericEnumOptions | ||
#### `GenericDecodeEnum` | ||
``` purescript | ||
class GenericDecodeEnum a where | ||
decodeEnum :: GenericEnumOptions -> Foreign -> F a | ||
``` | ||
|
||
A type class for type representations that can be used for decoding to an Enum. Only the sum and no-argument constructor instances are valid, while others provide a `Fail` constraint to fail in compilation. | ||
|
||
For example: | ||
|
||
```purescript | ||
data Fruit = Apple | Banana | Frikandel | ||
derive instance geFruit :: Generic Fruit _ | ||
instance dFruit :: Decode Fruit where | ||
decode = genericDecodeEnum defaultGenericEnumOptions | ||
``` | ||
|
||
##### Instances | ||
``` purescript | ||
(GenericDecodeEnum a, GenericDecodeEnum b) => GenericDecodeEnum (Sum a b) | ||
(IsSymbol name) => GenericDecodeEnum (Constructor name NoArguments) | ||
(Fail "genericEncode/DecodeEnum cannot be used on types that are not sums of constructors with no arguments.") => GenericDecodeEnum (Constructor name (Argument a)) | ||
(Fail "genericEncode/DecodeEnum cannot be used on types that are not sums of constructors with no arguments.") => GenericDecodeEnum (Constructor name (Product a b)) | ||
(Fail "genericEncode/DecodeEnum cannot be used on types that are not sums of constructors with no arguments.") => GenericDecodeEnum (Constructor name (Rec a)) | ||
``` | ||
|
||
#### `GenericEncodeEnum` | ||
|
||
``` purescript | ||
class GenericEncodeEnum a where | ||
encodeEnum :: GenericEnumOptions -> a -> Foreign | ||
``` | ||
|
||
A type class for type representations that can be used for encoding from an Enum. Only the sum and no-argument constructor instances are valid, while others provide a `Fail` constraint to fail in compilation. | ||
|
||
##### Instances | ||
``` purescript | ||
(GenericEncodeEnum a, GenericEncodeEnum b) => GenericEncodeEnum (Sum a b) | ||
(IsSymbol name) => GenericEncodeEnum (Constructor name NoArguments) | ||
(Fail "genericEncode/DecodeEnum cannot be used on types that are not sums of constructors with no arguments.") => GenericEncodeEnum (Constructor name (Argument a)) | ||
(Fail "genericEncode/DecodeEnum cannot be used on types that are not sums of constructors with no arguments.") => GenericEncodeEnum (Constructor name (Product a b)) | ||
(Fail "genericEncode/DecodeEnum cannot be used on types that are not sums of constructors with no arguments.") => GenericEncodeEnum (Constructor name (Rec a)) | ||
``` | ||
|
||
|
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,19 @@ | ||
## Module Data.Foreign.Internal | ||
|
||
#### `isStrMap` | ||
|
||
``` purescript | ||
isStrMap :: Foreign -> Boolean | ||
``` | ||
|
||
Test whether a foreign value is a dictionary | ||
|
||
#### `readStrMap` | ||
|
||
``` purescript | ||
readStrMap :: Foreign -> F (StrMap Foreign) | ||
``` | ||
|
||
Attempt to coerce a foreign value to a StrMap | ||
|
||
|
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
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