Showing posts with label functional programming. Show all posts
Showing posts with label functional programming. Show all posts

Monday, February 20, 2023

Rust pop-quiz: descending function from an ordering-function

#Rust pop-quiz

Okay, 'sorted alphabetically' with a sort-function simply means the default-sort, which is to sort, ascending.

What if you don't want the default-sort?

Write a function, 

down(f: F) -> (f1: F)
   where F: FnMut(&T, &T) -> Ordering

Where f1 has this behavior: 



Rust pop-quiz: sort and print CSV-output

#Rust pop-quiz

(yes, another one)

You see the CSV-output is not sorted prettily.

Sort the output alphabetically.


#Traits Bonus


Given comparator function, f: F
Sort the iterable container, c

print_sorted(f: F, c: impl IntoIterator
   where F: FnMut(&T, &T) -> Ordering

this will go into io_utils.rs