Comments (9)
Thanks for your interest in contributing.
We're pretty mindful of keeping plumbing.core
small -- just to those things we wish were in clojure.core
, more or less. That's a pretty high bar; internally, we have a plumbing.core-incubator
namespace, and only things that marinade in there for a few months and see a lot of usage are considered for inclusion.
Are there any of these that you find particularly useful and think meet this standard? FWIW, update
is already in there.
from plumbing.
That's cool. Then I'm going to use the incubator namespace if it can reduce my codebase. Btw, can you provide me a link to that namespace? (it's embarrassing but I can't find it haha)
The ones I would really like to see in clojure.core
:
defcopy
- useful for aliasing a form while keeping its metadata. I use it to keep the docstring for aliases.ffilter
orfind-first
- this one doesn't need introduction.update-each
- useful for updating severalmap
keys
with samefn
.update-multi
- useful for updating severalmap
keys
with severalfns
.or->
- too often do I find myself using the original value when->
returnsnil
(but can be used forfalse
too).unlazy
- this one is just so useful, when you want to revert from thelazy-seq
to the input type when doing map/reduce/filter.map-dregs
would be cool too forclojure.core
, but I'm not sure how frequently it would be used.
update-multi
and unlazy
are names I came up with. They could be named differently.
from plumbing.
Well defcopy
wont work in cljs and current impl of or->
also.
from plumbing.
Cool, thanks. core-incubator
is an internal thing currently -- it's by definition unstable, so not sure it's something we actually want to expose publicly.
defcopy
: we're currently using potemkin/import-vars
for this.
find-first
: a deliberate omission -- we decided it was not shorter/clearer enough to merit inclusion.
update-each
: how often do you want this rather than map-keys
?
update-multi
: could see this as useful, but I'm not sure how often. If anywhere, it would probably go in plumbing.map -- will have to think about it.
or->
: when do you find yourself using this? I don't think I've really seen this pattern (and using eval
like this is a big no-no IMO).
unlazy
: I think mapv
fills most of this niche for us, and I think being explicit is often a good thing. I think this also reverses the order for lists?
from plumbing.
potemkin/import-vars
looks neat. defcopy
allows me to additionally rename vars, which import-vars
doesn't (it seems). I do rename them a lot btw :) I even make copies of the var in the same ns
, for different naming tastes.
I use map-keys
and update-each
. The former updates all keys with one fn, the latter updates values of selected keys with one fn
, so they are quite different. Maybe the naming is ambiguous. An example: (update-each {:a 1 :b 2 :c 4} [:a :b] inc) => {:a 2, :c 4, :b 3}
update-multi
: I use it 2 times here and it's just 128 LOC. It may be some design fault on my part, though haha.
or->
: I'm only using it in the same source file, even though I felt the need for it in the past many times. The example is too simple, though. I think of it as defaulting to the original value when the result is false. Maybe the name is not the best either. I found some issues with the fn
(besides eval of course) so better ignore it for the moment. Sorry about this one. It's not mature enough.
unlazy
: yes, it reverses lists, well spotted! I guess I never tried it with lists haha. Being explicit is sound. Which fn
do you use for maps?
So it leaves us with defcopy
, update-each
and update-multi
. Do you want to leave defcopy
out also?
from plumbing.
Thanks for the details. I think we'll skip worrying about defcopy
for now, until we do something with potemkin. For update-multi
, after looking at these examples, I think just a ->
with multiple calls to update
is clearer, and nearly as short. Do you have concrete examples of where you use update-each
?
Sorry for being a stickler about this stuff -- but I've spent way too much time over the years cleaning up huge namespaces of my utility functions that seemed like a good idea at the time but in hindsight weren't really net wins.
from plumbing.
Yes, one could do that with ->
. My point there was to save 1 line. Maybe it's not as readable if each key must go in a different line anyway, but if it's a small one liner, I think it's a win, like this one in that file: (update-multi {:allFeaturesArray seq :partOfSpeech #(split % #",")})
. I would argue that if it's a 1 liner, readability may increase, when comparing to :keys
scattered through lines + ->
.
I found just one example of update-each
in my codebases:
(defn sync-timecodes [unsynced-sub synced-sub]
(let [time-offset (- (-> synced-sub :events first :Start)
(-> unsynced-sub :events first :Start))]
(update-in unsynced-sub [:events]
(partial map
#(update-each % [:Start :End] + time-offset)))))
Both :Start
and :End
would naturally be updated with the same fn
when shifting time by an offset
.
Don't worry, I'm already learning a lot with this ping pong and it was a pleasure :)
from plumbing.
It's clear by now there isn't an obvious need of any of the remaining forms, so I'm closing this.
For future reference, you may want to see defcopy
, update-each
and update-multi
.
Thanks for the discussion. It was really useful for me.
from plumbing.
Thanks for understanding -- we'll keep these in mind for future updates.
from plumbing.
Related Issues (20)
- Clojurescript version of topological-sort incorrectly (and randomly) reports a graph cycle error HOT 2
- Metadata Reader Macros and fnks HOT 4
- fnk binding form can't combine optional parameters with destructuring HOT 4
- Feature suggestion: defs HOT 6
- Compile Time Schema Checks HOT 3
- Outputing maps from graphs HOT 4
- defnk-defined functions don't document their args HOT 1
- Schema for Graph HOT 3
- Support for namespaced keys, part II HOT 9
- Annotate defnk/fnk meta with their :file HOT 1
- Functional versions of ?> and ?>> HOT 4
- (map/flatten {:foo false}) -> '() HOT 1
- lazymap's repository has been deleted, please migrate away from it HOT 6
- `eager-compile` throws an error with large graphs HOT 6
- `plumbing.core/keywordize-map` causes shadow-cljs warnings even it is not used in the project HOT 1
- cjlx has been deprecated
- Fix API documentation
- Please consider making a new release HOT 8
- Letk destructuring of an optional renamed key with schema validation HOT 6
- Malformed \uxxxx encoding error via clojars artifact HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plumbing.