scala - Meaning of exclamation mark in zipAll(s).takeWhile(!_._2.isEmpty) -



scala - Meaning of exclamation mark in zipAll(s).takeWhile(!_._2.isEmpty) -

what explanation mark doing in (!_._2.isempty) ?

as in :

def startswith[a](s: stream[a]): boolean = zipall(s).takewhile(!_._2.isempty) forall { case (h,h2) => h == h2 }

taken stream.

is negation ?

if yes, why no space required between ! , _ ?

is not !_ interpreted method name ?

can method names contain or start ! ?

it negation. expanding definition replacing _ more verbose name might create more obvious.

def startswith[a](s: stream[a]): boolean = zipall(s).takewhile(!_._2.isempty) forall { case (h,h2) => h == h2 }

can rewritten

def startswith[a](s: stream[a]): boolean = zipall(s).takewhile( element => !element._2.isempty) forall { case (h,h2) => h == h2 }

._2 sec item in tuple, in case looks list pair of items (references later h , h2) rewrite unpacking items pair of values as

def startswith[a](s: stream[a]): boolean = zipall(s).takewhile{ element => val (h, h2) = element !h2.isempty } forall { case (h,h2) => h == h2 }

scala syntax

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -