Package

purescript-return

Repository
ursi/purescript-return
License
BSD-3-Clause
Uploaded by
ursi
Published on
2021-04-05

Return introduces a new data type

data Return a
  = Cont a
  | Return a

and a function

mkReturnable ::  a. ((Return a -> a) -> a) -> a

Using mkReturnable you can create functions that "return" values early in a way that you normally would have to use explicit recursion to accomplish.

For example:

foldl' ::  a b f. Foldable f => (b -> a -> Return b) -> b -> f a -> b
foldl' f init as = mkReturnable \return -> foldl (\b a -> return $ f b a) init as

This is nice because it allows for you to define, for fee, folds that can exit early for anything that already has a Foldable instance, instead of having to use recursion to handle each case differently.

Modules
Return
Return.Folds
Dependencies