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
let strings = vec!["7", "42", "one"]; | |
let numbers: Result<Vec<_>,_> = string | |
.into_iter() | |
.map(|s| s.parse::<i32>()) | |
.collect::<Result<Vec<_>,_>>(); |
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
.collect()? | |
.into_iter() | |
.map(|n| n + 1) | |
.collect() |
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
use beau_collector::BeauCollector as _; | |
let strings = vec!["7", "42", "one"]; | |
let numbers = string | |
.into_iter() | |
.map(|s| s.parse::<i32>()) | |
.bcollect::<Vec<_>>()?; |
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
module Lib | |
( tot_1 | |
, tot_2 | |
) where | |
f :: Integral a => a -> a | |
f x = x `div` 3 - 2 | |
tot_1 :: Integral a => [a] -> a | |
tot_1 = tot f |
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
module Main where | |
import Lib | |
import Data.List | |
main :: IO () | |
main = do | |
contents <- readFile "inputs.txt" | |
let inputs = fmap read . lines $ contents | |
print . Lib.tot_1 $ inputs |
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
fn fold1<F>(self, f: F) -> Option<Self::Item> where | |
F: FnMut(Self::Item, Self::Item) -> Self::Item, | |
Self: Sized, |
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
foldFunction :: (a -> b -> Maybe a) -> Maybe a -> b -> Maybe a | |
foldFunction _ Nothing _ = Nothing | |
foldFunction f (Just acc) x = f acc x |
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
foldFunction' :: (a -> c -> Either a b) -> Either a b -> c -> Either a b | |
foldFunction' _ Left x _ = Left x | |
foldFunction' f (Right acc) x = f acc x |
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
ruleX :: Char -> Char -> Bool |
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
foldl1 :: Foldable t => (a -> a -> a) -> t a -> a |