32 lines
		
	
	
		
			612 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			612 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
pub hkt Functor[Self<T>]
 | 
						|
    fn <U> map(f: fn (t: T) -> U) -> Self<U>
 | 
						|
end
 | 
						|
 | 
						|
pub int Iterable<T>
 | 
						|
    fn iter() -> Iterator<T>
 | 
						|
end
 | 
						|
 | 
						|
pub int Iterator<T> = () -> Option<T>
 | 
						|
 | 
						|
pub enum Option<T> : Functor[Self<T>]
 | 
						|
    Some(T),
 | 
						|
    None;
 | 
						|
 | 
						|
    fn unwrap() -> T
 | 
						|
        self is Some(t) ? t : throw Exception('Empty Option')
 | 
						|
    end
 | 
						|
 | 
						|
    fn expect(msg: String) -> T
 | 
						|
        self is Some(t) ? t : throw Exception(msg)
 | 
						|
    end
 | 
						|
 | 
						|
    impl Functor
 | 
						|
        fn <U> map(f: fn (t: T) -> U) -> Self<U>
 | 
						|
            self is Some(t) ? Some(f(t)) : None
 | 
						|
        end
 | 
						|
    end
 | 
						|
 | 
						|
    static fn lift(t: T) -> Self<T>
 | 
						|
        Some(t)
 | 
						|
    end
 | 
						|
end |