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
foldl (\acc x -> acc + x) 0 [1,2,3,4] | |
-- acc starts at 0, x starts as the first element of the list, so 1 | |
-- 0 + 1 = 1 -> acc = 1, list = [2,3,4] | |
-- 1 + 2 = 3 -> acc = 3, list = [3,4] | |
-- 3 + 3 = 6 -> acc = 6, list = [4] | |
-- 6 + 4 = 10 -> acc = 10 | |
-- therefore, this foldl results in a value of 10 |
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
import Data.Char | |
import Data.List | |
data DNANucleotide = A | C | G | T deriving(Show, Eq, Ord, Read) | |
charToDNANucleotide :: Char -> DNANucleotide | |
charToDNANucleotide c = read [toUpper c] :: DNANucleotide | |
mainCountDNANucleotides = do | |
dna <- getLine |
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
data AssignmentGrade = AssignmentGrade { score :: Int, grade :: Char } deriving(Show, Read, Eq) | |
instance Ord AssignmentGrade where | |
compare ag1 ag2 = compare (score ag1) (score ag2) |
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
addFunction :: Int -> Int -> Int | |
addFunction x1 x2 = x1 + x2 | |
-- addFunction 1 2 ==> 3 | |
let add10 = addFunction 10 | |
-- :t add10 | |
-- add10 :: Int -> Int | |
-- add10 5 ==> 15 | |
-- add10 100 ==> 110 |
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
doMathFunction :: (Int -> Int -> Int) -> Int -> Int -> Int | |
doMathFunction func x1 x2 = func x1 x2 | |
-- doMathFunction (+) 1 2 ==> 3 | |
-- doMathFunction (*) 4 3 ==> 12 | |
-- doMathFunction (-) 4 3 ==> 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
rnaConverter = foldr (\x acc -> if x == 'T' then 'U':acc else x: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
module Bioinformatics.DNANucleotide ( | |
DNANucleotide (..), | |
charToDNANucleotide | |
) where | |
import Data.Char | |
import Data.List | |
data DNANucleotide = A | C | G | T deriving(Show, Eq, Ord, Read) |
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
func find<S : Sliceable>(domain: S, isValue: (S.Generator.Element) -> Bool) -> S.Index? { | |
return find(domain, domain.startIndex, isValue) | |
} | |
func find<S : Sliceable>(domain: S, startingIndex: S.Index, isValue: (S.Generator.Element) -> Bool) -> S.Index? { | |
if startingIndex == domain.endIndex { | |
return nil | |
} | |
if isValue(domain[startingIndex]) { | |
return startingIndex | |
} |
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 testText = "<a href=\"#\">Something</a>" | |
if let firstEndIndex = find(testText, ">") { | |
let testText2 = testText[Range<String.Index>(start: firstEndIndex.successor(), end: testText.endIndex)] | |
if let secondStartIndex = find(testText2, "<") { | |
let testText3 = testText2[Range<String.Index>(start: testText2.startIndex, end: secondStartIndex)] | |
} | |
} |
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 startSplits = split(testText, { $0 == "<" }) | |
let strippedValues = map(startSplits) { (s) -> String? in | |
if let endIndex = find(s, ">") { | |
return s[Range<String.Index>(start: endIndex.successor(), end: s.endIndex)] | |
} | |
return nil | |
} | |
let strings = strippedValues.filter({ $0 != nil }).filter({ $0 != "" }).map({ $0! }) |