読者です 読者をやめる 読者になる 読者になる

IT練習ノート

IT関連で調べたこと(実際は嵌ったこと)を書いています。

様々なsplitAt

HoogleでのsplitAt検索結果

http://www.haskell.org/hoogle/?hoogle=splitAt

比べてみると理解が深まりますね。

  • 配列
Prelude> :t splitAt
splitAt :: Int -> [a] -> ([a], [a])
Prelude> splitAt 5 "abcdefghijklmnopqrstuvwxyz"
("abcde","fghijklmnopqrstuvwxyz")
Prelude> 
  • テキスト
Prelude> :t Data.Text.splitAt
Data.Text.splitAt :: Int -> Data.Text.Internal.Text -> (Data.Text.Internal.Text,Data.Text.Internal.Text)
Prelude> Data.Text.splitAt 5 $ Data.Text.pack "abcdefghijklmnopqrstuvwxyz"
("abcde","fghijklmnopqrstuvwxyz")
Prelude> 
  • バイト列(Char8)
Prelude> :t Data.ByteString.Char8.splitAt
Data.ByteString.Char8.splitAt :: Int -> Data.ByteString.Internal.ByteString -> (Data.ByteString.Internal.ByteString, Data.ByteString.Internal.ByteString)
Prelude> Data.ByteString.Char8.splitAt 5 $ Data.ByteString.Char8.pack "abcdefghijklmnopqrstuvwxyz"
("abcde","fghijklmnopqrstuvwxyz")
  • バイト列
Prelude> :t Data.ByteString.splitAt 
Data.ByteString.splitAt :: Int -> Data.ByteString.Internal.ByteString ->(Data.ByteString.Internal.ByteString, Data.ByteString.Internal.ByteString)
Prelude> Data.ByteString.splitAt 5 $ Data.ByteString.Char8.pack "abcdefghijklmnopqrstuvwxyz"
("abcde","fghijklmnopqrstuvwxyz")
Prelude> 
Prelude> :t Data.Sequence.splitAt
Data.Sequence.splitAt :: Int -> Data.Sequence.Seq a -> (Data.Sequence.Seq a, Data.Sequence.Seq a)
Prelude> Data.Sequence.splitAt 5 $ Data.Sequence.fromList "abcdefghijklmnopqrstuvwxyz"
(fromList "abcde",fromList "fghijklmnopqrstuvwxyz")