conditional icon indicating copy to clipboard operation
conditional copied to clipboard

Additional Operations

Open bayareawebpro opened this issue 5 years ago • 1 comments

Suggestions:


//Switch
Condition::switch($value)
    ->default(new DefaultStrategy)
    ->case(1, new StrategyA)
    ->case(2, new StrategyB)
;

// Higher Order Proxy to Fluent Str
Condition::when($value)
    ->endsWith('City')->replaceLast(' City', '')->title()
    ->contains('New York')->uppercase()
    ->empty(new RandomCity)
;

//Delegate to Object API
Condition::when($obj)
    ->implements('toArray')
    ->then('toArray')

    ->subclassOf(Post::class)
    ->then('load', ['comments'])

    ->instanceOf(ViewFactory::class)
    ->then('render')

    ->finally(fn($value) => new Response($value))
;

// Literal Types
Condition::when($val)
    ->is('numeric')->then(fn($val)=> $value)
    ->is('string')->then(fn($val)=> $value)
    ->is('empty')->then(fn($val)=> $value)
    ->is('null')->then(fn($val)=> $value)

bayareawebpro avatar May 06 '20 14:05 bayareawebpro

These looks great. Thank you for your suggestions.

omitobi avatar May 14 '20 06:05 omitobi