Foreign
- Package
- purescript-foreign
- Repository
- purescript/purescript-foreign
This module defines types and functions for working with foreign data.
#Foreign Source
data Foreign :: TypeA 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 ForeignErrorA type for foreign type errors
Constructors
ForeignError StringTypeMismatch String StringErrorAtIndex Int ForeignErrorErrorAtProperty String ForeignError
Instances
#MultipleErrors Source
type MultipleErrors = NonEmptyList ForeignErrorA type for accumulating multiple ForeignErrors.
#F Source
type F = Except MultipleErrorsAn 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.
#FT Source
type FT = ExceptT MultipleErrors#unsafeToForeign Source
unsafeToForeign :: forall a. a -> ForeignCoerce any value to the a Foreign value.
This is considered unsafe as it's only intended to be used on primitive JavaScript types, rather than PureScript types. Exporting PureScript values via the FFI can be dangerous as they can be mutated by code outside the PureScript program, resulting in difficult to diagnose problems elsewhere.
#unsafeFromForeign Source
unsafeFromForeign :: forall a. Foreign -> aUnsafely coerce a Foreign value.
#unsafeReadTagged Source
unsafeReadTagged :: forall m a. Monad m => String -> Foreign -> FT m aUnsafely coerce a Foreign value when the value has a particular tagOf
value.
#isUndefined Source
isUndefined :: Foreign -> BooleanTest whether a foreign value is undefined
#readString Source
readString :: forall m. Monad m => Foreign -> FT m StringAttempt to coerce a foreign value to a String.
#readBoolean Source
readBoolean :: forall m. Monad m => Foreign -> FT m BooleanAttempt to coerce a foreign value to a Boolean.
#readNumber Source
readNumber :: forall m. Monad m => Foreign -> FT m NumberAttempt to coerce a foreign value to a Number.
- Modules
- Foreign
- Foreign.
Index - Foreign.
Keys