GithubHelp home page GithubHelp logo

fell's Introduction

Fell

Freer monads for Clojure and funcool/cats based on Freer Monads, More Extensible Effects and Effect Handlers in Scope.

Usage

Don't.

(ns fell.example
  (:require [cats.core :refer [mlet return]]
            [fell.core :as fell :refer [request-eff]]
            [fell.reader :as r]
            [fell.state :as state]))

;; Workaround for lack of parametric modules.
;; Could use singletons instead, but fn usages would be more verbose.
(let [{ask :ask, run-reader :run} (r/make ::reader)]
  (def ask ask)
  (def run-reader run-reader))

(let [{get-counter :get, set-counter :set, run-counter :run} (state/make ::counter)]
  (def get-counter get-counter)
  (def set-counter set-counter)
  (def run-counter run-counter))

(let [{get-status :get, set-status :set, run-status :run} (state/make ::status)]
  (def get-status get-status)
  (def set-status set-status)
  (def run-status run-status))

(def stateful-computation
  (mlet [initial-status get-status
         counter get-counter
         increment ask
         _ (set-counter (+ counter increment))
         counter* get-counter
         _ (set-status (str "Energy: " counter))]
    (return initial-status)))

(-> stateful-computation
    (run-counter 8)
    (run-reader 17)
    (run-status "Asleep")
    fell/run) ;=> #<Pair ["Energy: 8" #<Pair [25 "Asleep"]>]>

TODO

  • More tests
  • API (and internal naming) design and refactoring
  • More effects (e.g. bracket, threading)
  • Documentation
  • Performance optimization
  • Tail call "optimization"

License

Copyright © 2019 Pauli Jaakkola

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

fell's People

Contributors

nilern avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

fell's Issues

Tail Call Optimization

JVM monads have space issues. Although since Clojure does not have TCO anyway, maybe some sort of mloop macro would suffice?

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.