@@ -1087,6 +1087,32 @@ impl FSharpArray {
10871087 Ok ( FSharpArray { storage : results } )
10881088 }
10891089
1090+ #[ pyo3( signature = ( predicate, cons=None ) ) ]
1091+ pub fn skip_while (
1092+ & self ,
1093+ py : Python < ' _ > ,
1094+ predicate : & Bound < ' _ , PyAny > ,
1095+ cons : Option < & Bound < ' _ , PyAny > > ,
1096+ ) -> PyResult < FSharpArray > {
1097+ let len = self . storage . len ( ) ;
1098+ let mut count = 0 ;
1099+
1100+ while count < len {
1101+ let item = self . get_item_at_index ( count as isize , py) ?;
1102+ if !predicate. call1 ( ( item, ) ) ?. is_truthy ( ) ? {
1103+ break ;
1104+ }
1105+ count += 1 ;
1106+ }
1107+
1108+ if count == len {
1109+ let fs_cons = FSharpCons :: extract ( cons, self . storage . get_type ( ) ) ;
1110+ return fs_cons. allocate ( py, 0 ) ;
1111+ }
1112+
1113+ self . skip ( py, count as isize , cons)
1114+ }
1115+
10901116 pub fn chunk_by_size ( & self , py : Python < ' _ > , chunk_size : usize ) -> PyResult < Self > {
10911117 if chunk_size < 1 {
10921118 return Err ( PyErr :: new :: < exceptions:: PyValueError , _ > (
@@ -2908,17 +2934,26 @@ impl FSharpArray {
29082934 }
29092935 }
29102936
2911- #[ pyo3( signature = ( projection, comparer) ) ]
2937+ #[ pyo3( signature = ( projection, comparer= None ) ) ]
29122938 pub fn sort_by (
29132939 & self ,
29142940 py : Python < ' _ > ,
29152941 projection : & Bound < ' _ , PyAny > ,
2916- comparer : & Bound < ' _ , PyAny > ,
2942+ comparer : Option < & Bound < ' _ , PyAny > > ,
29172943 ) -> PyResult < FSharpArray > {
29182944 let mut result = self . clone ( ) ;
2945+ // Use provided comparer or create a default one
2946+ let default_comparer;
2947+ let comparer_ref = match comparer {
2948+ Some ( c) => c,
2949+ None => {
2950+ default_comparer = DefaultComparer :: new ( ) ?. into_pyobject ( py) ?;
2951+ & default_comparer
2952+ }
2953+ } ;
29192954 result. storage = result
29202955 . storage
2921- . sort_by_with_projection ( py, projection, comparer ) ?;
2956+ . sort_by_with_projection ( py, projection, comparer_ref ) ?;
29222957 Ok ( result)
29232958 }
29242959
@@ -3188,6 +3223,17 @@ pub fn skip(
31883223 array. skip ( py, count, cons)
31893224}
31903225
3226+ #[ pyfunction]
3227+ #[ pyo3( signature = ( predicate, array, cons=None ) ) ]
3228+ pub fn skip_while (
3229+ py : Python < ' _ > ,
3230+ predicate : & Bound < ' _ , PyAny > ,
3231+ array : & FSharpArray ,
3232+ cons : Option < & Bound < ' _ , PyAny > > ,
3233+ ) -> PyResult < FSharpArray > {
3234+ array. skip_while ( py, predicate, cons)
3235+ }
3236+
31913237#[ pyfunction]
31923238pub fn chunk_by_size (
31933239 py : Python < ' _ > ,
@@ -4042,11 +4088,12 @@ pub fn sort(
40424088}
40434089
40444090#[ pyfunction]
4091+ #[ pyo3( signature = ( projection, array, comparer=None ) ) ]
40454092pub fn sort_by (
40464093 py : Python < ' _ > ,
40474094 projection : & Bound < ' _ , PyAny > ,
40484095 array : & FSharpArray ,
4049- comparer : & Bound < ' _ , PyAny > ,
4096+ comparer : Option < & Bound < ' _ , PyAny > > ,
40504097) -> PyResult < FSharpArray > {
40514098 array. sort_by ( py, projection, comparer)
40524099}
@@ -4492,6 +4539,7 @@ pub fn register_array_module(parent_module: &Bound<'_, PyModule>) -> PyResult<()
44924539 m. add_function ( wrap_pyfunction ! ( set_slice, & m) ?) ?;
44934540 m. add_function ( wrap_pyfunction ! ( singleton, & m) ?) ?;
44944541 m. add_function ( wrap_pyfunction ! ( skip, & m) ?) ?;
4542+ m. add_function ( wrap_pyfunction ! ( skip_while, & m) ?) ?;
44954543 m. add_function ( wrap_pyfunction ! ( sort, & m) ?) ?;
44964544 m. add_function ( wrap_pyfunction ! ( sort_by, & m) ?) ?;
44974545 m. add_function ( wrap_pyfunction ! ( sort_in_place, & m) ?) ?;
0 commit comments