Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support recursive in get-in #30

Open
obeah opened this issue Mar 27, 2016 · 8 comments
Open

Support recursive in get-in #30

obeah opened this issue Mar 27, 2016 · 8 comments

Comments

@obeah
Copy link

obeah commented Mar 27, 2016

Hi,

it seems recursive is not supported by get-in. Was it omitted on purpose?
With small modifications it works for my use case:

(defn- unwrap-recursive [m]
  (cond
    (recursive? m) (deref (:derefable m)) ; probably use schema-value
    :else m))
(defn- get-in-schema [m k & [default]]
  (unwrap-recursive (unwrap-sequence-schemas (get m (key-in-schema m k) default))))

@Deraen
Copy link
Member

Deraen commented Mar 27, 2016

Yes, it was reverted on purpose. Using schema-value proved too unpredictable and broke existing code: 240f8a5

@Deraen
Copy link
Member

Deraen commented Mar 27, 2016

We are interested in finding a way to support this. Ideas welcome.

Some ideas here: #8 (comment)

@ikitommi
Copy link
Member

Could there be a separately special get-in-value, which would walk over schema Records?

@Deraen
Copy link
Member

Deraen commented Mar 27, 2016

Perhaps. I think -value postfix doesn't clearly indicate that Schema values would be walked over all along the path. Maybe -values is better?

@ikitommi
Copy link
Member

There is already get-schema-value which walks over one level and is documented "Returns the sub-schema or sub-schemas of given schema.". So, get-in-schema-value could be coherent name...

@obeah
Copy link
Author

obeah commented Mar 27, 2016

Thanks. I understand the problem with "conditional", "maybe" etc. (actually will be doing some special form of get-in for my particular use case of "conditional" - it will return a union of values for all possible branches). As for "recursive" I definitely missing smth - it seems to me it would be just enough to resolve it to actual underlying schema and continue but you obviously encountered some issues with that.

@Deraen
Copy link
Member

Deraen commented Mar 27, 2016

@obeah It is also somewhat unpredictable with recursive:

(get-in {:a {:b (s/recursive Foo)}} [:a :b])
;; Foo
;; or (s/recursive Foo) ?

@obeah
Copy link
Author

obeah commented Mar 27, 2016

thanks, got it. It seems that for this particular case, current implementation returns recursive, not underlying schema:
(get-in {:a {:b (s/recursive Foo)}} [:a :b])

But for the case when caller wants to go one or more levels deeper then it seems reasonable to resolve "recursive" to actual schema and continue.
So (get-in {:a {:b (s/recursive Foo)}} [:a :b :key-in-foo]) would return schema for :key-in-foo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants