marick / fp-oo

Code samples and exercise solutions for /Functional Programming for the Object-Oriented Programmer/
143 stars 50 forks source link

Regarding ex. 1 chapter 7.9 #52

Closed eyalgo closed 5 years ago

eyalgo commented 5 years ago

As I understand, a manager can't participate in afternoon sessions. I understand the solution suggested at https://github.com/marick/fp-oo/blob/master/solutions/scheduling.clj

The logic is when checking availability.

But what if we pass the manager boolean to solution function ? Something like that:

(def separate-1
(fn [pred sequence]
  [(filter pred sequence) ()]))

(def solution
(fn [courses registrants-courses instructor-count manager]
  (map (fn [courses]
           (half-day-solution courses registrants-courses instructor-count))
       (if (true? manager)
         (separate-1 :morning? courses)
         (separate :morning? courses))
       )))

(the reason for separate-1 is because I couldn't do filter in the if clause. Got a null pointer exception. Did I miss something?

eyalgo commented 5 years ago

Worked on later exercises. Makes more sense :)