This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SuggestPopularFriendPost { | |
private final IAccessProfileInfo profileInfo; | |
public SuggestPopularFriendPost(IAccessProfileInfo profileInfo) { | |
this.profileInfo = profileInfo; | |
} | |
public Iterable<PostSummary> suggestedPostsFor(ProfileId profileId) { | |
Iterable<ProfileId> friendIds = friendsOf(profileId); | |
Set<Topic> topics = favoriteTopicsOf(profileId); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Iterable<PostSummary> suggestedPostsFor(ProfileId profileId) { | |
Iterable<ProfileId> friendIds = friendsOf(profileId); // Get the friends of the current user | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Iterable<PostSummary> suggestedPostsFor(ProfileId profileId) { | |
Iterable<ProfileId> friendIds = friendsOf(profileId); // Get the friends of the current user | |
Set<Topic> topics = favoriteTopicsOf(profileId); // Get the favorite topics of the current user | |
Stream<PostSummary> friendsPosts = stream(friendIds) // For each friend | |
.flatMap(friendId -> lastPostsOf(friendId)) // * Get their last posts | |
.filter(post -> post.isAbout(topics)); // * Keep those whose topic is relevant | |
return mostLiked(3, friendsPosts); // Rank them by like count | |
} | |
private List<PostSummary> mostLiked(int count, Stream<PostSummary> posts) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suggestedPostsFor userId = do | |
friendIds <- friendsOf userId -- Get the friends of the current user | |
topics <- favoriteTopicsOf userId -- Get the favorite topics of the current user | |
friendsPosts <- forM friendIds $ \friendId -> do -- For each friend | |
posts <- lastPostsOf friendId -- * Get their last posts | |
return (filter (isAbout topics) posts) -- * Keep those whose topic is relevant | |
return (mostLiked 3 friendsPosts) -- Rank them to keep only the bests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void f (Context const& context, ...); | |
void caller_from_rest(Context const& context) | |
{ | |
WithContext restContext("REST", "/api/v1.0/f"); | |
f(context, ...); | |
// ... "REST" automatically removed at the end | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void f (Context const& context, ...) { | |
logger.info(context, "Doing stuff in function f"); | |
} | |
void caller_from_rest(Context const& context) { | |
context.put("REST", "/api/v1.0/f"); | |
// ... | |
f(context, ...); | |
// ... | |
context.remove("REST"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void f(Context const& context) { | |
// ... | |
logger.info(context, "log message"); | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Context { | |
public: | |
void put(key const&, json const&); | |
void remove(key const&); | |
std::map<key, json> getContext(); | |
//... | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE FlexibleInstances #-} | |
module LogContext (testLogContext) where | |
import Control.Concurrent | |
-- import Control.Concurrent.Async | |
-------------------------------------------------------------------------------- | |
-- Abstract logger language | |
-------------------------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Calling make-payment using named arguments | |
(make-payment | |
{:money "10 EUR" | |
:from "Alice" | |
:to "Bob"}) | |
;; Versus calling make-payment with positional arguments | |
(make-payment "10 EUR" "Alice" "Bob") |