This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-12
Channels
- # announcements (2)
- # aws (1)
- # beginners (63)
- # cider (2)
- # clj-kondo (1)
- # cljdoc (15)
- # clojure (114)
- # clojure-nl (1)
- # clojure-spec (15)
- # clojure-uk (10)
- # clojurescript (5)
- # clojutre (1)
- # community-development (6)
- # cursive (18)
- # data-science (1)
- # datascript (16)
- # datomic (2)
- # emacs (2)
- # events (3)
- # figwheel-main (2)
- # graphql (3)
- # jobs (2)
- # off-topic (23)
- # reitit (3)
- # shadow-cljs (27)
- # spacemacs (5)
- # sql (27)
- # unrepl (1)
Is anyone aware of a library that is designed to transform data based on a spec or similar? cc @alexmiller
Resist the temptation tho' @denik -- spec is not intended to be used to drive transformations 🙂
@alexmiller @seancorfield @ikitommi to be clear, I'm not looking to coerce data, rather I want to to give it a richer shape (e.g. places -> names / sequential -> associative). I have a concise place-based syntax like [:user/add [:post 5 :authors] {:id 10 :user/name "Eve"}]
that I want to turn into
{:op :user/add
:path [:post 5 :authors]
: entity {:id 10 :user/name "Eve"}}
This would be easy in vanilla clojure but there are some gotchas, for example path
is optional. With other edge cases writing that in vanilla clojure would get ugly fast. Spec's s/?
+ conform (or similar) seem like a perfect fit. So if it's not conform
, I'm wondering if there is a straightforward approach to parse and unparse while leveraging specs?@denik s/conform
would work for this, but I’ve seen people advising against using it
cond->
is great for optional stuff
I’d just use core stuff
@alexmiller not for parsing
there are libs for data structure parsing like https://github.com/cgrand/seqexp that do the "parsing" of data
Puzzled. I would have said that s/conform
would have been a perfect tool (without any add-onns) for parsing just that example. What are the downsides of using spec for parsing?
conform is fine for parsing
Request above is for additional transformation and enhancement of the result
conforming/parsing + generation of a spec for the parsed result (comformed shape) so that it can be checked in other function invocations as well as fspecs.
I would find this very useful:
1. sparse data comes in from a request, e.g. [:user/add [:post 5 :authors] {:id 10 :user/name "Eve"}]
2. conform
data to use names instead of indexes/places=>
{:op :user/add
:path [:post 5 :authors]
:entity {:id 10 :user/name "Eve"}}
3. use a derived spec of the conformed value from (2) to check validity of the value as it is updated throughout the programconforming/parsing + generation of a spec for the parsed result (comformed shape) so that it can be checked in other function invocations as well as fspecs.
I would find this very useful:
1. sparse data comes in from a request, e.g. [:user/add [:post 5 :authors] {:id 10 :user/name "Eve"}]
2. conform
data to use names instead of indexes/places=>
{:op :user/add
:path [:post 5 :authors]
:entity {:id 10 :user/name "Eve"}}
3. use a derived spec of the conformed value from (2) to check validity of the value as it is updated throughout the program