MonadError, MonadZero, and Unfoldable
texastoland opened this issue · 0 comments
MonadError
Direct port from PureScript Prelude (that's a good criteria for inclusion) with tests for any relevant laws from the ErrorControl
article. That version isn't idiomatic OCaml and will be superseded by algebraic effects. I could see it in a future version of bs-effects however. See more in janestreet/ppx_let#8 (comment).
MonadZero
Direct port from PureScript Prelude. The primary use case is filtering list/array comprehensions.
let factors n ->
let%bind a = 0 -- n
let%bind b = 0 -- a
let%bind () = guard(a * b == n)
(a, b)
Unfoldable
and generic --
Direct port from purescript-unfoldable (related to Foldable
in bs-abstract). PureScript implements a generic range
for Unfoldable1
and ..
operator for specialized versions. It might be nice to specialize for arrays and lists but we should benchmark if so. Belt also implements range
for arrays (but not lists). The operator (inspired by Batteries) is simply let (--) = Belt.Array.range
.