Strings\firstChar()

transformer returns Closure pure
string → (string → string)
At a glance — Slice from the first matching char. Wraps strpbrk().

Returns a function which can be used to get the contents of a string after (and including) the occurrence of a defined char. The created function can then reused over any string, or used as part of a Higher Order Function such as array_map().

/**
  *  @param string $chars All chars to check with.
  * @return Closure(string):strin
  */
Strings\firstChar(string $chars): Closure

Returned Closure

When Strings\firstChar() is called, it returns the following Closure which can be used like a regular function.

/**
  * @param string $haystack
  * @return string
  * @psalm-pure
  */ 
$function(string $haystack): bool

Examples

Partial Application

This can be used to create a simple closure which can be used as a regular function.

// Create function to get the rest of a string after the first occurrence of either m or i
$firstMorI = Strings\firstChar('mi');

// Called as a function.
$firstMorI('This is a Simple text.'); // 'is is a Simple text.'

// Used in a higher order function.
$array = array_map($firstMorI, ['This is a Simple text.', 'That may be a simple text.']);
print_r($array); // ['is is a Simple text.', 'may be a simple text.']

Curried

This can be called inline using currying.

print Strings\firstChar('a')('This is a Simple text.'); // 'a Simple text.'

Inlined with Higher Order Function

If you are not planning on reusing the Closure created, you can just call it inline with a higher order function as its callable.

$array = array_map(Strings\firstChar('a'), ['This is a Simple text.', 'That may be a simple text.']);
print_r($array); // ['a Simple text.', 'a simple text.']

Details

Strings Functions

Releated String manipulation Functions