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
Post a Comment