FP-inspired prelude/standard library for ReasonML projects
Relude.Js.Promise.fromIOWithResult
- converts an IO.t('a, 'e)
to a Js.Promise.t(result('a, 'e))
so the error type remains polymorphicTreeZipper.findInFocusAndChildren
#253Belt.Result.t('a, 'e)
with the built-in result('a, 'e)
TreeZipper.moveUp
where the leftSiblings
ordering was being mishandled #248This release updates the underlying bs-abstract
dependency to 1.0 and allows Relude to compile with Bucklescript 7.1+.
Array.empty
has been removed, as its type is no longer array('a)
, but it now introduces weak polymorphism. Bucklescript made this change to work around unsoundness issues with Js.Array.push
. You can read more about this change on the Bucklescript blog and the related bs-abstract issue.empty
, Array no longer implements MONOID_ANY
, PLUS
, ALTERNATIVE
, MONAD_ZERO
, and MONAD_PLUS
.Relude.NonEmpty
now does not require some of these typeclass instances (and instead uses a lazy () => t('a)
empty function). This actually makes NonEmpty
easier to construct.Fold_Map_Any
and Fold_Map_Plus
are now more flexible, allowing you to map both the container type and the inner type.mapHandleError
function to Result
and IO
x |> map(f) |> handleError(g)
Ior
to remove success/fail semantics, and make it more general purposeBefore this PR, Ior
had constructors IOk('a)
, IError('e)
, and IBoth('a, 'e)
, but this makes the type more semantic, and less useful for the purposes below. I changed the constructors to This('a)
, That('b)
, and Both('a, 'b)
. This still allows for success/fail semantics (This
being success, and That
being failure), but it also allows the type to be used for less-semantic things, like ALIGN
.
This was a breaking change in Ior
, but should be easy to fix - just rename IOk
to This
, IError
to That
, and IBoth
to Both
(and other similar name changes).
Ior
catThis
, catThat
, merge
, fold
, etc. - see files changedSEMIALIGN
and ALIGN
typeclassesmodule type SEMIALIGN = {
include BsAbstract.Interface.FUNCTOR;
let align: (t('a), t('b)) => t(Relude_Ior_Type.t('a, 'b));
let alignWith: (Relude_Ior_Type.t('a, 'b) => 'c, t('a), t('b)) => t('c);
};
module type ALIGN = {
include SEMIALIGN;
let nil: t('a);
};
These are quite similar to the APPLY
and APPLICATIVE
typeclasses (and also similar to SEMIGROUP
/MONOID
), but they have some interesting uses that you can't get with APPLY
.
One use of these is that they allow you to compose two effectful values, and will capture a successful result if either or both sides succeed. This is similar to apply
, but apply
fails if either side fails, whereas align
will only fail if both sides fail. The result of align
is captured in an Ior
, which has constructors for This('a)
, That('b)
, or Both('a 'b)
.
Another use of these is for zipping values together with the ability to fill in default values. Some of these helper functions have not yet been implemented, but you can see some here: https://hackage.haskell.org/package/semialign-1.1/docs/Data-Align.html#g:1
See Haskell, Scala cats/scalaz, and purescript resources for other info on Align
.
align
and alignWith
functions to various typesOption
Result
Validation
IO
SEMIALIGN
and ALIGN
instancesOption
- Semialign
and Align
Result.WithError
- Semialign
(with fail-fast error semantics)Validation.WithErrors
- Semialign
(with error collecting semantics)IO.WithError
- Semialign
SEMIALIGN
and ALIGN
These are empty placeholders for now, but would likely be the place to add some of the zip helpers
Ior
had some renames described aboveBifunctor
isntance was moved to the top-level of IO
rather than being inside the WithError
module functorFloat.top
and Float.bottom
now use min_float
and max_float
as determined by Bucklescript. Previously this was based on JS-specific bindings to Number.MIN_VALUE
.String.charAtOrEmpty
works like charAt
but gives you ""
if the provided index is out of range (instead of having to worry about option
)String.charCodeAt
works similarly to the Js.String
equivalent from Bucklescript, but it returns an option(int)
instead of a float
that could be NaNFloat.isNaN
lets you determine if a floating point value is the nan
valueFloat.nan
, Float.infinity
, and Float.negativeInfinity
values, so you don't have to rely on the globally-available values from PervasivesremoveAt
to List
and Array
#226fromList
, fromArray
, and reverse
to NonEmpty
, which consequently adds them to NonEmpty.List
and NonEmpty.Array
errorNel
and errorNea
to Validation
to lift a single error into a VError
containing a Nel
/Nea
Relude_Free_Applicative
module
Relude_Interface.ARROW
and ARROW_F
to FUNCTION_1
and FUNCTION_1_F
Bifunctor
and Bifoldable
modules outside the WithError
functor for Result
(they didn't need to be inside the WithError
context)