scala - Method to return values after predicate is satisfied -


to match condition use :

val c = "this test".split(" ").tolist//> c  : list[string] = list(this, is, a, test)  c.takewhile({x => !x.equals("is")})       //> res0: list[string] = list(this) 

is there method similar takewhile except takes after predicate satisifed ? c.takeafter({x => x.equals("is")}) returns list("a" , "test");

you use dropwhile:

scala>   c.dropwhile(_ != "is") res4: list[string] = list(is, a, test) 

this drop elements until hits predicate, note predicated string included need check if list empty , if not take tail.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -