pyramid icon indicating copy to clipboard operation
pyramid copied to clipboard

Reverse order for lists?

Open galaux opened this issue 3 years ago • 6 comments

Hey @lilactown !

Thanks for this great library.

I was wondering whether lists being reversed was a known/expected behavior or if this could be a bug or misuse on my side:

(let [entity {:id 9
              :my-list [{:thing {:id 1}}  ;; ← vector
                        {:thing {:id 2}}
                        {:thing {:id 3}}]}
      db (pyramid.core/add {} entity)]
  (pyramid.core/pull db [{[:id 9] [:id {:my-list [{:thing [:id]}]}]}]))
;; Order is preserved: {[:id 9] {:id 9, :my-list [{:thing {:id 1}} {:thing {:id 2}} {:thing {:id 3}}]}}


(let [entity {:id 9
              :my-list '({:thing {:id 1}}  ;; ← list
                         {:thing {:id 2}}
                         {:thing {:id 3}})}
      db (pyramid.core/add {} entity)]
  (pyramid.core/pull db [{[:id 9] [:id {:my-list [{:thing [:id]}]}]}]))
;; Reverse order: {[:id 9] {:id 9, :my-list ({:thing {:id 3}} {:thing {:id 2}} {:thing {:id 1}})}}

I noted the README says:

Collections like vectors, sets and lists should not mix entities and non-entities. Collections are recursively walked to find entities.

Could this be the explanation? I'm not sure I fully understand what exactly should be avoided.

Thanks for your time.

galaux avatar Jun 09 '22 19:06 galaux

Thanks for the report. Yup, this is a bug!

lilactown avatar Jun 10 '22 21:06 lilactown

you can try 3.3.0-SNAPSHOT, it ought to fix it for you

lilactown avatar Jun 11 '22 19:06 lilactown

Unfortunately no, results are still reversed (in my app and in the snippet provided above).

I double checked I'm using the correct version:

❯ tree ~/.m2/repository/town/
/home/galaux/.m2/repository/town/
└── lilac
    ├── cascade
    │   └── 2.0.0
    │       ├── cascade-2.0.0.jar
    │       ├── cascade-2.0.0.jar.sha1
    │       ├── cascade-2.0.0.pom
    │       ├── cascade-2.0.0.pom.sha1
    │       └── _remote.repositories
    └── pyramid
        └── 3.3.0-SNAPSHOT
            ├── maven-metadata-clojars.xml
            ├── maven-metadata-clojars.xml.sha1
            ├── pyramid-3.3.0-20220611.195651-2.jar
            ├── pyramid-3.3.0-20220611.195651-2.jar.sha1
            ├── pyramid-3.3.0-20220611.195651-2.pom
            ├── pyramid-3.3.0-20220611.195651-2.pom.sha1
            ├── pyramid-3.3.0-SNAPSHOT.jar
            ├── pyramid-3.3.0-SNAPSHOT.pom
            ├── _remote.repositories
            └── resolver-status.properties

galaux avatar Jun 12 '22 08:06 galaux

looks like my test got lost in a merge, and a bunch of other changes caused the fix to break. I'll keep working on it!

lilactown avatar Jun 12 '22 16:06 lilactown

@galaux try again?

lilactown avatar Jun 12 '22 16:06 lilactown

@lilactown SUCCESS 🥳

Thanks for your swift action !

galaux avatar Jun 14 '22 18:06 galaux