GithubHelp home page GithubHelp logo

purescript-refs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

purescript-refs's Issues

Eq instance?

I think it wouldn't be hard to do an Eq instance for Ref right? Would you be open to a pull request?

Return value from writeRef and modifyRef

Preempted by purescript/purescript-st#4:

modifySTRef :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
modifyRef   :: forall s   r.   Ref   s -> (s -> s) -> Eff (ref :: REF | r) Unit

In particular the current behavior of modifyRef' strangely returns an arbitrary value not what's stored.

Expose EffectFn variants

I think it would be good to export uncurried variants of the operations for cases where we want to forgo the overhead of currying.

Is `newRef` actually effectful?

I've bumped into a few cases where it would be really handy to be able to construct a Ref outside of Eff - it seems to me that reading and writing a ref are definitely effectful, but creating one isn't necessarily so. Thoughts?

Do you see value in a Ref-Monad like State?

I am using purescript for a canvas-based web app and don't need any fancy UI library. I end up with a lean, global application state and deal with events quite bare-footed.

I find myself writing

app <- read refAppState
flip write refAppState $
    app { foo = newFoo
        , bar = app.bar + 1
        }

quite a lot.

If you don't object, I'll come up with a pull request soon to allow to write the above via a monad for effectfull, global state:

foo .= newFoo
bar += 1

I miss the lenses :)

Also, maybe you have a suggestion for the module name.

How about Effect.Ref.Monad? Alternatively Control.Monad.State.Global.

Operators for writeRef and modifyRef

Mimicing Lens:

(.=) = writeRef
(%=) = modifyRef
(%%=) = modifyRef`

In practice looks like:

nextEvent counter payload = do
  count <- getRef counter
  counter %= (_ + 1)
  pure (Event (payload {id = count}))

Just wondered if it might be generally useful?

Expand newWithSelf documentation

The function passed to newWithSelf should not read or write to the reference it's passed, though it may create closures that will eventually do so. This restriction is not documented.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.