-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1cd22bc
commit e78cf17
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
type List; | ||
|
||
def String_len : (i:String) -> Int = native "lambda i: len(i)"; | ||
def String_list_to_String : (l:List) -> String = native "lambda l: ' '.join(l)"; | ||
def map_String_String_List: (function:(a: String) -> String) -> (l: List) -> List = native "lambda f: lambda xs: map(f, xs)"; | ||
def String_split : (i:String) -> (j:String) -> List = native "lambda i: lambda j: i.split(j)" ; | ||
def String_reverse : (i:String) -> String = native "lambda i: i[::-1]"; | ||
|
||
def spin_words (phrase: String) : String { | ||
words: List = String_split(phrase)(" "); | ||
reversed_words: List = map_String_String_List ((\x -> if (String_len(x) >= 5) then String_reverse(x) else x):(x:String)->String) (words); | ||
|
||
String_list_to_String(reversed_words) | ||
} | ||
|
||
def main (args:Int) : Unit { | ||
print (spin_words("this is another test")) | ||
} |