2026-09-21 21:22 UTC
Is there a pattern/name for a concept of a "lens" or "specification" pre-applied to a persistence repository?
Thinking, roughly:
```php
interface SuperSecretStuffRepository {
function find(SomeId): VeryImportant;
}
interface FilterForUser {
function apply(User, SuperSecretStuffRepository): SuperSecretStuffRepository;
}
```
It certainly is some sort of decorator.
Pseudo-code is #php
Replies (6)
-
@Girgias@phpc.social 2026-09-22 00:15
@ocramius@mastodon.social Lenses are a concept in category theory, but I'm very unsure if that's what you are actually looking for.
-
@ocramius@mastodon.social 2026-09-21 21:23
It looks like a monad, but it's not really, isn't it?
-
@dantleech@fosstodon.org 2026-09-21 21:34
@ocramius@mastodon.social not sure but what's the filter _doing_ to the repo? setting/mutating a userId? or is it decorating query builders or some such? "scope" comes to mind.
-
@mwop@phpc.social 2026-09-21 21:38
@ocramius@mastodon.social Reminds me a bit of Flyweight as well, but I don't think that's it, either.
-
@hywan@floss.social 2026-09-22 06:28
@ocramius@mastodon.social I call that a subset. Or a mapper. Or an adapter (rarely).
-
@brammm@phpc.social 2026-09-22 07:05
@ocramius@mastodon.social Reminds me a bit of https://github.com/frankdejonge/doctrine-query-specification