This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-29
Channels
- # 100-days-of-code (2)
- # bangalore-clj (1)
- # beginners (141)
- # cider (33)
- # cljs-dev (13)
- # cljsjs (7)
- # cljsrn (1)
- # clojure (88)
- # clojure-conj (3)
- # clojure-dev (24)
- # clojure-italy (11)
- # clojure-nl (4)
- # clojure-russia (1)
- # clojure-sanfrancisco (1)
- # clojure-spec (4)
- # clojure-uk (53)
- # clojurescript (65)
- # core-logic (2)
- # cursive (28)
- # datomic (33)
- # duct (2)
- # emacs (3)
- # figwheel-main (9)
- # fulcro (44)
- # hoplon (6)
- # leiningen (144)
- # mount (1)
- # nrepl (21)
- # off-topic (102)
- # onyx (2)
- # other-languages (5)
- # pathom (6)
- # planck (3)
- # portkey (1)
- # re-frame (7)
- # reagent (5)
- # reitit (17)
- # shadow-cljs (24)
- # spacemacs (16)
- # tools-deps (64)
- # uncomplicate (2)
- # vim (22)
Is there anything in vanilla JavaScript like clojure spec's ability to destructure based on a spec?
Let me find one...
Towards the end of the section, it shows how to use s/conform
to pull destructure data according to a spec.
ah that kind of destructuring. I hoped there would be an integration with let
or fn
destructuring and spec I wasn’t aware of 🙂
someone I know has made a spec-ish implemenation for node: https://github.com/mrijk/speculaas/tree/master/lib
That's cool, actually. I'm not running in node though. I'm hoping for something that lets me leverage JSONSchema, because that would work well with existing tooling. But I'll still check that lib out for future reference!
Daniel, do you mean something like https://github.com/metosin/spec-tools#generating-json-schemas or https://github.com/metosin/scjsv?
Wow, I didn't know about spec-tools. That's really cool...
Joi
used to be my favourite lib for schemas and validation in JS https://github.com/hapijs/joi
maps at the entry point of your library code e.g. https://github.com/fulcrologic/fulcro/blob/develop/src/main/fulcro/client.cljc#L76 https://github.com/omcljs/om/blob/master/src/main/om/next.cljc#L2720 flat top level API + metadata e.g. https://github.com/stuartsierra/component/blob/master/src/com/stuartsierra/component.cljc
My team wanted to find out the set of key sets our customers were sending at a particular endpoint. After some data munging I got a json file with an array of requests.
Halfway through writing a script to do this in javascript, it clicked.
Opened the REPL and did #(->> % (map (comp set keys)) set)
Then we saw a wonky set and wanted to see how frequently it was appearing.
It was one symbol change away #(->> % (map (comp set keys)) frequencies)
Damn I love Clojure!
The value of values is indeed immense
@jaihindh.reddy: It gets even better when you hook it up to a Spark cluster with Flambo, or put up a web-based REPL capable of vizard visualizations. At one point we even had the CFO learning a little clojure so he could play with the data…
Absolutely. I got the value of values philosophically when I watched Rich's talk but when I actually wrote that snippet. I felt it, viscerally. It's almost addictive, in the best of ways.
Anyone have a recommendation on the best article-length introduction to what functional programming is, and why it matters? There's so many of them out there, and I've entirely lost track of which ones are decent.
Oh, that's right, @maryrosecook wrote a really great FP intro. I'll start by recommending that, but other ideas super-welcome! https://maryrosecook.com/blog/post/a-practical-introduction-to-functional-programming
John Hughes - Why functional programming matters
^ That's a terrific paper, but not the best introduction to the idea for the audience I'm thinking of. I'm looking for things that are a bit lighter.
Truth! But for most people, I think you have to give them at least some idea of the advantages before you can convince them to read SICP 😉
it is hard, because the reasons for preferring functional programming aren't particularly light
my first thought was something like https://www.thocp.net/biographies/papers/backus_turingaward_lecture.pdf but I don't think that is light
http://curtclifton.net/papers/MoseleyMarks06a.pdf (out of the tarpit) is cited a lot too, but I don't think it could be called light either
Heh. Y'all are too smart to give me the answers I'm looking for 😉 I was hoping specifically to exclude "Why FP matters" and "Out of the Tarpit" by saying "article-length". It's for a fairly novice programmer, and I think he'll need to see some of the advantages before he's ready & motivated to take on the deeper stuff. I've pointed him to the Cook article I posted above, and also to http://blog.jenkster.com/2015/12/what-is-functional-programming.html
Maybe an article explaining how git is basically FP ? https://blog.jayway.com/2013/03/03/git-is-a-purely-functional-data-structure/
This is really profound! I'd asked a question about functional design patterns on this channel earlier, but I think this article get's at what I was trying to ask but in a deeper, more cross-cutting way...
there are also articles that do the opposite, explain FP by comparing it to git (you never change anything, you only get new versions)
Git’s also a blockchain right?
a lot will depend on the audience, some people care a lot about things like emerging trends in industry and best practices, other people are more interested in notions of correctness and elegance. case studies (git, react, hadoop, etc) are useful ways to answer the question "how is everyone building systems?" (and show that a lot of people are building systems based on immutable data and functions)
but it doesn't explain kind of why that pattern is something so common that people recognize it and strive for it
yeah, it’d be great if case studies recorded the reasoning people undertook when deciding on using functional approaches/patterns
as opposed to “way back when planning out react we initially chose this approach for X and Y”
what about something like http://mishadoff.com/blog/clojure-design-patterns/?
I think it'd be a great one, but I think my audience (of 1) is too green to know much (or anything?) about design patterns. This is someone fresh out of a Java/JS bootcamp, with essentially no previous programming experience.
I think the best motivation for a very new beginner might be build programs that can be composed easily. Even a new programmer these days has likely run in to the problem of trying to take two programs that work correctly on their own and combine them in to one new program that works correctly. Unfortunately my go to article on that is haskell based and starts immediately mentioning category theory
(first (filter...
should be in clojure.core
why is ffirst
in clojure.core but not (filter (first...
, is my question
why not use some
?
nvm, I see what you’re asking
also why mapv
but not mapm
there's a nice library for these things https://github.com/weavejester/medley
yeah I know there are libraries, I also dont mind having a utils
namespace or collections
namespace, but I'm genuinely curious
guess there isn't an answer
b/c core will never contain every function you might possibly need
the cool thing about functions is anyone can make them
Daniel, do you mean something like https://github.com/metosin/spec-tools#generating-json-schemas or https://github.com/metosin/scjsv?
oh yeah. i understand. Just remarking this one seems close and never quite what i need.
in general, “linear search” functions like find-first are intentionally under-represented
generally it’s better to arrange your data structure so you can look up the answer using some call that is effectively cost or log time instead
I’ve almost never wanted a function like find-first
when you need to lookup by ID but the order is important, neither a map nor a vector quite work, and find-first
works well here
well, there’s ordered-map, but in general that usually drives me back to considering why order is important and trying to remove that constraint
I do think having a few more map creation/transformation functions in core would be nice
think of a menu, it has menu items, they have an order. but if you want to edit a menu item, you lookup by ID
in this case you can't remove order
well, they don’t need to be in the same data structure necessarily
you could have a vector of ids and a map of id->info
well that doesn’t help you on lookup
sure, I mean, of course. im just saying, that this is why people use find-first
, or at least me
right, I’m just suggesting maybe you shouldn’t want to use it :)
ordering-map is a vector and a key->value map, under the hood. It is so thin a layer that explicitly using a separate vector and map is not a lot more
Correction - I meant to say ordered-map, referring to an existing 3rd party Clojure lib's data structure of that name, linked from the Clojure cheat sheet. I easily get that one and the similar-but-different ordering-map's names mixed up.
tbh I just checked and there are just two find-first in my main project and both of them are technical debt
¯\(ツ)/¯
> in general, “linear search” functions like find-first are intentionally under-represented that's a nice insight there. thanks @alexmiller
some stats: the codebase I’m working on has 2037 namespaces, of which 6 use (first (filter ...))
2037 namespaces. That is not a typo?
and across those, grep -R "(first (filter" ./ | wc -l
results in 61 occurrences. not sure how naive these are but not worth improving i'm sure
@eggsyntax I created a list of the works mentioned for "why functional programming?" discussed earlier today, and published them here: https://github.com/jafingerhut/jafingerhut.github.com/blob/master/notes/why-functional-programming.md Feel free to link to it, suggest additions via issues or PRs, etc.
Darn, only:
$ find . | grep ".clj[sc]\?$" | wc -l
473
I had some target folders and stuff in there. Did a fresh checkout now 😉but now my first filter count also goes down to 5. That’s about 1% of the namespaces still
I have nothing to add, except I was writing a few (first (filter ...))
today, and wondered about the lack of a find-first
in core. I almost posted something to a slack about it 🤢
No reason to feel nauseated about wanting to ask the question. I suspect there are a fair number of people's home-grown "util" namespaces that have such a thing, too, but linear time searching is a performance liability waiting to happen if used when the linear sequence can grow much larger later.
in my case, all the sequences are bounded to 10 items, and changing the structure of the data would mean reworking a database schema in a way I wouldn’t even know how to approach. There are cases when a linear search is the simplest, best option.
Sounds like you've got a perfect use case for linear search, then.
and also I’ve been using Kotlin on a side project, and found all the built-in stuff for dealing with collections really nice, for what it is (including first
)
This is really profound! I'd asked a question about functional design patterns on this channel earlier, but I think this article get's at what I was trying to ask but in a deeper, more cross-cutting way...