Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
[True, False, True, False],
{"elem": "num"},
),
(
"str_len",
["num", "1num", "", "*", " ", "sp ace", "ta b"],
[3, 4, 0, 1, 1, 6, 4],
{}
)
],
)
def test_methods_with_args(
Expand Down
5 changes: 5 additions & 0 deletions ulist/python/ulist/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ def starts_with(self, elem: str) -> UltraFastList:
assert isinstance(self._values, StringList)
return UltraFastList(self._values.starts_with(elem))

def str_len(self) -> "UltraFastList":
"""Return each element's string length of self."""
assert isinstance(self._values, StringList)
return UltraFastList(self._values.str_len())

def sub(self, other: "UltraFastList") -> "UltraFastList":
"""Return self - other."""
assert not isinstance(self._values, (BooleanList, StringList))
Expand Down
1 change: 1 addition & 0 deletions ulist/python/ulist/ulist.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class StringList:
def size(self) -> int: ...
def sort(self, ascending: bool) -> StringList: ...
def starts_with(self, elem: str) -> BooleanList: ...
def str_len(self) -> IntegerList64: ...
def to_list(self) -> List[str]: ...
def union_all(self, other: LIST_RS) -> LIST_RS: ...
def unique(self) -> StringList: ...
Expand Down
5 changes: 5 additions & 0 deletions ulist/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ impl StringList {
BooleanList::new(vec)
}

pub fn str_len(&self) -> IntegerList64 {
let vec = self.values().iter().map(|x| x.len() as i64).collect();
IntegerList64::new(vec)
}

pub fn to_list(&self) -> Vec<String> {
List::to_list(self)
}
Expand Down