This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-29
Channels
- # ai (2)
- # beginners (12)
- # bitcoin (1)
- # boot (41)
- # chestnut (5)
- # cider (9)
- # clara (24)
- # cljs-dev (11)
- # clojure (107)
- # clojure-dev (2)
- # clojure-italy (4)
- # clojure-nl (4)
- # clojure-russia (10)
- # clojure-spec (19)
- # clojure-uk (71)
- # clojurescript (121)
- # cursive (3)
- # data-science (7)
- # datacrypt (1)
- # datomic (72)
- # docs (7)
- # duct (2)
- # emacs (3)
- # ethereum (1)
- # figwheel (1)
- # fulcro (58)
- # graphql (16)
- # hoplon (9)
- # jobs (2)
- # jobs-rus (1)
- # lein-figwheel (1)
- # leiningen (25)
- # luminus (2)
- # lumo (5)
- # off-topic (6)
- # onyx (22)
- # pedestal (3)
- # portkey (1)
- # proton (2)
- # re-frame (7)
- # remote-jobs (1)
- # ring-swagger (3)
- # rum (2)
- # shadow-cljs (38)
- # specter (7)
- # yada (30)
@mccraigmccraig clojure API nirvana?
@otfrom it's nothing magical - just a combination of a few things which have suddenly clarified the code - reducing yada handlers to almost nothing apart from the HTTP-related declarations, and then easy automatic error-handling and response-encoding through the happy medium of short-circuit promise-chain evaluation
“reducing yada handlers to almost nothing” ???
@peterwestmacott e.g. https://gist.github.com/mccraigmccraig/30912c19c88c3c9f297da2574e3d3faf - the yada handler function has become standard and i almost don't have to think about the HTTP transport anymore - parameter decoding & coercion is all automatic and result and error capture and encoding is also automatic
nothing magical - but suddenly all the pieces fitted together and a lot of needless complexity disappeared
although, thinking about it, short-circuit promise-chain evaluation is fairly magical 🙂
@mccraigmccraig I'm going to try out the yada way soon, but having used metosin/compojure-api any idea how they differ/compare? I think metosin is handling the auto-coercion with muuntaja (yay, another name)
i've not tried metosin/compojure-api @reborg - it looks like v2.0 might be very similar to yada+bidi from the readme. if you are comfortable (or want to get comfortable) with monads i would highly recommend cats+manifold for composing ops for async apis
The M word 🙂 I usually stay away from that. But will use yada in anger soon, so will report back
given that i seem to be #clojure-uk's resident M-evangelist i should try and convince you why they are great, even in clojure, and especially for async 😬
here's why
this is an api handler from our app, behind a yada resource - https://gist.github.com/mccraigmccraig/86c4e60eae1462f2c37a738268ca0c4c
every step in the ddo
(some sugar around cats mlet
) bindings block which is outside of a :let
is an async operation returning a promise of something
the monad unwraps the values from the promise and binds them, and ensures that any errors in the steps shortcut the evaluation
but the code reads very closely to synchronous code - much nicer than callback chains or manifold's chain
fn approach
and there is nothing magical at all - just some (very) well thought out composition of lexical closures
i started with manifold because yada was using it - but it turns out i prefer promises to channels for non-stream-based things - the error-handling and composition story is better
although, since i'm using a promise-monad, i could switch to using core.async as the underlying async provider without changing (barely) any code at all - a core.async promise monad is straightforward to define - https://github.com/funcool/cats/blob/master/src/cats/labs/channel.cljc
tho that code is kinda old and would probably benefit from using a promise-chan
i actually did this on the client-side a while back (switched from using core.async as my async provider to using js/bluebird promises) and it was very straightforward
i was thinking about that - there's a bunch more stuff i want to do - in particular i'd like to create a composite monad, especially with something like a writer added in to permit detailed async tracing (to counter the loss of stacktraces), and maybe a reader to avoid having to pass app-contexts around as fn args... so monad-values become Promise<Reader,Writer,step-value>
that would be very cool, and i could do a presentation around that
but not for a couple of months yet - i have a lot of customer-requests to satisfy first 🙂
“Also, there is no upsell on message history. It’s free to get to your old messages.” - quote from Keybase “Teams” announcement.
yeah, I think there's a lot of resentment for how slack are presenting things currently.
@guy not for all of slack, just the… approach to marketing that is being taken for their paid tiers. Especially given how "cool" they've been up until now.
Hello All… I was just wondering if there is an “obvious” way to sort a vector of maps based on two values in each map, i.e. sort by id, date rather than just id?
Clearly I can use sort-by to sort by id OR date, no problems, but I can’t see a way to sort by id AND date without sorting by id and then slicing up the vector and re-sorting each part by date…
@maleghast sort
has a 2-arg version with a comparator which can be something like #(let [id-s (compare (:id %1) (:id %2))] (if (not= 0 id-s) id-s (compare (:date %1) (:date %1))))
(which i haven't tried out so caveat executor)
@mccraigmccraig Thanks, I will try that and let you know…
oh, yeah, that's much nicer
what @minimal said
All I have to do, now, is take the sorted vector and split it into partitions based on the date field and the id field… So all the maps that are for the same id and date need to end up in their own nested vector…
Yeah, this looks like it does the trick…
(group-by :station (sort-by (juxt :station :date) (:results example-data)))
But I think it might be better like this:
(sort-by :date (group-by :station (:results example-data)))
No, that doesn’t work, but I can group-by station and then do-seq over the grouped vector of maps and then group each one by date and the sort by date before I process them, and that will work very nicely… So I didn’t need the juxt on station and date, but it’s good to know how it works anyway… 🙂