Advertisement
AlexG2230954

Untitled

Jun 17th, 2024
1,462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.48 KB | None | 0 0
  1. type SmartList<'State, 't> = ('State -> 't -> 'State) -> 'State -> 'State
  2.  
  3. let fromList L folder state = Seq.fold folder state L
  4.  
  5. let fold folder state L = L folder state
  6. let map f L folder state = L (fun s el -> folder s (f el)) state
  7. let filter p L folder state =
  8.    let updatedFolder s el =
  9.        if p el then folder s el
  10.        else s
  11.    L updatedFolder state
  12.  
  13. // check
  14. let result = fromList [1; 2; 3; 4; 5] |> filter (fun x -> x > 2) |> fold (+) 0
  15. printfn "%A" result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement