Skip to content

Commit e7f5b39

Browse files
authored
Merge pull request #159 from yingmanwumen/feat_str_len
feat(StringList): implement `str_len`
2 parents 789e508 + a8871db commit e7f5b39

4 files changed

Lines changed: 17 additions & 0 deletions

File tree

tests/test_string.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
[True, False, True, False],
2929
{"elem": "num"},
3030
),
31+
(
32+
"str_len",
33+
["num", "1num", "", "*", " ", "sp ace", "ta b"],
34+
[3, 4, 0, 1, 1, 6, 4],
35+
{}
36+
)
3137
],
3238
)
3339
def test_methods_with_args(

ulist/python/ulist/core.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ def starts_with(self, elem: str) -> UltraFastList:
446446
assert isinstance(self._values, StringList)
447447
return UltraFastList(self._values.starts_with(elem))
448448

449+
def str_len(self) -> "UltraFastList":
450+
"""Return each element's string length of self."""
451+
assert isinstance(self._values, StringList)
452+
return UltraFastList(self._values.str_len())
453+
449454
def sub(self, other: "UltraFastList") -> "UltraFastList":
450455
"""Return self - other."""
451456
assert not isinstance(self._values, (BooleanList, StringList))

ulist/python/ulist/ulist.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ class StringList:
264264
def size(self) -> int: ...
265265
def sort(self, ascending: bool) -> StringList: ...
266266
def starts_with(self, elem: str) -> BooleanList: ...
267+
def str_len(self) -> IntegerList64: ...
267268
def to_list(self) -> List[str]: ...
268269
def union_all(self, other: LIST_RS) -> LIST_RS: ...
269270
def unique(self) -> StringList: ...

ulist/src/string.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ impl StringList {
129129
BooleanList::new(vec)
130130
}
131131

132+
pub fn str_len(&self) -> IntegerList64 {
133+
let vec = self.values().iter().map(|x| x.len() as i64).collect();
134+
IntegerList64::new(vec)
135+
}
136+
132137
pub fn to_list(&self) -> Vec<String> {
133138
List::to_list(self)
134139
}

0 commit comments

Comments
 (0)