Skip to content

Instantly share code, notes, and snippets.

@khmylov
Created December 29, 2014 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khmylov/6081d8d7d4a6a8723cfb to your computer and use it in GitHub Desktop.
Save khmylov/6081d8d7d4a6a8723cfb to your computer and use it in GitHub Desktop.
fsharp1
let cleanText (lines: string[]) =
lines
|> Seq.skipWhile (fun str -> not (bookStarted str))
|> Seq.takeWhile (fun str -> not (bookFinished str))
|> String.concat " "
|> Seq.map (fun c ->
if Char.IsLetter c then Char.ToLowerInvariant c
else ' ')
// ---->
let cleanText2 : string[] -> char seq =
Seq.skipWhile (not << bookStarted)
>> Seq.takeWhile (not << bookFinished)
>> String.concat " "
>> Seq.map (fun c ->
if Char.IsLetter c then Char.ToLowerInvariant c
else ' ')
@sergey-tihon
Copy link

My choice:

let cleanText lines =
    lines
    |> Seq.skipWhile (not << bookStarted)
    |> Seq.takeWhile (not << bookFinished)
    |> String.concat " "
    |> Seq.map (fun c -> 
        if Char.IsLetter c then Char.ToLowerInvariant c
        else ' ')

I think this is more readable for people, because it shows data flow (what is important) instead of beauty of function composition and explicit type annotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment