This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-06-18
Channels
- # admin-announcements (10)
- # boot (260)
- # cider (44)
- # clojure (226)
- # clojure-berlin (24)
- # clojure-dev (68)
- # clojure-germany (5)
- # clojure-india (14)
- # clojure-italy (3)
- # clojure-japan (21)
- # clojure-poland (34)
- # clojure-russia (20)
- # clojure-spain (2)
- # clojure-uk (8)
- # clojurescript (86)
- # core-async (38)
- # core-typed (70)
- # datomic (41)
- # docs (8)
- # editors (7)
- # euroclojure (6)
- # instaparse (2)
- # jobs (8)
- # ldnclj (47)
- # om (17)
- # other-lisps (1)
- # reactive (1)
- # reading-clojure (8)
- # reagent (13)
- # sneer (1)
- # sneer-br (1)
I'd appreciate if anybody could help me with a core.typed
question... just starting out so it may be a bit obvious.
Why does (IPersistentMap Integer myapp.core/Thing) Integer
not match (t/Option (ILookup t/Any x)) t/Any
do I need to explicitly lift the map into the Option
type?
There are probably more people able to help with that in the #C051QCQUF channel.
I feel like manifold.stream/throttle
doesn’t work how I thought it would: https://gist.github.com/ottbot/f2ffc9b8abbb64dac1dd
@ulsa: did you see I released the thing as a library now? found a different approach to solving the class loader issue
@ulsa: cool, thanks for giving it a go... i think there might be room for an additional, slighly higher level interface that deals with the json parsing, as that's will likely be the most common way of using lambda
@ulsa: instead of dealing with streams, you could provide a fn from (map, context) -> map
, and lambada could do the json deserialization/serialization
And, there's this: http://rundis.github.io/blog/2015/buddy_auth_part1.html
Hi, guys! what is the most popular Clojure library to deal with functor/monads? I know that there’re algo.monads
& cats
& few others, just curious which one is more useful/helpful/popular
@kachayev: Fluokitten looks very, very complete: http://fluokitten.uncomplicate.org
@aengelberg: what keeps you on Clojure 1.6?
@kachayev: I found https://github.com/bwo/monads much more natural for me than algo.monads where the implicit return in the do-monad body kept getting in my way (if i remember correctly). though i’m far from an experienced monadicist. bwo/monads hasn’t been touched for a while either
@kachayev: author of cats
here, AFAIK is the only one that supports both Clojure & ClojureScript in case you need that
see http://funcool.github.io/cats/latest/#_rationale for the reasons we wrote yet another monad library
actually, just now I’m looking for a library to cleanup server-side code (with many ad-hoc implementations for functor-like flows). no plans for ClojureScript, maybe in future
cats looks pretty cool
yep certainly does - guess I’m now looking to alias >>= back to bind and come up with some cunning way of turning haskelly mdos into mlets...
happy to contribute too, I wrote a similar thing for Ruby (https://github.com/txus/kleisli) and I miss all this stuff in Clojure!
the main problem with mlet
is that most probably you will "get it” if you know Haskell do-notation, otherwise it’s not that simple to get the idea behind it. and if you know do-notation, most probably, it’s ok for you to see >>=
in code
@kachayev: yep, but the docs show what pattern mlet
captures. it starts showing de desugared way of chaining computations and refactors it to mlet
I quite liked the approach in http://adambard.com/blog/five-mistakes-clojure-newbies-make/ (using attempt-all, which I think is based on algo.monad)
@kachayev: not sure i understand your question, you mean that if mlet
could use for
for sequence comprehensions?
Scala use the same syntax for sequences and monads with for…yield
. which is really convenient
you can use some built-in Clojure types with mlet
, lazy sequences should be equivalent to for
in a mlet
it’d be great to verify correctness, and also very handy for its users if they use core.typed
I've thought about it and I'd love to annotate the library, if you give it a shot it'd be very welcome
Anybody got tips on rendering PDF from a clojure ring based site (similar to wicked in Rails)?
definitely, sounds like a good excuse to get my hands dirty with core.typed on a real project 😄
I thought about this too (not for cats, but in general) and did not do it, because, you need the commitment of any maintainer and commiter to that library to fix the annotations if the API changes / new functions got added
well, the properties you can prove with core.typed can save you loads of unit tests — which need maintaining as well, so you’d probably save maintaining effort in the long run @sveri
@txus: That's why I use core.typed occaisonally on my own projects, no need to convince me 😉 We just have to start convincing library authors
nothing more convincing than a PR with a bunch of annotations and some unit-tests removed
borkdude: you could just generate an html file using hiccup and then shell out to wkhtmltopdf to turn it into pdf
looks like somebody already did just that: https://github.com/pdfkit/pdfkit-clj
@txus: @dialelo is there a thing I could read to get a better idea about functors/monads and what I’d use them for?
@martinklepsch: definitely, I got a few good bookmarks, gimme a sec
http://www.leonardoborges.com/writings/2012/11/30/monads-in-small-bites-part-i-functors/
http://www.leonardoborges.com/writings/2012/12/05/monads-in-small-bites-part-iii-monoids/
@martinklepsch: these 4 are really good to get started
and this one is very good as well: http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
@martinklepsch: @txus great recommendations, after that cats' docs should make more sense
@txus: that does look useful
@txus: thanks!
thanks to @leonardoborges for writing it 😄
Deep technical question about cats
library: how can I specify return/pure/mzero context
for any record/type that satisfies given protocol?
also, return
and mzero
have two arities and they accept an optional first parameter with the context
also, for having your own types work seamlesly in mlet
blocks you can tell cats
their context https://github.com/funcool/cats/blob/master/src/cats/monad/maybe.cljc#L46
my problem is that I’m working on library that works with records/types provided (not only own)
As cats implements everything using protocols, use third party types should not be a problem
I ran into a strange issue with AOT compilation — I have a Compojure-api app that runs fine, but when AOTing I get: unable to resolve symbol: missing-required-key in this context
in the middle of the DSL. There’s absolutely no missing-required-key
anywhere, even after macroexpanding, or in the compojure-api or ring-swagger codebase 😞
missing-require-keys: that sounds like prismatc schema, no?
missing-required-key, that is
@kachayev: so you want to receive values from types you don't own and make them participate in some of the cats
abstractions without them implementing the protocols? I'm not sure I understand your question
library that I’m working on helps you work efficiently with remote data sources, and implementation is based on the idea of building declarative AST of everything that you need to fetch from different sources and all functions that you want to apply to the results
@pesterhazy: nice, thanks
user have to define only how to fetch data from remote source, using simple DataSource
protocol with a single function (fetch [_] _)
I want to make it compatible with mlet/mreturn
syntax, and you can see what I did (I defined ast-monad
and updated all AST nodes implementations)
kachayev: I saw muse
the other day
and now you can you cats.core/fmap
with any AST node, but you can’t do this with your DataSource
(only with this value
modifier)
it looked interesting, but I couldn't really understand what it does
@pesterhazy: i’m working on better examples!
that would be great
@kachayev: yes, you are right, user defined datasource will not play in cats abstraction
actually transparently grabbing input data from remote locations is a problem I have very often
so from the description it sounds awesome
@pesterhazy: me too. that’s why I built a library for it
hmm, but I'm not clearly known how we can solve this problem. Maybe a greeat workaround is provide some kind of adapter
some function that takes a used defined datasource and return muse defined type that already implements all necesary protocols
@niwinz: yeah, as I wrote in the example you can use muse/value
that will create a simplest AST node with your input
it would be nice to be able to extend cats.core/get-current-context
function somehow...
Anyone have recommendations for interacting with a SOAP service? Looks like clj-soap is no longer maintained.
@txus: It is best to avoid AOT with Compojure-api. It is doing too much macro magic.
Related: I set up #C06GSN6R2 for talk about Compojure-api and other libraries using Ring-swagger.
@txus: Just create a wrapper namespace which doesn't depend on your other ns, and does require + resolve in runtime.
is it possible to include the last item using take-while? When the condition is false the current item is not returned
(let [p (partition-by pred coll)] (concat (first p) (take 1 (second p))))
That would work if you know it starts with some true values
@kachayev that would be slightly less performant as two traversals are made (take-while then drop-while)
(defn take-until
[pred coll]
(lazy-seq
(when-let [s (seq coll)]
(if (pred (first s))
(cons (first s) nil)
(cons (first s) (take-until pred (rest s))))))))
@aengelberg: slightly less right, partition-by
will also do (drop )
there's a terrible Hive thrift API that forces you to use it, because its chunked resultset implementation has a hasMoreResults
method
@kachayev good point. partition-by doesn't run the predicate twice per element, though. But yeah, it's probably similar performance.
@ghadi I never used Hive, but it’s a common situation. I.e. our server-side API produces for mobile clients sequence of items and special “cursor” = id of the next element in a collection, to make next request to get more data (flexible pagination)
@aengelberg: right
IMHO, the name implies it's just the opposite of take-while
(complements the predicate essentially) even though it has slightly different functionality
scttnlsn: so I went the route of generating stub java classes to interact with the service
this will build java classes and then I wrote a light clojure wrapper around them to interact with it
@voxdolo: Okay, I’ll look into that as well. Is there documentation about how to interact with those generated classes?
though, all said and told, I probably spent a day or two getting the initial wrapper written
@voxdolo: Good to know. I may stick with my clj-soap fork until I encounter more trouble.
if I understood SOAP better, I'd probably avoid the wsimport
-generated java classes entirely, as they're pretty bad Java code and pretty obtuse when trying to grok them
and actually, if you need a hand, I'd be happy to lend one… I have a vested interest at this point.
@voxdolo: Minor changes to the way responses are parsed: https://github.com/scttnlsn/clj-soap
arohner: the clj file gets load priority over the cljc file, so ClojureJVM will never load the cljc.
I think there was chatter about loading both for a bit but that got discarded as having huge issues with load order.
post on gradual typing for clojure http://frenchy64.github.io/2015/06/19/gradual-typing.html
is there a core.async function like take!, that returns the value? I want to take an item off the queue without blocking, return the value if it exists, or nil
any hot tips for solid slug generation libs?
(let [val (atom)] (a/take chan #(reset! val %) true)) @val_waeselynck)
arohner: i don't know if it is ok for your use-case, that code will throw away the taken value
if I move the @val_waeselynck over, it works though?
@pesterhazy: as I promised earlier.. I added new section “The Idea” to the README file to describe the problem and the solution suggested. Does it make sense? Does it make things more clear?
arohner: You can use alt!!
with priority and a (timeout 0)
as a workaround
Or what @ghadi suggested.
I should really read the history.
@arohner wait, move me over to where?
are there any circumstances under which component/stop wouldn't run when the entire system is shut down?
@val_waeselynck: ha, sorry. That was clojure code that slack interpreted as @ val
Luckily my name's not state
:)