{"id":17791221,"url":"https://github.com/schell/varying","last_synced_at":"2025-03-16T15:31:32.610Z","repository":{"id":31549687,"uuid":"35114326","full_name":"schell/varying","owner":"schell","description":"Continuously varying values, made easy :)","archived":false,"fork":false,"pushed_at":"2019-10-21T15:53:02.000Z","size":353,"stargazers_count":40,"open_issues_count":0,"forks_count":5,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-05T06:48:48.206Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/schell.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-05T17:36:41.000Z","updated_at":"2024-03-29T19:45:11.000Z","dependencies_parsed_at":"2022-08-20T13:00:40.258Z","dependency_job_id":null,"html_url":"https://github.com/schell/varying","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schell%2Fvarying","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schell%2Fvarying/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schell%2Fvarying/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schell%2Fvarying/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schell","download_url":"https://codeload.github.com/schell/varying/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221665390,"owners_count":16860238,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-27T10:50:18.229Z","updated_at":"2024-10-27T10:50:18.788Z","avatar_url":"https://github.com/schell.png","language":"Haskell","readme":"# varying\n[![Hackage](https://img.shields.io/hackage/v/varying.svg)](http://hackage.haskell.org/package/varying)\n[![Build Status](https://gitlab.com/schell/varying/badges/master/build.svg)](https://gitlab.com/schell/varying)\n\nThis library provides automaton based value streams and sequencing useful for\nfunctional reactive programming (FRP) and locally stateful programming (LSP).\n\n\n## Getting started\n\n```haskell\nmodule Main where\n\nimport Control.Varying\nimport Control.Applicative\nimport Control.Concurrent (forkIO, killThread)\nimport Data.Functor.Identity\nimport Data.Time.Clock\n\n-- | A simple 2d point type.\ndata Point = Point { px :: Float\n                   , py :: Float\n                   } deriving (Show, Eq)\n\nnewtype Delta = Delta { unDelta :: Float }\n\n-- An exponential tween back and forth from 0 to 50 over 1 seconds that\n-- loops forever. This spline takes float values of delta time as input,\n-- outputs the current x value at every step.\ntweenx :: Monad m =\u003e TweenT Float Float m Float\ntweenx = do\n    -- Tween from 0 to 50 over 1 second\n    tween_ easeOutExpo 0 50 1\n    -- Chain another tween back to the starting position\n    tween_ easeOutExpo 50 0 1\n    -- Loop forever\n    tweenx\n\n-- An exponential tween back and forth from 0 to 50 over 1 seconds that never\n-- ends.\ntweeny :: Monad m =\u003e TweenT Float Float m Float\ntweeny = do\n    tween_ easeOutExpo 50 0 1\n    tween_ easeOutExpo 0 50 1\n    tweeny\n\n-- Our time signal counts input delta time samples.\ntime :: Monad m =\u003e VarT m Delta Float\ntime = var unDelta\n\n-- | Our Point value that varies over time continuously in x and y.\nbackAndForth :: Monad m =\u003e VarT m Delta Point\nbackAndForth =\n    -- Turn our splines into continuous output streams. We must provide\n    -- a starting value since splines are not guaranteed to be defined at\n    -- their edges.\n    let x = tweenStream tweenx 0\n        y = tweenStream tweeny 0\n    in\n    -- Construct a varying Point that takes time as an input.\n    (Point \u003c$\u003e x \u003c*\u003e y)\n        -- Stream in a time signal using the 'plug left' combinator.\n        -- We could similarly use the 'plug right' (~\u003e) function\n        -- and put the time signal before the construction above. This is needed\n        -- because the tween streams take time as an input.\n        \u003c~ time\n\nmain :: IO ()\nmain = do\n    putStrLn \"An example of value streams using the varying library.\"\n    putStrLn \"Enter a newline to continue, and then a newline to quit\"\n    _ \u003c- getLine\n\n    t   \u003c- getCurrentTime\n    tId \u003c- forkIO $ loop backAndForth t\n\n    _ \u003c- getLine\n    killThread tId\n\nloop :: Var Delta Point -\u003e UTCTime -\u003e IO ()\nloop v t = do\n  t1 \u003c- getCurrentTime\n  -- Here we'll run in the Identity monad using a time delta provided by\n  -- getCurrentTime and diffUTCTime.\n  let dt = realToFrac $ diffUTCTime t1 t\n      Identity (Point x y, vNext) = runVarT v $ Delta dt\n      xStr = replicate (round x) ' ' ++ \"x\" ++ replicate (50 - round x) ' '\n      yStr = replicate (round y) ' ' ++ \"y\" ++ replicate (50 - round y) ' '\n      str  = zipWith f xStr yStr\n      f 'x' 'y' = '|'\n      f 'y' 'x' = '|'\n      f a ' ' = a\n      f ' ' b = b\n      f _ _ = ' '\n  putStrLn str\n  loop vNext t1\n```\n\n# Publications\n\nThe concept of `VarT` that this library is built on is isomorphic to Monadic Stream Functions as defined in \"[Functional Reactive Programming, Refactored](http://dl.acm.org/citation.cfm?id=2976010)\" ([mirror](http://www.cs.nott.ac.uk/~psxip1/#FRPRefactored)).\n\nThe isomorphism is\n``` haskell\ntoMSF :: Functor m =\u003e VarT m a b -\u003e MSF m a b\ntoMSF = MSF . (fmap . fmap . fmap $ toMSF) . runVarT\n\ntoVarT :: Functor m =\u003e MSF m a b -\u003e VarT m a b\ntoVarT = VarT . (fmap . fmap . fmap $ toVarT) . unMSF\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschell%2Fvarying","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschell%2Fvarying","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschell%2Fvarying/lists"}