Data.Foreign
- Package
- purescript-foreign
- Repository
- purescript/purescript-foreign
This module defines types and functions for working with foreign data.
#Foreign Source
data Foreign :: Type
A type for foreign data.
Foreign data is data from any external unknown or unreliable source, for which it cannot be guaranteed that the runtime representation conforms to that of any particular type.
Suitable applications of Foreign
are
- To represent responses from web services
- To integrate with external JavaScript libraries.
#ForeignError Source
data ForeignError
A type for foreign type errors
Constructors
ForeignError String
TypeMismatch String String
ErrorAtIndex Int ForeignError
ErrorAtProperty String ForeignError
JSONError String
Instances
#MultipleErrors Source
type MultipleErrors = NonEmptyList ForeignError
A type for accumulating multiple ForeignError
s.
#F Source
type F = Except MultipleErrors
An error monad, used in this library to encode possible failures when dealing with foreign data.
The Alt
instance for Except
allows us to accumulate errors,
unlike Either
, which preserves only the last error.
#unsafeFromForeign Source
unsafeFromForeign :: forall a. Foreign -> a
Unsafely coerce a Foreign
value.
#unsafeReadTagged Source
unsafeReadTagged :: forall a. String -> Foreign -> F a
Unsafely coerce a Foreign
value when the value has a particular tagOf
value.
#isUndefined Source
isUndefined :: Foreign -> Boolean
Test whether a foreign value is undefined
#readBoolean Source
readBoolean :: Foreign -> F Boolean
Attempt to coerce a foreign value to a Boolean
.
#fail Source
fail :: forall a. ForeignError -> F a
Throws a failure error in F
.