Git Product home page Git Product logo

cats's Issues

[question]: Context and ContextClass protocols naming.

I would open a discussion for the Context and ContextClass protocol naming.

The last one (ContextClass) is introduced for identify the types that represent the context. And Context protocol exists for make the relation between the context type (now backed by ContextClass) and the concrete type, example: Just or Nothing.

As we know, at this moment the macro used for set up the context is with-context.

Having that in mind, that are the questions here:

  • It make sense the ContextClass protocol name for identify a context? Maybe it should be named Context? seems to be more semantic.
  • It make sense the Context class for identify the types that are related to some context? (in fact them are not context object). May be this protocol should be called Contextual or ContextAware or something similar?

Recommendation to adjust documentation of fmap

Now that I'm actually reading the documentation, I wonder if this shouldn't be reworded altogether (emphasis mine):

"The main difference compared to the previous example with Clojure’s map function, is that map works with seqs and doesn’t respect the input container:

(map inc [1 2 3])
;; => (2 3 4)

But why does the fmap version "work" with vectors? Because some Clojure container types like vectors, lists, and sets also implement the functor abstraction."

But really the notion of "works" is subjective because one could argue that the map version "works" by returning a lazy sequence, whereas fmap on a vector doesn't "work" (or works too hard!) because it realizes the entire mapped sequence. One can imagine situations where you would want one over the other and vice-versa.

Perhaps instead of using the tricky word "works" the differences should merely be highlighted?

fmap or fapply with vararg?...and small question

Hi...I'm not sure but I think than fmap or fapply must accept vararg ...

in haskell you can do

ghci> pure (+) <*> Just 3 <*> Just 3
Just 6

in fluokitten you can do

(fmap * (just 5) (just 3))
;=> (just 15)

but I can't find how do it in cats avoiding nesting fmaps (maybe I'm missing something)

  1. I've a code with channels where they can return a maybe type...which could be the best way of handle it, would be cool use mlet but I'm not sure if it's possible, just now I've
defn return-nothing []
   (let [c (a/chan 1)]
      (a/go (a/>! c nothing))
      c))

(defn return-just [v]
   (let [c (a/chan 1)]
      (a/go (a/>! c (just v)))
      c))


a/go(
 (let 
   [a (return-just 3)
   b  (fmap return-just (fmap (partial / 2) a))]
  (...)
)

Helpers for ensuring that values are wrapped in a certain type

The counterparts of fns like from-maybe, take a value and ensure that they are wrapped in the correct type.

An example of how it'd behave for Maybe:

(require '[cats.monad.maybe :as maybe])

(maybe/to-maybe (maybe/just 42))
;; => #<Just 42>

(maybe/to-maybe 3)
;; => #<Just 3>

(maybe/to-maybe nil)
;; => #<Nothing>

(maybe/to-maybe (maybe/nothing))
;; => #<Nothing>

composing applicatives

i would like to compose applicatives for use with alet

i gather that this is achievable generically and doesn't require applicative transformers for each applicative type... though i can't find anything in cats atm

does there need to be something in cats which reifies a context for such a composed applicative ?

Deploy new JAR

I tried to use foldm the other day but it wasn't in the deployed JAR. By making this issue, I'm requesting a new deployment as soon as is agreeable.

js error on extend-type cljs.core.IFn

TypeError: Cannot set property 'cats$protocols$Contextual$' of undefined happens on evaluating this form:

(extend-type #?(:clj clojure.lang.IFn
                :cljs cljs.core.IFn)
  p/Contextual
  (-get-context [_] function-context))

More built-in monoids

  • Numbers
  • Sum
  • Prod
  • Booleans
  • Any
  • All
  • Others
  • Strings under concatentation
  • cats.data#Pair

Map implementation of Functor

Map's implementation of Functor does not do what I'd expect:

p/Functor
(-fmap [_ f v]
  (into {} (map f v)))

It passes the map entries to f. Not just the values. The clojure.algo.generic implementation, and the Haskell implementation in Data.Map would look something like this:

p/Functor
(-fmap [_ f v]
  (into {} (map (fn [[key val]] [key (f val)]) v)))

I.e. the keys remain unchanged and f is applied to the values only. This is an example of how I would expect it to work:

=> (fmap inc {:a 1 :b 2})
{:a 2 :b 3}

Why is it not implemented way?

mapseq on an empty collection throws assertion failure

(m/mapseq #(e/right (* % 2)) [])
AssertionError Assert failed: (not-empty mvs)  cats.core/sequence (core.cljc:540)

I'm pretty sure this assertion is in error – If I have a context that is mappable but empty, it should return a similar empty context.

Error following the tutorial

I have a little bit of familiarity with monads from Scala, but was interested in trying them with Clojure. Have set [funcool/cats "1.2.0"] in my project.clj (although have the same problem with other versions). I tried the first two lines of the tutorial in my REPL:

(require '[cats.core :as m])
(m/mappend [1 2 3] [4 5 6])

And got the following back:

IllegalArgumentException No context is set and it can not be automatically resolved. sun.reflect.NativeConstructorAccessorImpl.newInstance0 (NativeConstructorAccessorImpl.java:-2)

At this point my worse nightmare of monadic abstractions is realised :-( I am only two lines into the tutorial and I already have an incomprehensible error message.

But seriously, not sure if I am making a mistake, there is a bug in the code, a step missing in the tutorial etc.

Different alet evaluation strategy

Right now alet will batch applicative value evaluations in the order they are written. This is the best default since the operation being performed might depend on ordering.

For cases where ordering is not important (for example when performing asynchronous read operations) it'd be nice to be able to tell alet, since it might be able to optimize further.

The inner and base monads of a transformer

I've been reading about Haskell's monad transformers to clarify my understanding of the base and inner monad concepts.

[...] we will use base monad to refer to the non-transformer monad on which a transformer is based and inner monad to refer to the other monad on which the transformer is applied.

As we can see, in the Haskell implementation of transformers the 'inner' monad ends up in the transformer's type in different ways (I've added MaybeT):

Base Monad Transformer Original Type
("wrapped" by base)
Combined Type
("wrapped" by transformed)
Maybe MaybeT a m (Maybe a)
Writer WriterT (a, w) m (a, w)
Reader ReaderT r -> a r -> m a
State StateT s -> (a, s) s -> m (a, s)
Cont ContT (a -> r) -> r (a -> m r) -> m r

In the MaybeT and WriterT the resulting transformer instances end up having the 'inner' monad as the outermost wrapper. In the ReaderT and StateT case, the result of the functions ends up being an instance of the 'inner' monad.

I guess 'inner' is not the best name to describe a monad that a transformer wraps; the resulting type is what makes more sense for the 'base' monad, which doesn't have the 'inner' monad as the innermost wrapper.

(m/fmap inc [1 2 3]) => IllegalArgumentException

Forgive me if I'm misunderstanding something basic, I've only just begun reading the Cats Documentation.

Under the 5.1 Functor section, there is an example of applying fmap to a vector that is raising an exception for me:

user=> (m/fmap inc (maybe/just 1))
#<Just@4b00df11: 2>
user=> (m/fmap inc [1 2 3])
IllegalArgumentException You are using return/pure/mzero function without context.  cats.core/get-current-context (core.clj:63)

Any help appreciated.

Thanks,
Sean

Conditional protocol implementation for monad transformers

It'd be great if we can implement some protocols conditionally when constructing a monad transformer. For example, in the state monad transformer we'd want to make the transformer instance of MonadZero or MonadPlus iif the inner monad is an instance of those.

Same goes for MonadWriter, MonadReader and MonadState. In a transformer, if the inner monad is an instance of those the outer monad can be made one too, and the functions from those protocols can be used in the resulting transformer.

Manifold Stream support.

Currently cats supports on its cats.labs namespace already supports manifold deferreds and core.async channels. Would be awesome to have also support for manifold streams under cats.labs.manifold namespace.

Documentation error

Possible minor error in the documentation:

The main difference between foldl and reduce is that foldl has a fixed arity so all parameters are mandatory and foldl is a generic abstraction that can work with other types apart from collections.

should be

The main difference between foldl and reduce is that reduce has a fixed arity so all parameters are mandatory and foldl is a generic abstraction that can work with other types apart from collections.

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.