by fleitz · 14y ago · 0 comments
let cacheUser user =
cache.set(user.id,user)
user
let anonymousUser id =
Some(new User())
let sourceList = [(fun id -> cache.getUser(id),
(fun id -> db.getUser(id)),
anonymousUser]
let getCachedUser id =
sourceList
|> List.pick (fun source -> source id)
|> cacheUser let sourceList = [cache.getUser; db.getUser; anonymousUser]Likewise, engineers who have at least played with FP tend to be sensitive to code smell. In the absence of other, firmer data, I'm willing to loan some trust to a programmer with FP experience.
(Edit: I posted before you edited.)
OCaml/F# are too convenient that way. There's a lot of library stuff that you won't always think to look for.