Skip to content

Commit 98f8cc4

Browse files
committed
up: add some new help methods
1 parent 539d2e4 commit 98f8cc4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Str/StrValue.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ public static function new(string $str): self
2626
return new self($str);
2727
}
2828

29+
/**
30+
* @param string $str
31+
*
32+
* @return self
33+
*/
34+
public static function newTrim(string $str): self
35+
{
36+
return new self(trim($str));
37+
}
38+
2939
/**
3040
* Class constructor.
3141
*

src/Util/Optional.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ public static function empty(): self
5151
return self::$empty;
5252
}
5353

54+
/**
55+
* Creates an nullable Optional given a return value.
56+
* - value assert by `empty` function.
57+
*
58+
* @template S
59+
*
60+
* @param S $value
61+
*
62+
* @return static
63+
*/
64+
public static function ofEmptyAble(mixed $value): self
65+
{
66+
return empty($value) ? self::empty() : self::of($value);
67+
}
68+
5469
/**
5570
* Creates an nullable Optional given a return value.
5671
*

0 commit comments

Comments
 (0)