Appearance
当集合不为空时,whenNotEmpty 方法将执行给定的回调。
whenNotEmpty
collect(['michael', 'tom']) ->whenNotEmpty( fn ($items) => $items->push('adam') ); // ["michael", "tom", "adam"]
collect()->whenNotEmpty( fn ($items) => $items->push('adam'), fn ($items) => $items->push('curder') ); // ["curder"]