> All the pagination libs I know for ecto return structs with additional
metadata besides the actual results of the db query. Currently one needs to
build around those structs specifically to be able to do preloads or other
mapping operations or one would loose the metadata.

Can you please provide an example? I am just trying to full understand the
problem. :)

> Having a `SomeProtocol.empty` protocol we could still use everything
provided by Enum (even with it returning a list), but have a way to replace
items in the container with the new modified ones

Wouldn't a functor be better suited then?


*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D


On Tue, May 21, 2019 at 6:34 PM Benjamin Milde <[email protected]>
wrote:

> All the pagination libs I know for ecto return structs with additional
> metadata besides the actual results of the db query. Currently one needs to
> build around those structs specifically to be able to do preloads or other
> mapping operations or one would loose the metadata. Having a
> `SomeProtocol.empty` protocol we could still use everything provided by
> Enum (even with it returning a list), but have a way to replace items in
> the container with the new modified ones without manually pattern matching
> between single results, lists of results or structs returned because one
> happens to be using pagination. Monadic collection types basically don't do
> it much differently. Extract the subject out of the container, do
> computation and replace the old value when done. I'd imagine `Enumerable`
> and the potential `SomeProtocol` would solve a lot of usecases, where
> people usually ask for Enum to retain the outer collection type.
>
> Am Dienstag, 21. Mai 2019 18:14:49 UTC+2 schrieb José Valim:
>>
>> My concern is that Collectable.empty cannot be implemented by all
>> structs. For example, what does it mean to call empty() on a IO.stream?
>> Perhaps it would make sense as a separate protocol?
>>
>> Also, can you please expand on how Repo.preload could use Scrivener.Page
>> in detail? Thanks!
>>
>>
>> *José Valim*
>> www.plataformatec.com.br
>> Skype: jv.ptec
>> Founder and Director of R&D
>>
>>
>> On Tue, May 21, 2019 at 5:46 PM Benjamin Milde <[email protected]>
>> wrote:
>>
>>> I've had quite often needs for doing some computation (mapping) on ecto
>>> result, but having a flexible function similar to `Repo.preload` currently
>>> needs a whole bunch of boilerplate in terms of differenciating collections
>>> from single items and especially returning the same type afterwards (e.g.
>>> keep it a collection or single item). I know that Enumerable and
>>> Collectable were split consciously, but it would be great to have something
>>> like `Collectable.empty/1`, so one could do some work using `Enum`
>>> functions and in the end do: `Enum.into(changed,
>>> Collectable.empty(initial))` and it would empty the collectable and fill it
>>> up again using the changed data. This way the `Repo.preload` could e.g.
>>> additionally support custom enumerable and collectable collections as first
>>> argument like e.g. `%Scrivener.Page{}`.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "elixir-lang-core" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/elixir-lang-core/19c24b83-fc2a-4af3-950e-eba7f767db14%40googlegroups.com
>>> <https://groups.google.com/d/msgid/elixir-lang-core/19c24b83-fc2a-4af3-950e-eba7f767db14%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/1498525e-30fd-4cde-92a0-4b2e01cdbdf3%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/1498525e-30fd-4cde-92a0-4b2e01cdbdf3%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4LJuRZPhGJUbhen%3DTFXWJRJTqJADu0AoZg8DwVzcbJ2vg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to