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 for non-empty-array/non-empty-list #2

Closed
azjezz opened this issue Mar 27, 2021 · 0 comments · Fixed by #3
Closed

support for non-empty-array/non-empty-list #2

azjezz opened this issue Mar 27, 2021 · 0 comments · Fixed by #3
Assignees
Labels
enhancement New feature or request

Comments

@azjezz
Copy link
Contributor

azjezz commented Mar 27, 2021

first reported in azjezz/psl#145 by @bendavies

Hi there!

Is your feature request related to a problem? Please describe.

Is is feasible to

  1. add non-empty-array and non-empty-list support to the type system, such that:
  2. the return Psl\Iter\first and other functions can be T and not T|null?

Describe the solution you'd like
I want to be able to do things like:

<?php

declare(strict_types=1);

use Psl;

class FooExtractor
{
   /** @param list<Foo> $foos */
   public function __invoke(array $foos): Foo
   {
       $foosFiltered = Vec\filter(
           $foos,
           function (Foo $foo): bool {
               ...
           }
       );

       //assert $foosFiltered type is non-empty-list/array here.

       //this will error as the return type is `T|null`
       return Iter\first($foosFiltered);
   }
}

Is there a better way to achieve what I'm trying to do?

Thanks!

@azjezz azjezz added the enhancement New feature or request label Mar 27, 2021
@azjezz azjezz self-assigned this Mar 27, 2021
@azjezz azjezz linked a pull request Apr 4, 2021 that will close this issue
@azjezz azjezz closed this as completed in #3 Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant