Skip to content

Commit

Permalink
Add comparator tuple fold
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-byrne committed Oct 16, 2024
1 parent 8f04414 commit 8638e42
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/exam01/exam01.sml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ fun insert comp add li =
val testInsert = insert (fn (a, b) => a < b) 5 [1, 2, 3, 4, 6, 7, 8]; (* should be [1, 2, 3, 4, 5, 6, 7, 8] *)
raiseIfFalse(testInsert = [1, 2, 3, 4, 5, 6, 7, 8]);

(* remove question *)
(* map to tuple question *)
fun foo f li = map (fn (cur) => (cur, f(cur))) li;
val bar = foo (fn x => x * x) [1, 2, 3, 4]; (* should be [(1, 1), (2, 4), (3, 9), (4, 16)] *)
raiseIfFalse(bar = [(1, 1), (2, 4), (3, 9), (4, 16)]);

(* remove symmetric dups question *)
fun foo f li = foldr (fn ((cur1, cur2), acc) => if f(cur1) = f(cur2) then (cur1, cur2)::acc else acc) [] li;


0 comments on commit 8638e42

Please sign in to comment.