Alter field value before render In Drupal 8, I was thinking that's a simple task but it's not : 

function hmytheme_preprocess_field(&amp;$variables, $hook) {
    $element = $variables['element'];
    if (isset($element['#field_name'])) {

        if($element['#field_name'] == "bar"){
             element['#items']-&gt;value ="foo";
             //or
             element['#items']-&gt;set(0,"foo");
        }
    }
}


this is not afecting the render. 
How to ? 
I don't whant to save the altered value
It's too late to change the field object, because the field is already prepared for rendering. You have to find the field value inside of the render array, for example in #markup, and change it there. Where you find the value depends how your field display is configured in the view mode.


  While possible, there's often a better way. You could make your own
  formatter that returns the structure that you want. #text is a
  formatted text field, you could make a filter that transforms the text
  the way you want. Depends on what you want to do exactly.


(Comment from @Berdir)

See the drupal docs how to create a custom field formatter:

https://www.drupal.org/docs/8/creating-custom-modules/create-a-custom-field-formatter