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
    
  
  
    
  | function main() { | |
| var label = "Semester 7/Design Patterns/assign2"; | |
| var folder = "dp-assign2"; | |
| GmailApp | |
| .getUserLabelByName(label) | |
| .getThreads() | |
| .map(lastMessage) | |
| .map(extractAttachment) | |
| .forEach(saveFile(folder)); | 
  
    
      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
    
  
  
    
  | package main | |
| import "fmt" | |
| func producer(queue chan string) { | |
| fmt.Println(<-queue) | |
| } | |
| func main() { | |
| queue := make(chan string) | 
  
    
      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
    
  
  
    
  | typedef int (*operator)(int, int); | |
| int main() { | |
| operator plus = (int a, int b) { | |
| return a+b; | |
| }; | |
| int res = (*plus)(1, 2); | |
| printf("%d ", res); | |
| return 0; | |
| } | 
  
    
      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
    
  
  
    
  | #include <stdio.h> | |
| typedef int(*func)(int); | |
| func plus(int a) { | |
| int add(int b) { | |
| return a + b; | |
| } | |
| return add; | |
| } | 
  
    
      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
    
  
  
    
  | typedef int elem_t; | |
| typedef struct List { | |
| elem_t head; | |
| struct List *tail; | |
| } List; | |
| List *cons(elem_t head, List *tail) { | |
| List *res = malloc(sizeof(List)); | |
| res->head = head; | 
  
    
      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
    
  
  
    
  | List *copy(List *oldList) { | |
| // empty | |
| if (oldList == NULL) { | |
| return NULL; | |
| } | |
| // head | |
| List *newList = cons(oldList->head, NULL); | |
| List *res = newList; | |
| oldList = oldList->tail; | 
  
    
      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 static<A,B> B foldLeftRec(BiFunction<B,A,B> f, B v, List<A> xs) { | |
| return xs.isEmpty() ? v : foldl(f, f.apply(v, xs.head()), xs.tail()); | |
| } | |
| public static<A,B> B foldLeftIter(BiFunction<B,A,B> f, B v, List<A> xs) { | |
| B acc = v; | |
| for (A x: xs) { | |
| acc = f.apply(acc, x); | |
| } | |
| return acc; | 
  
    
      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
    
  
  
    
  | factLeftHelper acc [] = acc | |
| factLeftHelper acc (x:xs) = factLeftHelper (acc * x) xs | |
| factLeft = factLeftHelper 1 | 
  
    
      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
    
  
  
    
  | // rec | |
| public static<T> List<T> cons(T head, List<T> tail) { | |
| return new List(head, tail); | |
| } | |
| private static<T> void copyTailRec(List<T> newList, List<T> oldList) { | |
| if (oldList != null) { | |
| newList.tail = cons(oldList.head, null); | |
| copyTailRec(newList.tail, oldList.tail); | 
  
    
      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
    
  
  
    
  | List *copyIter(List *oldList) { | |
| List res, *newList; | |
| newList = &res; | |
| newList->tail = NULL; | |
| while (oldList != NULL) { | |
| newList->tail = cons(oldList->head, NULL); | |
| newList = newList->tail; | |
| oldList = oldList->tail; | |
| } | 
OlderNewer