Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code examples in the documentation don't return what's expected #240

Open
piotr-yuxuan opened this issue Apr 18, 2020 · 0 comments
Open

Comments

@piotr-yuxuan
Copy link

Versions used:

  • [org.clojure/clojure "1.10.1"]
  • [funcool/cats "2.3.6"]
  • [funcool/promesa "5.1.0"]

ns form:

(ns user
  (:require
    [cats.builtin]
    [cats.core :refer [bind return alet mlet fmap fapply]]
    [cats.monad.maybe :refer [just]]
    [cats.labs.promise]
    [promesa.core :as p]))

When evaluating the examples provided in https://funcool.github.io/cats/latest/#alet, some results don't match what is shown in the doc:

(macroexpand '(alet [a (just 1)
                     b (just 41)]
                (+ a b)))
;; =>
(fapply
  (fmap
    (fn [a]
      (fn [b]
        (do (+ a b))))
    (just 1))
  (just 41))

;; the documentation suggests it returns:
(fapply (fn [a]
          (fn [b]
            (do
              (+ a b))))
        (just 1)
        (just 41))

The asynchronous code raises an exception:

(defn sleep-promise
  "A simple function that emulates an
  asynchronous operation."
  [wait]
  (p/promise (fn [resolve reject]
               (future
                 (Thread/sleep wait)
                 (resolve wait)))))

(time
  @(mlet [x (sleep-promise 42)
          y (sleep-promise 41)]
         (return (+ x y))))
;; Execution error (ClassCastException) at user/eval34213$fn$fn (user.clj:4).
;; class user$sleep_promise$fn__34206 cannot be cast to class java.lang.Number (user$sleep_promise$fn__34206 is in unnamed module of loader clojure.lang.DynamicClassLoader @571ca823; java.lang.Number is in module java.base of loader 'bootstrap')

Anyway thanks for the work already done on this library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant